Add files via upload
This commit is contained in:
108
src/main/java/envoy/client/ui/ChatWindow.java
Normal file
108
src/main/java/envoy/client/ui/ChatWindow.java
Normal file
@ -0,0 +1,108 @@
|
||||
package envoy.client.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JTextPane;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.datatype.DatatypeConfigurationException;
|
||||
|
||||
import envoy.client.EnvoyClient;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Color;
|
||||
|
||||
/**
|
||||
* Project: <strong>envoy-client</strong><br>
|
||||
* File: <strong>ChatWindow.java</strong><br>
|
||||
* Created: <strong>28 Sep 2019</strong><br>
|
||||
* Author: <strong>Maximilian Käfer </strong>
|
||||
*/
|
||||
|
||||
public class ChatWindow extends JFrame {
|
||||
|
||||
private JPanel contentPane;
|
||||
EnvoyClient envoyClient = new EnvoyClient();
|
||||
|
||||
public ChatWindow() {
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 600, 800);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBackground(new Color(220, 220, 220));
|
||||
contentPane.setForeground(new Color(0, 0, 0));
|
||||
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.gridwidth = 10;
|
||||
|
||||
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(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
if(messageEnterTextfield.getText().isEmpty() == false) {
|
||||
envoyClient.setContent(messageEnterTextfield.getText());
|
||||
envoyClient.sendMessage();
|
||||
}
|
||||
|
||||
} catch (DatatypeConfigurationException | JAXBException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user