From 2d6074f6ae5177b3254fe20716d589170637313e Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Fri, 9 Feb 2024 01:43:21 +0100 Subject: [PATCH] =?UTF-8?q?refactoring:=20Einr=C3=BCcken=20und=20Kommentar?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ChatGUI.java | 59 ++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/src/main/java/ChatGUI.java b/src/main/java/ChatGUI.java index 852f623..109f0f1 100644 --- a/src/main/java/ChatGUI.java +++ b/src/main/java/ChatGUI.java @@ -11,42 +11,45 @@ import javax.swing.JTextField; public class ChatGUI implements ActionListener { - JTextField inputTextField = new JTextField(); - JTextArea outputTextArea = new JTextArea(); - - JFrame gui; - - public ChatGUI() { - gui = new JFrame(); - - gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - gui.setTitle("java-chat"); - - gui.setLayout(new BorderLayout()); - - - JScrollPane outputScrollPane = new JScrollPane(outputTextArea); - gui.add(outputScrollPane, BorderLayout.CENTER); - - inputTextField.setPreferredSize(new Dimension(0, 30)); - gui.add(inputTextField, BorderLayout.SOUTH); - - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - int quarterWidth = screenSize.width / 2; - int quarterHeight = screenSize.height / 2; - gui.setSize(quarterWidth, quarterHeight); + JTextField inputTextField = new JTextField(); + JTextArea outputTextArea = new JTextArea(); + + JFrame gui; + + public ChatGUI() { + gui = new JFrame(); + + // Set up the main frame + gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + gui.setTitle("java-chat"); + + gui.setLayout(new BorderLayout()); + + // Set up the output text area with scrolling + JScrollPane outputScrollPane = new JScrollPane(outputTextArea); + gui.add(outputScrollPane, BorderLayout.CENTER); + + // Set up the input text field + inputTextField.setPreferredSize(new Dimension(0, 30)); + gui.add(inputTextField, BorderLayout.SOUTH); + + // Set the size of the GUI to be a quarter of the screen size + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + int quarterWidth = screenSize.width / 2; + int quarterHeight = screenSize.height / 2; + gui.setSize(quarterWidth, quarterHeight); gui.setVisible(true); - } - + } + public static void main(String[] args) { new ChatGUI(); } + @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub - + } - }