Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////// THIS METHOD IS CALLED FIRST, DISPLAYING THE PANE INITIALLY
- public static void DisplayLoginMenu(Container pane) {
- pane.removeAll();
- pane.setLayout(new GridBagLayout());
- final JPasswordField passwordTextfield;
- final JTextField usernameTextfield;
- JButton loginButton, registerButton;
- GridBagConstraints c = new GridBagConstraints();
- JLabel whitespace;
- whitespace = new JLabel("");
- c.weightx = 0.5;
- c.weighty= 0.5;
- c.fill = GridBagConstraints.HORIZONTAL;
- c.gridx = 0;
- c.gridy = 0;
- pane.add(whitespace, c);
- whitespace = new JLabel("");
- c.gridx = 3;
- pane.add(whitespace, c);
- picture = new JLabel(javaChat);
- picture.setHorizontalAlignment(JLabel.CENTER);//centers, otherwise it will flow from the very left, which looks unclean
- picture.setOpaque(true);
- picture.setBackground(Color.black);
- //c.ipady = 150;
- c.weightx = 1;
- c.gridwidth = 2;
- c.gridx = 1;
- c.gridy = 0;
- pane.add(picture, c);
- JLabel usernameLabel = new JLabel("Username:");
- c.gridwidth = 1; //reset to default
- c.ipady = 0; //reset to default
- c.weightx = 0.25;
- c.gridx = 1;
- c.gridy = 2;
- pane.add(usernameLabel, c);
- usernameTextfield = new JTextField();
- c.gridx = 2;
- c.weightx = 1.75;
- c.gridy = 2;
- pane.add(usernameTextfield, c);
- JLabel passwordLabel = new JLabel("Password:");
- c.ipady = 0; //reset to default
- c.weightx = 0.25;
- c.gridx = 1;
- c.gridy = 3;
- pane.add(passwordLabel, c);
- passwordTextfield = new JPasswordField();
- c.weightx = 1.75;
- c.gridx = 2;
- c.gridy = 3;
- pane.add(passwordTextfield, c);
- registerButton = new JButton("Register");
- c.weightx = 1.75;
- c.gridx = 2;
- c.gridy = 5;
- pane.add(registerButton, c);
- loginButton = new JButton("Login");
- c.fill = GridBagConstraints.HORIZONTAL;
- c.ipady = 40; //make this component tall
- c.gridwidth = 2;
- c.gridx = 1;
- c.gridy = 4;
- pane.add(loginButton, c);
- JLabel copyrightLabel = new JLabel("© 2011 - Michael Foley");
- copyrightLabel.setHorizontalAlignment(JLabel.CENTER);
- copyrightLabel.setForeground(Color.GRAY);
- c.fill = GridBagConstraints.HORIZONTAL;
- c.ipady = 0; //reset to default
- c.anchor = GridBagConstraints.PAGE_END; //bottom of space
- c.gridy = 7;
- pane.add(copyrightLabel, c);
- ActionListener loginRegisterListener = new ActionListener() {
- public void actionPerformed(ActionEvent event) {
- if (event.getActionCommand()=="Login"){
- char[] passArray = passwordTextfield.getPassword();//moves the char array that the JTextField has into a separate array
- //though the JPasswordField is an extension of the JTextField, the .getText method has been depreciated
- String password = "";//the file the password is moved to before sending it off
- for (int i=0; i < passArray.length; i++){//moves the chars in the array into the password string
- password=password+passArray[i];
- }
- //DisplayLoggedIn(menuFrame.getContentPane());
- //send login to the server
- new ClientListenerThread(usernameTextfield.getText(),password);
- }
- if (event.getActionCommand()=="Register"){
- DisplayRegisterMenu(registerMenuFrame.getContentPane());
- registerMessage.setText("Register");
- registerMenuFrame.setSize(500,200);
- registerMenuFrame.setVisible(true);
- }
- }
- };
- loginButton.addActionListener(loginRegisterListener);
- registerButton.addActionListener(loginRegisterListener);
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////
- /////////////////// THIS METHOD IS THEN CALLED UP:
- public static void DisplayLoggedIn(Container pane){
- pane.removeAll();
- JPanel buttonPannel = new JPanel();
- JButton addFriendButton = new JButton("Add Friend");
- JButton delFriendButton = new JButton("Remove Friend");
- JButton startConvoButton = new JButton("Chat");
- JButton logoutButton = new JButton("Logout");
- buttonPannel.setLayout(new GridLayout(2,2));
- JScrollPane scrollPane = new JScrollPane();
- JPanel friendListPanel = new JPanel();
- buttonPannel.add(addFriendButton);
- buttonPannel.add(delFriendButton);
- buttonPannel.add(startConvoButton);
- buttonPannel.add(logoutButton);
- pane.setLayout(new BorderLayout());
- pane.add(buttonPannel, BorderLayout.NORTH);
- pane.add(scrollPane, BorderLayout.CENTER);
- scrollPane.add(friendListPanel);
- menuFrame.setVisible(false);
- menuFrame.setVisible(true);
- ActionListener loggedInListener = new ActionListener() {
- public void actionPerformed(ActionEvent event) {
- if (event.getActionCommand()=="Add Friend"){
- JFrame addFriendFrame = new JFrame("Add Friend");
- DisplayAddFriendMenu(addFriendFrame.getContentPane());
- addFriendFrame.setVisible(true);
- addFriendFrame.setSize(400,150);
- //end addfriend
- }
- if (event.getActionCommand()=="Revmove Friend"){
- }
- if (event.getActionCommand()=="Chat"){
- }
- if (event.getActionCommand()=="Logout"){
- ClientListenerThread.Logout();
- }
- }
- };
- addFriendButton.addActionListener(loggedInListener);
- delFriendButton.addActionListener(loggedInListener);
- startConvoButton.addActionListener(loggedInListener);
- logoutButton.addActionListener(loggedInListener);
- }
- //////////// AND THEN THE FIRST METHOD
- THE PROBLEM ISN'T OCCURRING WITH THE FIRST SWITCH, BUT WITH THE SECOND
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement