From 34791e0f6bdd0e19759c7ede3ec23a5b4b8b47cc Mon Sep 17 00:00:00 2001 From: Alena Bandarovich Date: Fri, 9 Feb 2024 21:43:56 +0100 Subject: [PATCH] Refactor: Move output text area to a new method --- src/main/java/ChatClient.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/ChatClient.java b/src/main/java/ChatClient.java index 7ff74a6..90966c8 100644 --- a/src/main/java/ChatClient.java +++ b/src/main/java/ChatClient.java @@ -103,12 +103,7 @@ public class ChatClient extends JFrame implements KeyListener { } private void initGui() { - outputTextArea = new JTextArea(); - outputTextArea.setEditable(false); - outputTextArea.setBorder(BorderFactory.createTitledBorder("Chat")); - outputTextArea.setBackground(Color.lightGray); - - outputScrollPane = new JScrollPane(outputTextArea); + prepareOutputTextArea(); timeLabel = new JLabel(); updateTime(); @@ -126,6 +121,16 @@ public class ChatClient extends JFrame implements KeyListener { setDefaultCloseOperation(EXIT_ON_CLOSE); setLocationRelativeTo(null); } + + private void prepareOutputTextArea() { + outputTextArea = new JTextArea(); + outputTextArea.setEditable(false); + outputTextArea.setBorder(BorderFactory.createTitledBorder("Chat")); + outputTextArea.setBackground(Color.lightGray); + + outputScrollPane = new JScrollPane(outputTextArea); + } + private void receiveMessages() { try { connectionToServer = new Socket(address, Constants.PORT);