Browse Source

Zeitstempelfunktion hinzugefügt

remotes/origin/server
Paul Kattenborn 11 months ago
parent
commit
126942d000
  1. 10
      src/main/java/ChatGUI.java

10
src/main/java/ChatGUI.java

@ -5,6 +5,8 @@ import java.awt.Font;
import java.awt.Toolkit; 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 java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JFrame; import javax.swing.JFrame;
@ -117,8 +119,8 @@ public class ChatGUI implements ActionListener {
} }
if (e.getSource() == inputTextField || e.getSource() == sendButton) { if (e.getSource() == inputTextField || e.getSource() == sendButton) {
String inputText = inputTextField.getText(); String inputText = inputTextField.getText();
outputTextArea.append(inputText + "\n");
inputTextField.setText(""); inputTextField.setText("");
addMessage(inputText);
} }
if (e.getSource() == red) { if (e.getSource() == red) {
outputTextArea.setForeground(Color.RED); outputTextArea.setForeground(Color.RED);
@ -139,6 +141,12 @@ public class ChatGUI implements ActionListener {
if (e.getSource() == large) { if (e.getSource() == large) {
outputTextArea.setFont(outputTextArea.getFont().deriveFont(Font.PLAIN, 20)); outputTextArea.setFont(outputTextArea.getFont().deriveFont(Font.PLAIN, 20));
} }
}
private void addMessage(String message) {
String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date());
outputTextArea.append("[" + timeStamp + "] " + message + "\n");
outputTextArea.setCaretPosition(outputTextArea.getDocument().getLength());
} }
} }
Loading…
Cancel
Save