From 126942d00013cd67b547ef3827ea52e63e02bfe4 Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Fri, 9 Feb 2024 17:07:10 +0100 Subject: [PATCH] =?UTF-8?q?Zeitstempelfunktion=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ChatGUI.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/ChatGUI.java b/src/main/java/ChatGUI.java index 743e4f4..765d6d7 100644 --- a/src/main/java/ChatGUI.java +++ b/src/main/java/ChatGUI.java @@ -5,6 +5,8 @@ import java.awt.Font; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.text.SimpleDateFormat; +import java.util.Date; import javax.swing.JButton; import javax.swing.JFrame; @@ -117,8 +119,8 @@ public class ChatGUI implements ActionListener { } if (e.getSource() == inputTextField || e.getSource() == sendButton) { String inputText = inputTextField.getText(); - outputTextArea.append(inputText + "\n"); inputTextField.setText(""); + addMessage(inputText); } if (e.getSource() == red) { outputTextArea.setForeground(Color.RED); @@ -139,6 +141,12 @@ public class ChatGUI implements ActionListener { if (e.getSource() == large) { 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()); } }