|
|
@ -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); |
|
|
@ -140,5 +142,11 @@ public class ChatGUI implements ActionListener { |
|
|
|
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()); |
|
|
|
|
|
|
|
} |
|
|
|
} |