From c089275208d580e5672221fd647ad47a6322d431 Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Fri, 9 Feb 2024 03:43:24 +0100 Subject: [PATCH] refactoring: Kommentare + formatieren --- src/main/java/ChatGUI.java | 54 +++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/main/java/ChatGUI.java b/src/main/java/ChatGUI.java index d5efb58..743e4f4 100644 --- a/src/main/java/ChatGUI.java +++ b/src/main/java/ChatGUI.java @@ -17,7 +17,7 @@ import javax.swing.JTextArea; import javax.swing.JTextField; public class ChatGUI implements ActionListener { - + // Menu items for font sizes JMenuItem small = new JMenuItem("small-font"); JMenuItem medium = new JMenuItem("medium-font"); @@ -28,9 +28,9 @@ public class ChatGUI implements ActionListener { JMenuItem red = new JMenuItem("red"); JMenuItem blue = new JMenuItem("blue"); JMenuItem green = new JMenuItem("green"); - + JMenuItem exit = new JMenuItem("Exit"); - + JTextField inputTextField = new JTextField(); JTextArea outputTextArea = new JTextArea(); JButton sendButton = new JButton("Senden"); @@ -44,11 +44,11 @@ public class ChatGUI implements ActionListener { gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); gui.setTitle("java-chat"); gui.setLayout(new BorderLayout()); - + // Set up the menu bar JMenuBar bar = new JMenuBar(); gui.setJMenuBar(bar); - + // Create menu items and menus JMenu options = new JMenu("options"); JMenu colors = new JMenu("font-colors"); @@ -65,11 +65,11 @@ public class ChatGUI implements ActionListener { colors.add(red); colors.add(blue); colors.add(green); - + size.add(small); size.add(medium); size.add(large); - + // Register action listeners for menu items red.addActionListener(this); blue.addActionListener(this); @@ -82,19 +82,20 @@ public class ChatGUI implements ActionListener { exit.addActionListener(this); bar.add(menu); - + // Set up the output text area with scrolling JScrollPane outputScrollPane = new JScrollPane(outputTextArea); gui.add(outputScrollPane, BorderLayout.CENTER); + // Set up the input panel with text field and send button JPanel inputPanel = new JPanel(new BorderLayout()); - inputPanel.add(inputTextField, BorderLayout.CENTER); - inputPanel.add(sendButton, BorderLayout.EAST); - gui.add(inputPanel, BorderLayout.SOUTH); + inputPanel.add(inputTextField, BorderLayout.CENTER); + inputPanel.add(sendButton, BorderLayout.EAST); + gui.add(inputPanel, BorderLayout.SOUTH); inputTextField.addActionListener(this); sendButton.addActionListener(this); - + // Set the size of the GUI to be a quarter of the screen size Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int quarterWidth = screenSize.width / 2; @@ -102,6 +103,7 @@ public class ChatGUI implements ActionListener { gui.setSize(quarterWidth, quarterHeight); gui.setVisible(true); } + // main methode zum Testen, müsste bei Implementation entfernt werden public static void main(String[] args) { @@ -114,13 +116,13 @@ public class ChatGUI implements ActionListener { System.exit(0); } if (e.getSource() == inputTextField || e.getSource() == sendButton) { - String inputText = inputTextField.getText(); - outputTextArea.append(inputText + "\n"); - inputTextField.setText(""); + String inputText = inputTextField.getText(); + outputTextArea.append(inputText + "\n"); + inputTextField.setText(""); } if (e.getSource() == red) { outputTextArea.setForeground(Color.RED); - + } else if (e.getSource() == blue) { outputTextArea.setForeground(Color.BLUE); } else if (e.getSource() == black) { @@ -128,17 +130,15 @@ public class ChatGUI implements ActionListener { } else if (e.getSource() == green) { outputTextArea.setForeground(Color.GREEN); } - if(e.getSource() == small) { - outputTextArea.setFont(outputTextArea.getFont().deriveFont(Font.PLAIN, 12)); - } - if(e.getSource() == medium) { - outputTextArea.setFont(outputTextArea.getFont().deriveFont(Font.PLAIN, 16)); - } - if(e.getSource() == large) { - outputTextArea.setFont(outputTextArea.getFont().deriveFont(Font.PLAIN, 20)); - } - - + if (e.getSource() == small) { + outputTextArea.setFont(outputTextArea.getFont().deriveFont(Font.PLAIN, 12)); + } + if (e.getSource() == medium) { + outputTextArea.setFont(outputTextArea.getFont().deriveFont(Font.PLAIN, 16)); + } + if (e.getSource() == large) { + outputTextArea.setFont(outputTextArea.getFont().deriveFont(Font.PLAIN, 20)); + } } }