FineNerds

ClientGUI.java

Jul 17th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.93 KB | None | 0 0
  1. package main;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6. import java.io.PrintWriter;
  7. import java.net.Socket;
  8.  
  9. import javax.swing.JButton;
  10. import javax.swing.JFrame;
  11. import javax.swing.JLabel;
  12. import javax.swing.JList;
  13. import javax.swing.JOptionPane;
  14. import javax.swing.JPanel;
  15. import javax.swing.JScrollPane;
  16. import javax.swing.JTextArea;
  17. import javax.swing.JTextField;
  18. import javax.swing.ScrollPaneConstants;
  19. import javax.swing.SwingConstants;
  20.  
  21. public class ClientGUI {
  22.  
  23. //Global Variables
  24. private static Client client;
  25. public static String userName = "";
  26.  
  27. //GUI Global Variables - Main Window
  28. public static JFrame MainWindow = new JFrame();
  29. public static JButton connect = new JButton();
  30. public static JButton disconnect = new JButton();
  31. public static JButton send = new JButton();
  32. private static JLabel conversation = new JLabel();
  33. private static JLabel online = new JLabel();
  34. private static JLabel loggedIn = new JLabel();
  35. private static JLabel loggedInAs = new JLabel();
  36. public static JTextField taMessage = new JTextField();
  37. public static JTextArea taConversation = new JTextArea();
  38. private static JScrollPane spConversation = new JScrollPane();
  39. private static JScrollPane spOnline = new JScrollPane();
  40. public static JList lOnline = new JList();
  41.  
  42. //GUI Global Variables - Login Window
  43. public static JFrame LoginWindow = new JFrame();
  44. public static JTextField username = new JTextField();
  45. private static JButton login = new JButton("Enter");
  46. private static JLabel enterUsername = new JLabel("Enter your desired UserName: ");
  47. private static JPanel pLogin = new JPanel();
  48.  
  49. //-------------------------------------------------------------------------------------
  50.  
  51. public static void main(String args[])
  52. {
  53. BuildMainWindow();
  54. Initialize();
  55. }
  56.  
  57. public static void Connect()
  58. {
  59. try
  60. {
  61. final int port = 2525;
  62. final String host = "LoveTree";
  63. Socket socket = new Socket(host, port);
  64. System.out.println("Connected to: " +host);
  65.  
  66.  
  67. /**PrintWriter out = new PrintWriter(socket);
  68. out.println(username);
  69. out.flush();
  70. client = new Client(socket.getOutputStream());
  71.  
  72. Thread x = new Thread(client);**/
  73. }
  74. catch(Exception e)
  75. {
  76. System.out.println(e);
  77. JOptionPane.showMessageDialog(null, "Server not responding. Try Again.");
  78. System.exit(0);
  79. }
  80. }
  81.  
  82. public static void Initialize()
  83. {
  84. send.setEnabled(false);
  85. connect.setEnabled(false);
  86. disconnect.setEnabled(false);
  87. }
  88.  
  89. public static void BuilLogInWindow()
  90. {
  91. LoginWindow.setTitle("What's your username?");
  92. LoginWindow.setSize(400,100);
  93. LoginWindow.setLocationRelativeTo(null);
  94. LoginWindow.setResizable(false);
  95. pLogin = new JPanel();
  96. pLogin.add(enterUsername);
  97. pLogin.add(username);
  98. pLogin.add(login);
  99. LoginWindow.add(pLogin);
  100.  
  101. //Login_Action();
  102. LoginWindow.setVisible(true);
  103. }
  104.  
  105. public static void BuildMainWindow()
  106. {
  107. MainWindow.setTitle("The Tree");
  108. MainWindow.setSize(615, 375);
  109. MainWindow.setLocationRelativeTo(null);
  110. MainWindow.setResizable(false);
  111. MainWindowProperties();
  112. //MainWindow_Action();
  113. MainWindow.setVisible(true);
  114. }
  115.  
  116. public static void paint(Graphics g)
  117. {
  118. g.setColor(new Color(0, 0, 0));
  119. g.drawRect(496, 296, 2, 2);
  120. g.drawRect(138, 24, 2, 2);
  121. g.drawRect(18, 26, 2, 2);
  122. g.drawRect(15, 269, 2, 2);
  123. }
  124.  
  125. public static void MainWindowProperties()
  126. {
  127. MainWindow.setBackground(new Color(56, 60, 68));
  128. MainWindow.setSize(615, 375);
  129. MainWindow.getContentPane().setLayout(null);
  130.  
  131. send.setBackground(new Color(0, 0, 0));
  132. send.setForeground(new Color(255, 108, 22));
  133. send.setText("Send");
  134. MainWindow.getContentPane().add(send);
  135. send.setBounds(496, 243, 559, 296);
  136.  
  137. disconnect.setBackground(new Color(0, 0, 0));
  138. disconnect.setForeground(new Color(255, 108, 22));
  139. disconnect.setText("Disconnect");
  140. MainWindow.getContentPane().add(disconnect);
  141. send.setBounds(138, 11, 242, 24);
  142.  
  143. connect.setBackground(new Color(0, 0, 0));
  144. connect.setForeground(new Color(255, 108, 22));
  145. connect.setText("Connect");
  146. MainWindow.getContentPane().add(connect);
  147. send.setBounds(18, 11, 122, 24);
  148.  
  149. taMessage.setBackground(new Color(0, 0, 0));
  150. taMessage.setForeground(new Color(255, 255, 255));
  151. taMessage.requestFocus();
  152. MainWindow.getContentPane().add(taMessage);
  153. taMessage.setBounds(15, 31, 487, 269);
  154.  
  155. taConversation.setColumns(24);
  156. taConversation.setFont(new Font("Tahoma", 0, 12));
  157. taConversation.setForeground(new Color(255, 255, 255));
  158. taConversation.setLineWrap(true);
  159. taConversation.setRows(12);
  160. taConversation.setEditable(false);
  161.  
  162. spConversation.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
  163. spConversation.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
  164. spConversation.setViewportView(taConversation);
  165. MainWindow.getContentPane().add(spConversation);
  166. spConversation.setBounds(473, 33, 485, 267);
  167.  
  168. online.setHorizontalAlignment(SwingConstants.CENTER);
  169. online.setText("Online:");
  170. online.setToolTipText("");
  171. MainWindow.getContentPane().add(online);
  172. online.setForeground(new Color(255, 208, 22));
  173. online.setBounds(495, 8, 601, 30);
  174.  
  175. String [] TestNames = {"Jack", "Connor", "Sophie", "Lucy"};
  176. lOnline.setForeground(new Color(255, 255, 255));
  177. lOnline.setListData(TestNames);
  178.  
  179. spOnline.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  180. spOnline.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
  181. spOnline.setViewportView(lOnline);
  182. MainWindow.getContentPane().add(spOnline);
  183. spOnline.setBounds(497, 33, 599, 267);
  184.  
  185. loggedInAs.setFont(new Font("Tahoma", 0, 12));
  186. loggedInAs.setText("Logged in as:");
  187. MainWindow.setContentPane(loggedInAs);
  188. loggedInAs.setForeground(new Color(255, 208, 22));
  189. loggedInAs.setBounds(282, 9, 0, 0);
  190.  
  191. }
  192.  
  193. }
Advertisement
Add Comment
Please, Sign In to add comment