From 13f12889773daf87d29d2304b966147d6c9352ca Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Fri, 9 Feb 2024 19:10:46 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Popup-Button=20Funktionalit=C3=A4t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ChatGUI.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/ChatGUI.java b/src/main/java/ChatGUI.java index 2f8e4ad..a521d26 100644 --- a/src/main/java/ChatGUI.java +++ b/src/main/java/ChatGUI.java @@ -60,6 +60,7 @@ public class ChatGUI implements ActionListener { JMenu size = new JMenu("font-size"); popupButton = new JButton("Popup-Nachricht senden"); + popupButton.addActionListener(this); JMenu menu = new JMenu("File"); menu.add(exit); @@ -155,10 +156,14 @@ 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); @@ -166,4 +171,3 @@ public class ChatGUI implements ActionListener { } -} From a57bfabd7f5d437c65e3ea38e9aca4fda8812e68 Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Fri, 9 Feb 2024 19:12:42 +0100 Subject: [PATCH 2/3] refactoring: Kommentare und Lesbarkeit --- src/main/java/ChatGUI.java | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/ChatGUI.java b/src/main/java/ChatGUI.java index a521d26..93c62e7 100644 --- a/src/main/java/ChatGUI.java +++ b/src/main/java/ChatGUI.java @@ -33,7 +33,7 @@ public class ChatGUI implements ActionListener { JMenuItem green = new JMenuItem("green"); JMenuItem exit = new JMenuItem("Exit"); - + private JButton popupButton; JTextField inputTextField = new JTextField(); @@ -59,6 +59,7 @@ 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); @@ -118,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()); @@ -157,17 +158,15 @@ public class ChatGUI implements ActionListener { outputTextArea.setFont(outputTextArea.getFont().deriveFont(Font.PLAIN, 20)); } if (e.getSource() == popupButton) { - String message = inputTextField.getText(); - inputTextField.setText(""); - sendPopupMessage(message); - } + String message = inputTextField.getText(); + inputTextField.setText(""); + sendPopupMessage(message); + } - } - public void sendPopupMessage(String message) { - JOptionPane.showMessageDialog(gui, message); - } - + public void sendPopupMessage(String message) { + JOptionPane.showMessageDialog(gui, message); + } } From 94c11f755030721d2b76355f2ceeb42ef291acee Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Fri, 9 Feb 2024 19:22:28 +0100 Subject: [PATCH 3/3] test_popupTest --- src/main/java/ChatGUI.java | 2 +- src/test/java/ChatGUITest.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/ChatGUI.java b/src/main/java/ChatGUI.java index 93c62e7..6ad34f1 100644 --- a/src/main/java/ChatGUI.java +++ b/src/main/java/ChatGUI.java @@ -34,7 +34,7 @@ public class ChatGUI implements ActionListener { JMenuItem exit = new JMenuItem("Exit"); - private JButton popupButton; + JButton popupButton; JTextField inputTextField = new JTextField(); JTextArea outputTextArea = new JTextArea(); 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); + } }