Browse Source

hinzufügen senden-button

remotes/origin/server
Paul Kattenborn 11 months ago
parent
commit
14c221315b
  1. 13
      src/main/java/ChatGUI.java

13
src/main/java/ChatGUI.java

@ -6,10 +6,12 @@ import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
@ -31,6 +33,7 @@ public class ChatGUI implements ActionListener {
JTextField inputTextField = new JTextField();
JTextArea outputTextArea = new JTextArea();
JButton sendButton = new JButton("Senden");
JFrame gui;
@ -84,11 +87,13 @@ public class ChatGUI implements ActionListener {
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);
JPanel inputPanel = new JPanel(new BorderLayout());
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();
@ -108,7 +113,7 @@ public class ChatGUI implements ActionListener {
if (e.getSource() == exit) {
System.exit(0);
}
if (e.getSource() == inputTextField) {
if (e.getSource() == inputTextField || e.getSource() == sendButton) {
String inputText = inputTextField.getText();
outputTextArea.append(inputText + "\n");
inputTextField.setText("");

Loading…
Cancel
Save