This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
envoy/src/main/java/envoy/client/ui/ChatWindow.java

99 lines
3.2 KiB
Java

package envoy.client.ui;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.border.EmptyBorder;
import envoy.client.EnvoyClient;
/**
* Project: <strong>envoy-client</strong><br>
* File: <strong>ChatWindow.java</strong><br>
* Created: <strong>28 Sep 2019</strong><br>
* Author: <strong>Maximilian K&aumlfer &amp; Kai S. K. Engelbart</strong>
*/
public class ChatWindow extends JFrame {
private static final long serialVersionUID = 6865098428255463649L;
private JPanel contentPane = new JPanel();
private EnvoyClient envoyClient = new EnvoyClient();
public ChatWindow() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 600, 800);
setTitle("Envoy");
setLocationRelativeTo(null);
contentPane.setBackground(new Color(220, 220, 220));
contentPane.setForeground(Color.white);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
GridBagLayout gbl_contentPane = new GridBagLayout();
gbl_contentPane.columnWidths = new int[] { 1, 1, 1 };
gbl_contentPane.rowHeights = new int[] { 1, 1, 1 };
gbl_contentPane.columnWeights = new double[] { 0.3, 1.0, 0.1 };
gbl_contentPane.rowWeights = new double[] { 0.05, 1, 0.07 };
contentPane.setLayout(gbl_contentPane);
// Message enter field
JTextArea messageEnterTextfield = new JTextArea();
messageEnterTextfield.setLineWrap(true);
GridBagConstraints gbc_moveSelectionMessageEnterTextfield = new GridBagConstraints();
gbc_moveSelectionMessageEnterTextfield.fill = GridBagConstraints.BOTH;
gbc_moveSelectionMessageEnterTextfield.gridx = 1;
gbc_moveSelectionMessageEnterTextfield.gridy = 2;
gbc_moveSelectionMessageEnterTextfield.insets = new Insets(10, 10, 10, 10);
contentPane.add(messageEnterTextfield, gbc_moveSelectionMessageEnterTextfield);
// Post Button
JButton postButton = new JButton("Post");
postButton.setForeground(new Color(255, 255, 255));
postButton.setBackground(new Color(0, 100, 0));
GridBagConstraints gbc_moveSelectionPostButton = new GridBagConstraints();
gbc_moveSelectionPostButton.fill = GridBagConstraints.BOTH;
gbc_moveSelectionPostButton.gridx = 2;
gbc_moveSelectionPostButton.gridy = 2;
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());
} catch (Exception e) {
JOptionPane.showMessageDialog(this,
"An exception occured while sending a message. See the log for more details.",
"Exception occured",
JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}
});
}
public static void main(String[] args) {
EventQueue.invokeLater(() -> {
try {
ChatWindow frame = new ChatWindow();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
});
}
}