diff --git a/src/main/java/ChatGUI.java b/src/main/java/ChatGUI.java index 2f8e4ad..6ad34f1 100644 --- a/src/main/java/ChatGUI.java +++ b/src/main/java/ChatGUI.java @@ -33,8 +33,8 @@ public class ChatGUI implements ActionListener { JMenuItem green = new JMenuItem("green"); JMenuItem exit = new JMenuItem("Exit"); - - private JButton popupButton; + + JButton popupButton; JTextField inputTextField = new JTextField(); JTextArea outputTextArea = new JTextArea(); @@ -59,7 +59,9 @@ public class ChatGUI implements ActionListener { JMenu colors = new JMenu("font-colors"); JMenu size = new JMenu("font-size"); + // Create Pop-Up Button popupButton = new JButton("Popup-Nachricht senden"); + popupButton.addActionListener(this); JMenu menu = new JMenu("File"); menu.add(exit); @@ -117,7 +119,7 @@ public class ChatGUI implements ActionListener { new ChatGUI(); } - + // add-message method with time stamp void addMessage(String message) { String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date()); @@ -155,15 +157,16 @@ public class ChatGUI implements ActionListener { if (e.getSource() == large) { outputTextArea.setFont(outputTextArea.getFont().deriveFont(Font.PLAIN, 20)); } + if (e.getSource() == popupButton) { + String message = inputTextField.getText(); + inputTextField.setText(""); + sendPopupMessage(message); + } - } - public class NotificationManager { - - public void sendPopupMessage(String message) { - JOptionPane.showMessageDialog(gui, message); - } + public void sendPopupMessage(String message) { + JOptionPane.showMessageDialog(gui, message); + } } -} diff --git a/src/test/java/ChatGUITest.java b/src/test/java/ChatGUITest.java index 2931dad..f38488e 100644 --- a/src/test/java/ChatGUITest.java +++ b/src/test/java/ChatGUITest.java @@ -92,6 +92,16 @@ public class ChatGUITest { assertTrue(chatGUI.outputTextArea.getText().contains(expectedMessage)); } + @Test + public void testSendPopupMessage() { + ChatGUI chatGUI = new ChatGUI(); + + + String testMessage = "Test Popup-Nachricht"; + + + chatGUI.sendPopupMessage(testMessage); + } }