From 2579040ed7d10b7d1bc86bb2006197f84d5c380d Mon Sep 17 00:00:00 2001 From: Alena Bandarovich Date: Fri, 9 Feb 2024 19:05:28 +0100 Subject: [PATCH] Add method to initialize timer --- src/main/java/ChatClient.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/ChatClient.java b/src/main/java/ChatClient.java index ac9268b..b8fd458 100644 --- a/src/main/java/ChatClient.java +++ b/src/main/java/ChatClient.java @@ -1,6 +1,8 @@ import javax.swing.*; import javax.swing.border.EmptyBorder; import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.io.*; @@ -70,6 +72,7 @@ public class ChatClient extends JFrame implements KeyListener { private JTextArea outputTextArea; private JTextField inputTextField; private JScrollPane outputScrollPane; + private Timer timer; public ChatClient() { super("Chat"); @@ -80,6 +83,16 @@ public class ChatClient extends JFrame implements KeyListener { } } + private void initTimer() { + timer = new Timer(1000, new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + //Method to update time + } + }); + timer.start(); + } + private void initGui() { outputTextArea = new JTextArea(); outputTextArea.setEditable(false); @@ -107,6 +120,7 @@ public class ChatClient extends JFrame implements KeyListener { toServerWriter = new PrintWriter(new OutputStreamWriter(connectionToServer.getOutputStream())); initGui(); + initTimer(); while (true) { String message = fromServerReader.readLine();