client: send and receive network messages
[WeStealzYourDataz.git] / src / uk / ac / ntu / n0521366 / wsyd / client / Chat.java
1 /*
2  * To change this license header, choose License Headers in Project Properties.
3  * To change this template file, choose Tools | Templates
4  * and open the template in the editor.
5  */
6 package uk.ac.ntu.n0521366.wsyd.client;
7
8 /**
9  *
10  * @author Eddie Berrisford-Lynch
11  */
12 public class Chat extends javax.swing.JDialog {
13
14     /**
15      * Creates new form WSYD_Chat
16      */
17     public Chat(java.awt.Frame parent, boolean modal) {
18         super(parent, modal);
19         initComponents();
20     }
21
22     /**
23      * This method is called from within the constructor to initialize the form.
24      * WARNING: Do NOT modify this code. The content of this method is always
25      * regenerated by the Form Editor.
26      */
27     @SuppressWarnings("unchecked")
28     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
29     private void initComponents() {
30         java.awt.GridBagConstraints gridBagConstraints;
31
32         gPanelChatInstance = new javax.swing.JPanel();
33         jScrollPane1 = new javax.swing.JScrollPane();
34         gListChatWindow = new javax.swing.JList();
35         jPanel2 = new javax.swing.JPanel();
36         gButtonAttach = new javax.swing.JButton();
37         jScrollPane2 = new javax.swing.JScrollPane();
38         gTAreaMessage = new javax.swing.JTextArea();
39         gButtonSend = new javax.swing.JButton();
40         gTPanelNewChat = new javax.swing.JTabbedPane();
41
42         gPanelChatInstance.setMinimumSize(new java.awt.Dimension(450, 350));
43         gPanelChatInstance.setPreferredSize(new java.awt.Dimension(450, 350));
44         gPanelChatInstance.setLayout(new java.awt.BorderLayout());
45
46         gListChatWindow.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
47         gListChatWindow.setModel(new javax.swing.AbstractListModel() {
48             String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
49             public int getSize() { return strings.length; }
50             public Object getElementAt(int i) { return strings[i]; }
51         });
52         gListChatWindow.setPreferredSize(new java.awt.Dimension(300, 180));
53         gListChatWindow.setVisibleRowCount(20);
54         jScrollPane1.setViewportView(gListChatWindow);
55
56         gPanelChatInstance.add(jScrollPane1, java.awt.BorderLayout.CENTER);
57
58         jPanel2.setPreferredSize(new java.awt.Dimension(450, 70));
59         jPanel2.setLayout(new java.awt.GridBagLayout());
60
61         gButtonAttach.setFont(new java.awt.Font("Dialog", 1, 10)); // NOI18N
62         gButtonAttach.setText("Attach");
63         gButtonAttach.setPreferredSize(new java.awt.Dimension(94, 50));
64         gridBagConstraints = new java.awt.GridBagConstraints();
65         gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
66         jPanel2.add(gButtonAttach, gridBagConstraints);
67
68         jScrollPane2.setMinimumSize(new java.awt.Dimension(256, 100));
69
70         gTAreaMessage.setColumns(20);
71         gTAreaMessage.setRows(6);
72         jScrollPane2.setViewportView(gTAreaMessage);
73
74         jPanel2.add(jScrollPane2, new java.awt.GridBagConstraints());
75
76         gButtonSend.setText("Send");
77         gButtonSend.setPreferredSize(new java.awt.Dimension(94, 50));
78         gridBagConstraints = new java.awt.GridBagConstraints();
79         gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
80         jPanel2.add(gButtonSend, gridBagConstraints);
81
82         gPanelChatInstance.add(jPanel2, java.awt.BorderLayout.PAGE_END);
83
84         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
85
86         gTPanelNewChat.setMinimumSize(new java.awt.Dimension(450, 350));
87         gTPanelNewChat.setPreferredSize(new java.awt.Dimension(500, 400));
88
89         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
90         getContentPane().setLayout(layout);
91         layout.setHorizontalGroup(
92             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
93             .addComponent(gTPanelNewChat, javax.swing.GroupLayout.PREFERRED_SIZE, 500, javax.swing.GroupLayout.PREFERRED_SIZE)
94         );
95         layout.setVerticalGroup(
96             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
97             .addComponent(gTPanelNewChat, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE)
98         );
99
100         pack();
101     }// </editor-fold>//GEN-END:initComponents
102
103     /**
104      * @param args the command line arguments
105      */
106     public static void main(String args[]) {
107         /* Set the Nimbus look and feel */
108         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
109         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
110          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
111          */
112         try {
113             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
114                 if ("Nimbus".equals(info.getName())) {
115                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
116                     break;
117                 }
118             }
119         } catch (ClassNotFoundException ex) {
120             java.util.logging.Logger.getLogger(Chat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
121         } catch (InstantiationException ex) {
122             java.util.logging.Logger.getLogger(Chat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
123         } catch (IllegalAccessException ex) {
124             java.util.logging.Logger.getLogger(Chat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
125         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
126             java.util.logging.Logger.getLogger(Chat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
127         }
128         //</editor-fold>
129         //</editor-fold>
130
131         /* Create and display the dialog */
132         java.awt.EventQueue.invokeLater(new Runnable() {
133             public void run() {
134                 Chat dialog = new Chat(new javax.swing.JFrame(), true);
135                 dialog.addWindowListener(new java.awt.event.WindowAdapter() {
136                     @Override
137                     public void windowClosing(java.awt.event.WindowEvent e) {
138                         System.exit(0);
139                     }
140                 });
141                 dialog.setVisible(true);
142             }
143         });
144     }
145
146     // Variables declaration - do not modify//GEN-BEGIN:variables
147     private javax.swing.JButton gButtonAttach;
148     private javax.swing.JButton gButtonSend;
149     private javax.swing.JList gListChatWindow;
150     private javax.swing.JPanel gPanelChatInstance;
151     private javax.swing.JTextArea gTAreaMessage;
152     private javax.swing.JTabbedPane gTPanelNewChat;
153     private javax.swing.JPanel jPanel2;
154     private javax.swing.JScrollPane jScrollPane1;
155     private javax.swing.JScrollPane jScrollPane2;
156     // End of variables declaration//GEN-END:variables
157 }