" + getSenderElement(testMessages.get(i)) + " " + "
" + "
" + getFirstContentElement(testMessages.get(i)) + ""); + } + + + + JScrollPane scrollPane = new JScrollPane(); + scrollPane.setForeground(new Color(0, 0, 0)); + scrollPane.setBackground(new Color(51, 51, 51)); + scrollPane.setViewportView(elementList); + scrollPane.setBorder(null); + + GridBagConstraints gbc_scrollPane = new GridBagConstraints(); + gbc_scrollPane.fill = GridBagConstraints.BOTH; + gbc_scrollPane.gridwidth = 2; + gbc_scrollPane.gridx = 1; + gbc_scrollPane.gridy = 1; + + + gbc_scrollPane.insets = new Insets(10, 10, 10, 10); + + contentPane.add(scrollPane, gbc_scrollPane); + + + // Message enter field----------------- JTextArea messageEnterTextfield = new JTextArea(); + messageEnterTextfield.setCaretColor(new Color(255, 255, 255)); + messageEnterTextfield.setForeground(new Color(255, 255, 255)); + messageEnterTextfield.setBackground(new Color(51, 51, 51)); messageEnterTextfield.setLineWrap(true); + messageEnterTextfield.setBorder(null); + messageEnterTextfield.setFont( new Font("Arial", Font.PLAIN, 17)); + messageEnterTextfield.setBorder(new EmptyBorder(5, 5, 5, 5)); GridBagConstraints gbc_moveSelectionMessageEnterTextfield = new GridBagConstraints(); gbc_moveSelectionMessageEnterTextfield.fill = GridBagConstraints.BOTH; @@ -58,10 +133,14 @@ public class ChatWindow extends JFrame { contentPane.add(messageEnterTextfield, gbc_moveSelectionMessageEnterTextfield); - // Post Button + + + + // Post Button----------------- JButton postButton = new JButton("Post"); postButton.setForeground(new Color(255, 255, 255)); - postButton.setBackground(new Color(0, 100, 0)); + postButton.setBackground(new Color(102, 51, 153)); + postButton.setBorderPainted(false); GridBagConstraints gbc_moveSelectionPostButton = new GridBagConstraints(); @@ -71,11 +150,14 @@ public class ChatWindow extends JFrame { gbc_moveSelectionPostButton.insets = new Insets(10, 10, 10, 10); + contentPane.add(postButton, gbc_moveSelectionPostButton); postButton.addActionListener((evt) -> { if (!messageEnterTextfield.getText().isEmpty()) try { - envoyClient.sendMessage("Kai", "Maxi", messageEnterTextfield.getText()); + envoyClient.sendMessage(envoyClient.createMessage("Kai", "Maxi", messageEnterTextfield.getText())); + addMessageToChat("Du", messageEnterTextfield.getText()); + messageEnterTextfield.setText(""); } catch (Exception e) { JOptionPane.showMessageDialog(this, "An exception occured while sending a message. See the log for more details.", @@ -85,7 +167,35 @@ public class ChatWindow extends JFrame { } }); } - + + /** + * gets the Sender from the Message + * @param message + * @return + */ + public String getSenderElement (Message message) { + return message.getMetaData().getSender(); + } + + /** + * gets the First Content Element(text) from the Message + * @param message + * @return + */ + public String getFirstContentElement (Message message) { + return message.getContent().get(0).getText(); + } + + /** + * adds the Sender and the First Content Element(text) of the new Message to the listModel + * @param message + * @return + */ + public void addMessageToChat(String Sender, String Content) { + listModel.addElement("" + "
" + Sender + " " + "
" + "
" + Content + ""); + } + + public static void main(String[] args) { EventQueue.invokeLater(() -> { try {