Browse Source

neue Funktionalitäten

remotes/origin/server
Paul Kattenborn 11 months ago
parent
commit
00a5c027fd
  1. 1
      pom.xml
  2. 15
      src/main/java/ChatGUI.java
  3. 23
      src/test/java/ChatGUITest.java

1
pom.xml

@ -34,3 +34,4 @@
</project>

15
src/main/java/ChatGUI.java

@ -5,6 +5,8 @@ import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JButton;
import javax.swing.JFrame;
@ -116,6 +118,14 @@ 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());
outputTextArea.append("[" + timeStamp + "] " + message + "\n");
outputTextArea.setCaretPosition(outputTextArea.getDocument().getLength());
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == exit) {
@ -123,8 +133,8 @@ public class ChatGUI implements ActionListener {
}
if (e.getSource() == inputTextField || e.getSource() == sendButton) {
String inputText = inputTextField.getText();
outputTextArea.append(inputText + "\n");
inputTextField.setText("");
addMessage(inputText);
}
if (e.getSource() == red) {
outputTextArea.setForeground(Color.RED);
@ -146,11 +156,14 @@ public class ChatGUI implements ActionListener {
outputTextArea.setFont(outputTextArea.getFont().deriveFont(Font.PLAIN, 20));
}
}
public class NotificationManager {
public void sendPopupMessage(String message) {
JOptionPane.showMessageDialog(gui, message);
}
}
}

23
src/test/java/ChatGUITest.java

@ -1,8 +1,11 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.junit.Before;
import org.junit.Test;
@ -59,9 +62,11 @@ public class ChatGUITest {
chatGUI.inputTextField.setText("Testnachricht");
chatGUI.sendButton.doClick();
String expectedOutput = "Testnachricht\n";
String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date());
String expectedOutput = "[" + timeStamp + "] Testnachricht\n";
assertEquals(expectedOutput, chatGUI.outputTextArea.getText());
}
@Test
public void testInputTextFieldActionPerformed() {
@ -69,12 +74,24 @@ public class ChatGUITest {
chatGUI.actionPerformed(new ActionEvent(chatGUI.inputTextField, ActionEvent.ACTION_PERFORMED, ""));
String expectedOutput = "Testnachricht\n";
String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date());
String expectedOutput = "[" + timeStamp + "] Testnachricht\n";
assertEquals(expectedOutput, chatGUI.outputTextArea.getText());
assertEquals("", chatGUI.inputTextField.getText());
}
@Test
public void testAddMessage() {
String message = "Testnachricht";
chatGUI.addMessage(message);
String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date());
String expectedMessage = "[" + timeStamp + "] " + message + "\n";
assertTrue(chatGUI.outputTextArea.getText().contains(expectedMessage));
}
}
Loading…
Cancel
Save