Browse Source

refactoring: Verschoerung Code

remotes/origin/server
Paul Kattenborn 11 months ago
parent
commit
080c6393cd
  1. 72
      src/main/java/ChatGUI.java

72
src/main/java/ChatGUI.java

@ -16,10 +16,10 @@ import javax.swing.JTextField;
public class ChatGUI implements ActionListener { public class ChatGUI implements ActionListener {
JMenuItem exit = new JMenuItem("Exit"); 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(); JTextField inputTextField = new JTextField();
JTextArea outputTextArea = new JTextArea(); JTextArea outputTextArea = new JTextArea();
@ -35,30 +35,30 @@ public class ChatGUI implements ActionListener {
gui.setLayout(new BorderLayout()); gui.setLayout(new BorderLayout());
JMenuBar bar = new JMenuBar(); JMenuBar bar = new JMenuBar();
gui.setJMenuBar(bar);
gui.setJMenuBar(bar);
JMenu options = new JMenu("options");
JMenu colors = new JMenu("font-colors");
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);
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);
colors.add(black);
colors.add(red);
colors.add(blue);
colors.add(green);
red.addActionListener(this);
blue.addActionListener(this);
black.addActionListener(this);
green.addActionListener(this);
red.addActionListener(this);
blue.addActionListener(this);
black.addActionListener(this);
green.addActionListener(this);
exit.addActionListener(this);
exit.addActionListener(this);
bar.add(menu);
bar.add(menu);
// Set up the output text area with scrolling // Set up the output text area with scrolling
JScrollPane outputScrollPane = new JScrollPane(outputTextArea); JScrollPane outputScrollPane = new JScrollPane(outputTextArea);
@ -89,21 +89,21 @@ public class ChatGUI implements ActionListener {
System.exit(0); System.exit(0);
} }
if (e.getSource() == inputTextField) { 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() == 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() == 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);
}
}
}
}
} }
Loading…
Cancel
Save