diff --git a/src/main/java/ChatGUI.java b/src/main/java/ChatGUI.java index 3651223..b33e153 100644 --- a/src/main/java/ChatGUI.java +++ b/src/main/java/ChatGUI.java @@ -14,12 +14,12 @@ import javax.swing.JTextArea; import javax.swing.JTextField; public class ChatGUI implements ActionListener { - + JMenuItem exit = new JMenuItem("Exit"); - JMenuItem black = new JMenuItem("black"); - JMenuItem red = new JMenuItem("red"); - JMenuItem blue = new JMenuItem("blue"); - JMenuItem green = new JMenuItem("green"); + JMenuItem black = new JMenuItem("black"); + JMenuItem red = new JMenuItem("red"); + JMenuItem blue = new JMenuItem("blue"); + JMenuItem green = new JMenuItem("green"); JTextField inputTextField = new JTextField(); JTextArea outputTextArea = new JTextArea(); @@ -27,49 +27,49 @@ public class ChatGUI implements ActionListener { public ChatGUI() { gui = new JFrame(); - + // Set up the main frame gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); gui.setTitle("java-chat"); gui.setLayout(new BorderLayout()); - + JMenuBar bar = new JMenuBar(); - gui.setJMenuBar(bar); - - JMenu options = new JMenu("options"); - JMenu colors = new JMenu("font-colors"); - - JMenu menu = new JMenu("File"); - menu.add(exit); - menu.add(options); - bar.add(menu); - options.add(colors); - - colors.add(black); - colors.add(red); - colors.add(blue); - colors.add(green); - - red.addActionListener(this); - blue.addActionListener(this); - black.addActionListener(this); - green.addActionListener(this); - - exit.addActionListener(this); - - bar.add(menu); - + gui.setJMenuBar(bar); + + JMenu options = new JMenu("options"); + JMenu colors = new JMenu("font-colors"); + + JMenu menu = new JMenu("File"); + menu.add(exit); + menu.add(options); + bar.add(menu); + options.add(colors); + + colors.add(black); + colors.add(red); + colors.add(blue); + colors.add(green); + + red.addActionListener(this); + blue.addActionListener(this); + black.addActionListener(this); + green.addActionListener(this); + + 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 text field inputTextField.setPreferredSize(new Dimension(0, 30)); gui.add(inputTextField, BorderLayout.SOUTH); - + inputTextField.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; @@ -89,21 +89,21 @@ public class ChatGUI implements ActionListener { System.exit(0); } if (e.getSource() == inputTextField) { - 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); } - if (e.getSource() == red) { - outputTextArea.setForeground(Color.RED); - } - if (e.getSource() == blue) { - outputTextArea.setForeground(Color.BLUE); - }else if (e.getSource() == black) { - outputTextArea.setForeground(Color.BLACK); - } else if (e.getSource() == green) { - outputTextArea.setForeground(Color.GREEN); + if (e.getSource() == blue) { + outputTextArea.setForeground(Color.BLUE); + } else if (e.getSource() == black) { + outputTextArea.setForeground(Color.BLACK); + } else if (e.getSource() == green) { + outputTextArea.setForeground(Color.GREEN); - } + } -} + } }