Browse Source

hinzufügen senden-button

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

25
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;
@ -79,17 +82,19 @@ 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 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();
int quarterWidth = screenSize.width / 2;
@ -108,10 +113,10 @@ public class ChatGUI implements ActionListener {
if (e.getSource() == exit) {
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) {
outputTextArea.setForeground(Color.RED);

Loading…
Cancel
Save