Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Chat application Sign in Problem (maybe : Exception)

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Chat application Sign in Problem (maybe : Exception)

    hi everyone, this is my 1st post here

    i'm working on chat application, actually i've done with it, it's work fine BUT when i want to making it look great by adding BG and other thing's it's not working at all

    1st Project code

    Work fine

    Java Class
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    package Client;
    /* Imports the javax.swing package classes. */
    import java.awt.AlphaComposite;
    import java.awt.Color;
    import java.io.IOException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.JPanel;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import javax.swing.JList;
    import javax.swing.JScrollPane;
    import javax.swing.JDialog;
    import javax.swing.JPasswordField;
    import javax.swing.BorderFactory;
    /*Imports the java.awt package classes.*/
    import java.awt.GraphicsEnvironment;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.FlowLayout;
    import java.awt.Font;
    import java.awt.Graphics2D;
    /*Imports the javax.swing.event package classes.*/
    import java.awt.Image;
     
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.JOptionPane;
    import javax.swing.UIManager;
    import javax.swing.JSeparator;
     
    /*
    class ChatLogin - Creates the Chat Login window for the chat application.
          Method:
          - actionPerformed()
          - main()
    */
    public class ChatLogin extends JDialog implements ActionListener
    {
       JPanel panel;
       JPanel pane;
       /* Declares the objects of the JLabel class. */
       JLabel titleLabel;
       JLabel usernameLabel;
       JLabel pwdLabel;
       JLabel localhostLabel;
       /* Declares the objects of JTextField class */
       JTextField usernameText;
       JPasswordField pwdText;
       JTextField localhostText;
       /*Declares the objects of the JButton class.*/
       JButton connect;
       JButton exit;
       GridBagLayout gbl;
       GridBagConstraints gbc;
       int value;
       /* Defines the default constructor.*/
       public ChatLogin()
       {
          /*Sets the title of the Font dialog box.*/
          setTitle("Binatna MSG");
          /*Sets the size of Font dialog box.*/
          setSize(280, 170);
          /*Sets resizable button to FALSE.*/
          setResizable(false);
          /*Initializes the object of the GridBagLayout class*/
          gbl = new GridBagLayout();
          /* Sets the Layout. */
          getContentPane().setLayout(gbl);
          /*Creates an object of the GridBagConstraints class.*/
          gbc = new GridBagConstraints();
          /*
             Initializes the title label object and adds it to the 1, 1, 2, 1 position with WEST
             alignment.
          */
             gbc.gridx = 1;
             gbc.gridy = 1;
             gbc.gridwidth = 2;
             gbc.gridheight = 1;
             gbc.anchor = GridBagConstraints.CENTER;
             pane = new JPanel();
          pane.setLayout(new FlowLayout());
          titleLabel = new JLabel("Sign in");
          titleLabel.setFont(new Font("Verdana",Font.BOLD,20));
          pane.add(titleLabel);
          getContentPane().add(pane, gbc);
          gbc.gridx = 1;
          gbc.gridy = 2;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.WEST;
          getContentPane().add(new JSeparator(), gbc);
          /*
             Initializes the IP address label object and adds it to the 1, 3, 1, 1 position with
             EAST alignment
          */
          gbc.gridx = 1;
          gbc.gridy = 3;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.EAST;
          localhostLabel = new JLabel("Localhost : ");
          getContentPane().add(localhostLabel, gbc);
          /*
    Initializes the IP address text field object and adds it to the 2, 3, 1, 1 position with WEST alignment
          */
          gbc.gridx = 2;
          gbc.gridy = 3;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.WEST;
          localhostText = new JTextField("127.0.0.1", 15);
          localhostText.setFont(new Font("Verdana",Font.PLAIN,12));
          getContentPane().add(localhostText, gbc);
          gbc.gridx = 1;
          gbc.gridy = 4;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.WEST;
          getContentPane().add(new JSeparator(), gbc);
          /*
    Initializes the user name label object and adds it to the 1, 5, 1, 1 position with EAST alignment.
          */
          gbc.gridx = 1;
          gbc.gridy = 5;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.EAST;
          usernameLabel = new JLabel("Username : ");
          getContentPane().add(usernameLabel, gbc);
          /*
             Initializes the user name text field object and adds it to the 2, 5, 1, 1 position with
             WEST alignment.
          */
          gbc.gridx = 2;
          gbc.gridy = 5;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.WEST;
          usernameText = new JTextField(15);
          usernameText.setFont(new Font("Verdana",Font.PLAIN,12));
          getContentPane().add(usernameText, gbc);
          gbc.gridx = 1;
          gbc.gridy = 6;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.WEST;
          getContentPane().add(new JSeparator(), gbc);
          /*
             Initializes the password label object and adds it to the 1, 7, 1, 1 position with EAST
             alignment.
          */
          gbc.gridx = 1;
          gbc.gridy = 7;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.EAST;
          pwdLabel = new JLabel("Password : ");
          getContentPane().add(pwdLabel, gbc);
          /*
             Initializes the password text field object and adds it to the 2, 7, 1, 1 position with
             WEST alignment.
          */
          gbc.gridx = 2;
          gbc.gridy = 7;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.WEST;
          pwdText = new JPasswordField(15);
          pwdText.setFont(new Font("Verdana",Font.PLAIN,12));
          pwdText.addActionListener(this);
          getContentPane().add(pwdText, gbc);
          gbc.gridx = 1;
          gbc.gridy = 8;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.WEST;
          getContentPane().add(new JSeparator(), gbc);
          /*
             Initializes the OK and Cancel button. Adds the button to the 2, 9, 1, 1 position with
             WEST alignment.
          */
          gbc.gridx = 2;
          gbc.gridy = 9;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.WEST;
          panel = new JPanel();
          panel.setLayout(new FlowLayout(FlowLayout.LEFT));
          connect = new JButton("Connect");
          connect.addActionListener(this);
          exit = new JButton("Exit");
          exit.addActionListener(this);
          panel.add(connect);
          panel.add(exit);
          getContentPane().add(panel, gbc);
     
          addWindowListener(new WindowAdapter()
          {
             public void windowClosing(WindowEvent we)
             {
                System.exit(0);
             }
          });
       }
       /*
    actionPerformed() - This method is called when the user clicks the any button.
    Parameters:	ae: Represents an object of the ActionEvent class that contains the details of the event.
       Return Value: NA
       */
       public void actionPerformed(ActionEvent ae)
       {
          if(ae.getSource() == connect)
          {
                try {
                    /*Creates an object of the ChatClient class.*/
                    ChatClient tcc = new ChatClient();
                    /*Calls the con() method to connect to the server.*/
                    tcc.con(localhostText.getText(), usernameText.getText(), pwdText.getText());
                    this.setVisible(false);
                } catch (IOException ex) {
                    Logger.getLogger(ChatLogin.class.getName()).log(Level.SEVERE, null, ex);
                }
          }
          else if(ae.getSource() == exit)
          {
             System.exit(0);
          }
          else if(ae.getSource() == pwdText)
          {
                try {
                    /*Creates an object of the ChatClient class.*/
                    ChatClient tcc = new ChatClient();
                    /*Calls the con() method to connect to the server.*/
                    tcc.con(localhostText.getText(), usernameText.getText(), pwdText.getText());
                    this.setVisible(false);
                } catch (IOException ex) {
                    Logger.getLogger(ChatLogin.class.getName()).log(Level.SEVERE, null, ex);
                }
             }
             }
             /*Main method.*/
             public static void main(String args[])
             {
                try
                {
                   /*Sets the window look and feel to the application.*/
                   UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                }
                catch(Exception e){}
                ChatLogin cl = new ChatLogin();
                cl.show();
          }
    }

    ---------------------------------------------------------
    2nd Project Not Working
    (
    - i used NetBeans
    - there is a red square alert beside 1st and 2nd Exception
    - i can't get access to ChatClient when i click connect button or exit when i click exit button)

    JFrame Form

    package Client;
     
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.IOException;
    import java.io.IOException.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
     
     
        // Variables declaration - do not modify
    /**
     *
     * @author Aymane
     */
    public class ChatLogin extends javax.swing.JFrame implements ActionListener {
     
        /*ActionPerfermed Start*/
           public void actionPerformed(ActionEvent ae) {
          if(ae.getSource() == connect_button)
          {
                try {
                    /*Creates an object of the ChatClient class.*/
                    ChatClient tcc = new ChatClient();
                    /*Calls the con() method to connect to the server.*/
                    tcc.con(localhost_text_field.getText(), username_text_field.getText(), password_text_field.getText());
                    this.setVisible(false);
                } catch (IOException ex) {
                    Logger.getLogger(ChatLogin.class.getName()).log(Level.SEVERE, null, ex);
                }
          }
          else if(ae.getSource() == exit_button)
          {
             System.exit(0);
          }
          else if(ae.getSource() == password_text_field)
          {
                try {
                    /*Creates an object of the ChatClient class.*/
                    ChatClient tcc = new ChatClient();
                    /*Calls the con() method to connect to the server.*/
                    tcc.con(localhost_text_field.getText(), username_text_field.getText(), password_text_field.getText());
                    this.setVisible(false);
                }
                catch (IOException ex) {
                    Logger.getLogger(ChatLogin.class.getName()).log(Level.SEVERE, null, ex);
                }
             }
             }
        /*ActionPerformd end*/
     
        /** Creates new form ChatLogin */
        public ChatLogin() {
            initComponents();
        }
     
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
     
            localhost_text_field = new javax.swing.JTextField();
            username_text_field = new javax.swing.JTextField();
            connect_button = new javax.swing.JButton();
            exit_button = new javax.swing.JButton();
            password_text_field = new javax.swing.JPasswordField();
            jLabel1 = new javax.swing.JLabel();
            jMenuBar1 = new javax.swing.JMenuBar();
            file_menu = new javax.swing.JMenu();
            connect_menu_item = new javax.swing.JMenuItem();
            jSeparator1 = new javax.swing.JPopupMenu.Separator();
            exit_menu_item = new javax.swing.JMenuItem();
            about_menu = new javax.swing.JMenu();
            application_menu_item = new javax.swing.JMenuItem();
            jSeparator2 = new javax.swing.JPopupMenu.Separator();
            aymane_menu_item = new javax.swing.JMenuItem();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setMinimumSize(new java.awt.Dimension(350, 510));
            setResizable(false);
            getContentPane().setLayout(null);
     
            localhost_text_field.setFont(new java.awt.Font("Tahoma", 1, 14));
            localhost_text_field.setForeground(new java.awt.Color(196, 0, 0));
            localhost_text_field.setText("127.0.0.1");
            localhost_text_field.setAlignmentX(0.0F);
            localhost_text_field.setAlignmentY(0.0F);
            localhost_text_field.setBorder(null);
            localhost_text_field.setOpaque(false);
            getContentPane().add(localhost_text_field);
            localhost_text_field.setBounds(87, 196, 176, 30);
     
            username_text_field.setFont(new java.awt.Font("Tahoma", 1, 14));
            username_text_field.setForeground(new java.awt.Color(190, 0, 0));
            username_text_field.setText("Aymane");
            username_text_field.setBorder(null);
            username_text_field.setOpaque(false);
            getContentPane().add(username_text_field);
            username_text_field.setBounds(87, 266, 176, 30);
     
            connect_button.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
            connect_button.setForeground(new java.awt.Color(255, 255, 255));
            connect_button.setText("Connect");
            connect_button.setAlignmentY(0.0F);
            connect_button.setBorderPainted(false);
            connect_button.setContentAreaFilled(false);
            getContentPane().add(connect_button);
            connect_button.setBounds(90, 424, 100, 25);
     
            exit_button.setFont(new java.awt.Font("Tahoma", 1, 14));
            exit_button.setForeground(new java.awt.Color(255, 255, 255));
            exit_button.setText("Exit");
            exit_button.setBorderPainted(false);
            exit_button.setContentAreaFilled(false);
            getContentPane().add(exit_button);
            exit_button.setBounds(190, 424, 73, 25);
     
            password_text_field.setFont(new java.awt.Font("Tahoma", 0, 14));
            password_text_field.setForeground(new java.awt.Color(190, 0, 0));
            password_text_field.setText("Password");
            password_text_field.setAlignmentX(0.0F);
            password_text_field.setAlignmentY(0.0F);
            password_text_field.setBorder(null);
            password_text_field.setOpaque(false);
            getContentPane().add(password_text_field);
            password_text_field.setBounds(87, 337, 176, 30);
     
            jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/bg.png"))); // NOI18N
            jLabel1.setVerticalAlignment(javax.swing.SwingConstants.TOP);
            jLabel1.setAlignmentY(0.0F);
            jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
            jLabel1.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
            getContentPane().add(jLabel1);
            jLabel1.setBounds(0, 0, 350, 450);
     
            jMenuBar1.setBackground(new java.awt.Color(0, 0, 0));
            jMenuBar1.setBorder(null);
            jMenuBar1.setForeground(new java.awt.Color(190, 0, 0));
            jMenuBar1.setAlignmentX(0.0F);
            jMenuBar1.setBorderPainted(false);
     
            file_menu.setBackground(new java.awt.Color(0, 0, 0));
            file_menu.setForeground(new java.awt.Color(190, 0, 0));
            file_menu.setText("File");
            file_menu.setAlignmentX(0.0F);
            file_menu.setAlignmentY(0.0F);
            file_menu.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
            file_menu.setOpaque(true);
     
            connect_menu_item.setBackground(new java.awt.Color(0, 0, 0));
            connect_menu_item.setForeground(new java.awt.Color(190, 0, 0));
            connect_menu_item.setText("Connect");
            connect_menu_item.setInheritsPopupMenu(true);
            file_menu.add(connect_menu_item);
     
            jSeparator1.setBackground(new java.awt.Color(255, 255, 255));
            file_menu.add(jSeparator1);
     
            exit_menu_item.setBackground(new java.awt.Color(0, 0, 0));
            exit_menu_item.setForeground(new java.awt.Color(190, 0, 0));
            exit_menu_item.setText("Exit");
            file_menu.add(exit_menu_item);
     
            jMenuBar1.add(file_menu);
     
            about_menu.setForeground(new java.awt.Color(190, 0, 0));
            about_menu.setText("About");
            about_menu.setAutoscrolls(true);
     
            application_menu_item.setBackground(new java.awt.Color(0, 0, 0));
            application_menu_item.setForeground(new java.awt.Color(190, 0, 0));
            application_menu_item.setText("Binatna Chat");
            application_menu_item.setBorder(null);
            about_menu.add(application_menu_item);
            about_menu.add(jSeparator2);
     
            aymane_menu_item.setBackground(new java.awt.Color(0, 0, 0));
            aymane_menu_item.setForeground(new java.awt.Color(190, 0, 0));
            aymane_menu_item.setText("Aymane Tech");
            aymane_menu_item.setBorder(null);
            about_menu.add(aymane_menu_item);
     
            jMenuBar1.add(about_menu);
     
            setJMenuBar(jMenuBar1);
     
            pack();
        }// </editor-fold>                        
     
        /**/
     
        /**/
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
     
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new ChatLogin().setVisible(true);
                }
            });
     
     
     
        // Variables declaration - do not modify                     
        private javax.swing.JMenu about_menu;
        private javax.swing.JMenuItem application_menu_item;
        private javax.swing.JMenuItem aymane_menu_item;
        private javax.swing.JButton connect_button;
        private javax.swing.JMenuItem connect_menu_item;
        private javax.swing.JButton exit_button;
        private javax.swing.JMenuItem exit_menu_item;
        private javax.swing.JMenu file_menu;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JMenuBar jMenuBar1;
        private javax.swing.JPopupMenu.Separator jSeparator1;
        private javax.swing.JPopupMenu.Separator jSeparator2;
        private javax.swing.JTextField localhost_text_field;
        private javax.swing.JPasswordField password_text_field;
        private javax.swing.JTextField username_text_field;
        // End of variables declaration                   
     
    }

    plz help me!!!!!!!!!!!


  2. #2
    Junior Member
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Chat application Sign in Problem (maybe : Exception)


    didn't expect this result, anyway

    can anyone help me in this one

    i want to add background image to this code

    import java.awt.AlphaComposite;
    import java.awt.Color;
    import java.io.IOException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.JPanel;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import javax.swing.JList;
    import javax.swing.JScrollPane;
    import javax.swing.JDialog;
    import javax.swing.JPasswordField;
    import javax.swing.BorderFactory;
    import java.awt.GraphicsEnvironment;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.FlowLayout;
    import java.awt.Font;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.JOptionPane;
    import javax.swing.UIManager;
    import javax.swing.JSeparator;
     
    /*
    class ChatLogin - Creates the Chat Login window for the chat application.
          Method:
          - actionPerformed()
          - main()
    */
    public class ChatLogin extends JDialog implements ActionListener
    {
       JPanel panel;
       JPanel pane;
       /* Declares the objects of the JLabel class. */
       JLabel titleLabel;
       JLabel usernameLabel;
       JLabel pwdLabel;
       JLabel localhostLabel;
       /* Declares the objects of JTextField class */
       JTextField usernameText;
       JPasswordField pwdText;
       JTextField localhostText;
       /*Declares the objects of the JButton class.*/
       JButton connect;
       JButton exit;
       GridBagLayout gbl;
       GridBagConstraints gbc;
       int value;
       /* Defines the default constructor.*/
       public ChatLogin()
       {
          /*Sets the title of the Font dialog box.*/
          setTitle("Binatna MSG");
          /*Sets the size of Font dialog box.*/
          setSize(280, 170);
          /*Sets resizable button to FALSE.*/
          setResizable(false);
          /*Initializes the object of the GridBagLayout class*/
          gbl = new GridBagLayout();
          /* Sets the Layout. */
          getContentPane().setLayout(gbl);
          /*Creates an object of the GridBagConstraints class.*/
          gbc = new GridBagConstraints();
          /*
             Initializes the title label object and adds it to the 1, 1, 2, 1 position with WEST
             alignment.
          */
             gbc.gridx = 1;
             gbc.gridy = 1;
             gbc.gridwidth = 2;
             gbc.gridheight = 1;
             gbc.anchor = GridBagConstraints.CENTER;
             pane = new JPanel();
          pane.setLayout(new FlowLayout());
          titleLabel = new JLabel("Sign in");
          titleLabel.setFont(new Font("Verdana",Font.BOLD,20));
          pane.add(titleLabel);
          getContentPane().add(pane, gbc);
          gbc.gridx = 1;
          gbc.gridy = 2;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.WEST;
          getContentPane().add(new JSeparator(), gbc);
          /*
             Initializes the IP address label object and adds it to the 1, 3, 1, 1 position with
             EAST alignment
          */
          gbc.gridx = 1;
          gbc.gridy = 3;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.EAST;
          localhostLabel = new JLabel("Localhost : ");
          getContentPane().add(localhostLabel, gbc);
          /*
    Initializes the IP address text field object and adds it to the 2, 3, 1, 1 position with WEST alignment
          */
          gbc.gridx = 2;
          gbc.gridy = 3;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.WEST;
          localhostText = new JTextField("127.0.0.1", 15);
          localhostText.setFont(new Font("Verdana",Font.PLAIN,12));
          getContentPane().add(localhostText, gbc);
          gbc.gridx = 1;
          gbc.gridy = 4;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.WEST;
          getContentPane().add(new JSeparator(), gbc);
          /*
    Initializes the user name label object and adds it to the 1, 5, 1, 1 position with EAST alignment.
          */
          gbc.gridx = 1;
          gbc.gridy = 5;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.EAST;
          usernameLabel = new JLabel("Username : ");
          getContentPane().add(usernameLabel, gbc);
          /*
             Initializes the user name text field object and adds it to the 2, 5, 1, 1 position with
             WEST alignment.
          */
          gbc.gridx = 2;
          gbc.gridy = 5;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.WEST;
          usernameText = new JTextField(15);
          usernameText.setFont(new Font("Verdana",Font.PLAIN,12));
          getContentPane().add(usernameText, gbc);
          gbc.gridx = 1;
          gbc.gridy = 6;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.WEST;
          getContentPane().add(new JSeparator(), gbc);
          /*
             Initializes the password label object and adds it to the 1, 7, 1, 1 position with EAST
             alignment.
          */
          gbc.gridx = 1;
          gbc.gridy = 7;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.EAST;
          pwdLabel = new JLabel("Password : ");
          getContentPane().add(pwdLabel, gbc);
          /*
             Initializes the password text field object and adds it to the 2, 7, 1, 1 position with
             WEST alignment.
          */
          gbc.gridx = 2;
          gbc.gridy = 7;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.WEST;
          pwdText = new JPasswordField(15);
          pwdText.setFont(new Font("Verdana",Font.PLAIN,12));
          pwdText.addActionListener(this);
          getContentPane().add(pwdText, gbc);
          gbc.gridx = 1;
          gbc.gridy = 8;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.WEST;
          getContentPane().add(new JSeparator(), gbc);
          /*
             Initializes the OK and Cancel button. Adds the button to the 2, 9, 1, 1 position with
             WEST alignment.
          */
          gbc.gridx = 2;
          gbc.gridy = 9;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.anchor = GridBagConstraints.WEST;
          panel = new JPanel();
          panel.setLayout(new FlowLayout(FlowLayout.LEFT));
          connect = new JButton("Connect");
          connect.addActionListener(this);
          exit = new JButton("Exit");
          exit.addActionListener(this);
          panel.add(connect);
          panel.add(exit);
          getContentPane().add(panel, gbc);
     
          addWindowListener(new WindowAdapter()
          {
             public void windowClosing(WindowEvent we)
             {
                System.exit(0);
             }
          });
       }
       /*
    actionPerformed() - This method is called when the user clicks the any button.
    Parameters:	ae: Represents an object of the ActionEvent class that contains the details of the event.
       Return Value: NA
       */
       public void actionPerformed(ActionEvent ae)
       {
          if(ae.getSource() == connect)
          {
                try {
                    /*Creates an object of the ChatClient class.*/
                    ChatClient tcc = new ChatClient();
                    /*Calls the con() method to connect to the server.*/
                    tcc.con(localhostText.getText(), usernameText.getText(), pwdText.getText());
                    this.setVisible(false);
                } catch (IOException ex) {
                    Logger.getLogger(ChatLogin.class.getName()).log(Level.SEVERE, null, ex);
                }
          }
          else if(ae.getSource() == exit)
          {
             System.exit(0);
          }
          else if(ae.getSource() == pwdText)
          {
                try {
                    /*Creates an object of the ChatClient class.*/
                    ChatClient tcc = new ChatClient();
                    /*Calls the con() method to connect to the server.*/
                    tcc.con(localhostText.getText(), usernameText.getText(), pwdText.getText());
                    this.setVisible(false);
                } catch (IOException ex) {
                    Logger.getLogger(ChatLogin.class.getName()).log(Level.SEVERE, null, ex);
                }
             }
             }
             /*Main method.*/
             public static void main(String args[])
             {
                try
                {
                   /*Sets the window look and feel to the application.*/
                   UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                }
                catch(Exception e){}
                ChatLogin cl = new ChatLogin();
                cl.show();
          }
    }

Similar Threads

  1. sign XML with WS-Security
    By splendes in forum Java SE APIs
    Replies: 1
    Last Post: October 6th, 2010, 08:49 AM
  2. Java Chat Problem
    By skillwill2002 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 4th, 2010, 10:30 AM
  3. How do I privately sign my applet?
    By AlphaWhelp in forum Java Theory & Questions
    Replies: 1
    Last Post: December 16th, 2009, 08:42 AM
  4. Chat application problem
    By fembiz in forum Java Networking
    Replies: 1
    Last Post: December 11th, 2009, 04:21 AM
  5. Replies: 1
    Last Post: October 20th, 2009, 06:31 AM