|
@ -6,10 +6,12 @@ import java.awt.Toolkit; |
|
|
import java.awt.event.ActionEvent; |
|
|
import java.awt.event.ActionEvent; |
|
|
import java.awt.event.ActionListener; |
|
|
import java.awt.event.ActionListener; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.JButton; |
|
|
import javax.swing.JFrame; |
|
|
import javax.swing.JFrame; |
|
|
import javax.swing.JMenu; |
|
|
import javax.swing.JMenu; |
|
|
import javax.swing.JMenuBar; |
|
|
import javax.swing.JMenuBar; |
|
|
import javax.swing.JMenuItem; |
|
|
import javax.swing.JMenuItem; |
|
|
|
|
|
import javax.swing.JPanel; |
|
|
import javax.swing.JScrollPane; |
|
|
import javax.swing.JScrollPane; |
|
|
import javax.swing.JTextArea; |
|
|
import javax.swing.JTextArea; |
|
|
import javax.swing.JTextField; |
|
|
import javax.swing.JTextField; |
|
@ -31,6 +33,7 @@ public class ChatGUI implements ActionListener { |
|
|
|
|
|
|
|
|
JTextField inputTextField = new JTextField(); |
|
|
JTextField inputTextField = new JTextField(); |
|
|
JTextArea outputTextArea = new JTextArea(); |
|
|
JTextArea outputTextArea = new JTextArea(); |
|
|
|
|
|
JButton sendButton = new JButton("Senden"); |
|
|
|
|
|
|
|
|
JFrame gui; |
|
|
JFrame gui; |
|
|
|
|
|
|
|
@ -79,17 +82,19 @@ public class ChatGUI implements ActionListener { |
|
|
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); |
|
|
gui.add(outputScrollPane, BorderLayout.CENTER); |
|
|
gui.add(outputScrollPane, BorderLayout.CENTER); |
|
|
|
|
|
|
|
|
// Set up the input text field |
|
|
|
|
|
inputTextField.setPreferredSize(new Dimension(0, 30)); |
|
|
|
|
|
gui.add(inputTextField, BorderLayout.SOUTH); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JPanel inputPanel = new JPanel(new BorderLayout()); |
|
|
|
|
|
inputPanel.add(inputTextField, BorderLayout.CENTER); |
|
|
|
|
|
inputPanel.add(sendButton, BorderLayout.EAST); |
|
|
|
|
|
gui.add(inputPanel, BorderLayout.SOUTH); |
|
|
|
|
|
|
|
|
inputTextField.addActionListener(this); |
|
|
inputTextField.addActionListener(this); |
|
|
|
|
|
|
|
|
|
|
|
sendButton.addActionListener(this); |
|
|
|
|
|
|
|
|
// Set the size of the GUI to be a quarter of the screen size |
|
|
// Set the size of the GUI to be a quarter of the screen size |
|
|
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
|
|
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
|
|
int quarterWidth = screenSize.width / 2; |
|
|
int quarterWidth = screenSize.width / 2; |
|
@ -108,10 +113,10 @@ public class ChatGUI implements ActionListener { |
|
|
if (e.getSource() == exit) { |
|
|
if (e.getSource() == exit) { |
|
|
System.exit(0); |
|
|
System.exit(0); |
|
|
} |
|
|
} |
|
|
if (e.getSource() == inputTextField) { |
|
|
|
|
|
String inputText = inputTextField.getText(); |
|
|
|
|
|
outputTextArea.append(inputText + "\n"); |
|
|
|
|
|
inputTextField.setText(""); |
|
|
|
|
|
|
|
|
if (e.getSource() == inputTextField || e.getSource() == sendButton) { |
|
|
|
|
|
String inputText = inputTextField.getText(); |
|
|
|
|
|
outputTextArea.append(inputText + "\n"); |
|
|
|
|
|
inputTextField.setText(""); |
|
|
} |
|
|
} |
|
|
if (e.getSource() == red) { |
|
|
if (e.getSource() == red) { |
|
|
outputTextArea.setForeground(Color.RED); |
|
|
outputTextArea.setForeground(Color.RED); |
|
|