Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.58 KB | None | 0 0
  1. ///////////////////////////////////////////////////////////////////////////////////////////////
  2. ////////////////// THIS METHOD IS CALLED FIRST, DISPLAYING THE PANE INITIALLY
  3. public static void DisplayLoginMenu(Container pane) {
  4. pane.removeAll();
  5. pane.setLayout(new GridBagLayout());
  6.  
  7. final JPasswordField passwordTextfield;
  8. final JTextField usernameTextfield;
  9. JButton loginButton, registerButton;
  10.  
  11.  
  12. GridBagConstraints c = new GridBagConstraints();
  13. JLabel whitespace;
  14.  
  15. whitespace = new JLabel("");
  16. c.weightx = 0.5;
  17. c.weighty= 0.5;
  18. c.fill = GridBagConstraints.HORIZONTAL;
  19. c.gridx = 0;
  20. c.gridy = 0;
  21. pane.add(whitespace, c);
  22.  
  23.  
  24.  
  25. whitespace = new JLabel("");
  26. c.gridx = 3;
  27. pane.add(whitespace, c);
  28.  
  29. picture = new JLabel(javaChat);
  30. picture.setHorizontalAlignment(JLabel.CENTER);//centers, otherwise it will flow from the very left, which looks unclean
  31. picture.setOpaque(true);
  32. picture.setBackground(Color.black);
  33. //c.ipady = 150;
  34. c.weightx = 1;
  35. c.gridwidth = 2;
  36. c.gridx = 1;
  37. c.gridy = 0;
  38. pane.add(picture, c);
  39.  
  40. JLabel usernameLabel = new JLabel("Username:");
  41. c.gridwidth = 1; //reset to default
  42. c.ipady = 0; //reset to default
  43. c.weightx = 0.25;
  44. c.gridx = 1;
  45. c.gridy = 2;
  46. pane.add(usernameLabel, c);
  47.  
  48. usernameTextfield = new JTextField();
  49. c.gridx = 2;
  50. c.weightx = 1.75;
  51. c.gridy = 2;
  52. pane.add(usernameTextfield, c);
  53.  
  54. JLabel passwordLabel = new JLabel("Password:");
  55. c.ipady = 0; //reset to default
  56. c.weightx = 0.25;
  57. c.gridx = 1;
  58. c.gridy = 3;
  59. pane.add(passwordLabel, c);
  60.  
  61. passwordTextfield = new JPasswordField();
  62.  
  63. c.weightx = 1.75;
  64. c.gridx = 2;
  65. c.gridy = 3;
  66. pane.add(passwordTextfield, c);
  67.  
  68. registerButton = new JButton("Register");
  69. c.weightx = 1.75;
  70. c.gridx = 2;
  71. c.gridy = 5;
  72. pane.add(registerButton, c);
  73.  
  74. loginButton = new JButton("Login");
  75. c.fill = GridBagConstraints.HORIZONTAL;
  76. c.ipady = 40; //make this component tall
  77. c.gridwidth = 2;
  78. c.gridx = 1;
  79. c.gridy = 4;
  80. pane.add(loginButton, c);
  81.  
  82. JLabel copyrightLabel = new JLabel("© 2011 - Michael Foley");
  83. copyrightLabel.setHorizontalAlignment(JLabel.CENTER);
  84. copyrightLabel.setForeground(Color.GRAY);
  85. c.fill = GridBagConstraints.HORIZONTAL;
  86. c.ipady = 0; //reset to default
  87. c.anchor = GridBagConstraints.PAGE_END; //bottom of space
  88. c.gridy = 7;
  89. pane.add(copyrightLabel, c);
  90. ActionListener loginRegisterListener = new ActionListener() {
  91.  
  92. public void actionPerformed(ActionEvent event) {
  93. if (event.getActionCommand()=="Login"){
  94. char[] passArray = passwordTextfield.getPassword();//moves the char array that the JTextField has into a separate array
  95. //though the JPasswordField is an extension of the JTextField, the .getText method has been depreciated
  96. String password = "";//the file the password is moved to before sending it off
  97. for (int i=0; i < passArray.length; i++){//moves the chars in the array into the password string
  98. password=password+passArray[i];
  99. }
  100.  
  101. //DisplayLoggedIn(menuFrame.getContentPane());
  102. //send login to the server
  103. new ClientListenerThread(usernameTextfield.getText(),password);
  104. }
  105. if (event.getActionCommand()=="Register"){
  106. DisplayRegisterMenu(registerMenuFrame.getContentPane());
  107. registerMessage.setText("Register");
  108. registerMenuFrame.setSize(500,200);
  109. registerMenuFrame.setVisible(true);
  110. }
  111.  
  112. }
  113. };
  114. loginButton.addActionListener(loginRegisterListener);
  115. registerButton.addActionListener(loginRegisterListener);
  116.  
  117. }
  118.  
  119. ///////////////////////////////////////////////////////////////////////////////////////////////
  120. /////////////////// THIS METHOD IS THEN CALLED UP:
  121.  
  122. public static void DisplayLoggedIn(Container pane){
  123. pane.removeAll();
  124.  
  125. JPanel buttonPannel = new JPanel();
  126. JButton addFriendButton = new JButton("Add Friend");
  127. JButton delFriendButton = new JButton("Remove Friend");
  128. JButton startConvoButton = new JButton("Chat");
  129. JButton logoutButton = new JButton("Logout");
  130. buttonPannel.setLayout(new GridLayout(2,2));
  131.  
  132. JScrollPane scrollPane = new JScrollPane();
  133. JPanel friendListPanel = new JPanel();
  134.  
  135.  
  136. buttonPannel.add(addFriendButton);
  137. buttonPannel.add(delFriendButton);
  138. buttonPannel.add(startConvoButton);
  139. buttonPannel.add(logoutButton);
  140. pane.setLayout(new BorderLayout());
  141. pane.add(buttonPannel, BorderLayout.NORTH);
  142. pane.add(scrollPane, BorderLayout.CENTER);
  143.  
  144. scrollPane.add(friendListPanel);
  145.  
  146.  
  147.  
  148.  
  149. menuFrame.setVisible(false);
  150. menuFrame.setVisible(true);
  151.  
  152. ActionListener loggedInListener = new ActionListener() {
  153.  
  154. public void actionPerformed(ActionEvent event) {
  155. if (event.getActionCommand()=="Add Friend"){
  156. JFrame addFriendFrame = new JFrame("Add Friend");
  157. DisplayAddFriendMenu(addFriendFrame.getContentPane());
  158. addFriendFrame.setVisible(true);
  159. addFriendFrame.setSize(400,150);
  160. //end addfriend
  161.  
  162. }
  163. if (event.getActionCommand()=="Revmove Friend"){
  164.  
  165. }
  166. if (event.getActionCommand()=="Chat"){
  167.  
  168. }
  169. if (event.getActionCommand()=="Logout"){
  170. ClientListenerThread.Logout();
  171. }
  172. }
  173. };
  174. addFriendButton.addActionListener(loggedInListener);
  175. delFriendButton.addActionListener(loggedInListener);
  176. startConvoButton.addActionListener(loggedInListener);
  177. logoutButton.addActionListener(loggedInListener);
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185. }
  186. //////////// AND THEN THE FIRST METHOD
  187. THE PROBLEM ISN'T OCCURRING WITH THE FIRST SWITCH, BUT WITH THE SECOND
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement