Browse Source

Show current time in chat window

remotes/origin/hotfix/client/improve-chat-window-appearence
Alena Bandarovich 11 months ago
parent
commit
cc07a4f8de
  1. 15
      src/main/java/ChatClient.java

15
src/main/java/ChatClient.java

@ -7,6 +7,8 @@ import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.*;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ChatClient extends JFrame implements KeyListener {
public static class TR extends JFrame {
@ -73,6 +75,7 @@ public class ChatClient extends JFrame implements KeyListener {
private JTextField inputTextField;
private JScrollPane outputScrollPane;
private Timer timer;
private JLabel timeLabel;
public ChatClient() {
super("Chat");
@ -87,12 +90,18 @@ public class ChatClient extends JFrame implements KeyListener {
timer = new Timer(1000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//Method to update time
updateTime();
}
});
timer.start();
}
private void updateTime() {
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a");
String currentTime = sdf.format(new Date());
timeLabel.setText("Current Time: " + currentTime);
}
private void initGui() {
outputTextArea = new JTextArea();
outputTextArea.setEditable(false);
@ -101,6 +110,10 @@ public class ChatClient extends JFrame implements KeyListener {
outputScrollPane = new JScrollPane(outputTextArea);
timeLabel = new JLabel();
updateTime();
add(timeLabel, BorderLayout.NORTH);
inputTextField = new JTextField();
inputTextField.setBorder(BorderFactory.createTitledBorder("Nachricht eingeben"));
inputTextField.addKeyListener(this);

Loading…
Cancel
Save