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()); } }