diff --git a/src/main/java/ChatGUI.java b/src/main/java/ChatGUI.java new file mode 100644 index 0000000..852f623 --- /dev/null +++ b/src/main/java/ChatGUI.java @@ -0,0 +1,52 @@ +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JFrame; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.JTextField; + +public class ChatGUI implements ActionListener { + + JTextField inputTextField = new JTextField(); + JTextArea outputTextArea = new JTextArea(); + + JFrame gui; + + public ChatGUI() { + gui = new JFrame(); + + gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + gui.setTitle("java-chat"); + + gui.setLayout(new BorderLayout()); + + + JScrollPane outputScrollPane = new JScrollPane(outputTextArea); + gui.add(outputScrollPane, BorderLayout.CENTER); + + inputTextField.setPreferredSize(new Dimension(0, 30)); + gui.add(inputTextField, BorderLayout.SOUTH); + + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + int quarterWidth = screenSize.width / 2; + int quarterHeight = screenSize.height / 2; + gui.setSize(quarterWidth, quarterHeight); + gui.setVisible(true); + } + + public static void main(String[] args) { + + new ChatGUI(); + } + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + + } + + +} diff --git a/src/main/java/ClientHandler.java b/src/main/java/ClientHandler.java index 45570aa..b30e37a 100644 --- a/src/main/java/ClientHandler.java +++ b/src/main/java/ClientHandler.java @@ -66,6 +66,7 @@ public class ClientHandler implements Runnable { toClientWriter.println(message); // Send the message to the client toClientWriter.flush(); // Flush the stream } + //Test method public String getLastMessage() { return lastMessage; } diff --git a/src/test/java/ChatServerTest.java b/src/test/java/ChatServerTest.java deleted file mode 100644 index 4b7eb79..0000000 --- a/src/test/java/ChatServerTest.java +++ /dev/null @@ -1,44 +0,0 @@ -import static org.junit.jupiter.api.Assertions.*; - -import java.util.List; - -import org.junit.jupiter.api.Test; - -class ChatServerTest { - - @Test - public void testConstructor() { - // Arrange - ChatServer chatServer = null; - - // Act - try { - chatServer = new ChatServer(1234); - } catch (Exception e) { - fail("Exception occurred: " + e.getMessage()); - } - - // Assert - assertNotNull(chatServer); - } - @Test - public void testBroadcastMessage() { - // Arrange - ChatServer chatServer = new ChatServer(1234); - ClientHandler client1 = new ClientHandler(chatServer, null); - ClientHandler client2 = new ClientHandler(chatServer, null); - chatServer.getClients().add(client1); - chatServer.getClients().add(client2); - - // Act - chatServer.broadcastMessage("Test message"); - - // Assert - List clients = chatServer.getClients(); - for (ClientHandler client : clients) { - assertEquals("Test message", client.getLastMessage()); - } - } -} - -