java selfish routing login screen

Discussion in 'Meet and Greet' started by sanket28, Mar 7, 2011.

  1. sanket28

    sanket28 New Member

    Joined:
    Mar 7, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    import javax.swing.*;
    import java.awt.Container; //for container class
    import java.awt.event.KeyListener; 
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyAdapter;
    import java.awt.event.ActionListener;
    import java.awt.event.*;
    import javax.swing.border.TitledBorder; //for border
    class Authority extends JFrame implements ActionListener
    {
     Container c;
     JButton Jb1,b2,b3;
     JLabel l1,l2,l3,l4,l5;
     JTextField t1;
     JPasswordField t2;
     TitledBorder tb;
     Authority()
     {
      //create main Window
      super("Authority Validation Window");
      c=getContentPane();
      c.setLayout(null);
            setSize(800,560);
      l4=new JLabel("User Identification");
      l4.setBounds(340,100,200,60);
         c.add(l4);
      //create frame for Authority Window using Jbutton
      Jb1=new JButton();
            Jb1.setLayout(null);
      Jb1.setBounds(180,150,450,240);
      c.add(Jb1);
      l4=new JLabel();
      l4.setBounds(125,80,560,350);
      tb=new TitledBorder("Authority Validation Window");
            l4.setBorder(tb);
      c.add(l4);
      //create username n password
      l1=new JLabel("Enter Username: ");
      l1.setBounds(65,40,100,30);
      Jb1.add(l1);
      l2=new JLabel("Enter Password: ");
      l2.setBounds(65,90,100,30);
      Jb1.add(l2);
             //Enter Username n Password
       t1=new JTextField();
       t1.setBounds(200,40,170,30);
       t1.requestFocus();
       Jb1.add(t1);
       t2=new JPasswordField();
       t2.setBounds(200,90,170,30);
       t2.requestFocus();
       Jb1.add(t2);
             //create OK n CANCEL buttons
       b2=new JButton("OK");
       b2.setBounds(80,170,120,30);
       b2.setMnemonic('O'); //for underlining
       b2.addActionListener(this);
       Jb1.add(b2);
       b3=new JButton("CANCEL");
       b3.setBounds(240,170,120,30);
       b3.setMnemonic('C');
       b3.addActionListener(this);
       Jb1.add(b3);
             //for displaying error message
       l3=new JLabel("Please enter the correct password");
       l3.setBounds(240,120,200,40);
             //keyListener
       addKeyListener(new KeyAdapter()
        { public void keyPressed(KeyEvent ke)
        {
             if(ke.getKeyCode()==13) //enter key
           { 
          if(b2.hasFocus()) //OK button 
           { 
          if(t1.getText().equals("Selfish Routing")  && t2.getText().equals("n782996k"))
          { t1.setText(null);  t2.setText(null);
               new mainselfish(); }
          else
          { Jb1.add(l3); }
          }
           }
           if(b3.hasFocus()) //CANCEL button
         { new Project(); }//cancel button close
           repaint();
         }
                   });
      setVisible(true);
      setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
      }//end of parameter constructor
        public void actionPerformed(ActionEvent ae)
     {
      if(ae.getActionCommand().equals("OK")) //OK button
      { 
       if(t1.getText().equals("Selfish Routing")&&t2.getText().equals("n782996k"))
       {t1.setText(null); t2.setText(null);
          new mainselfish(); }
         else
       { t1.setText(null); t2.setText(null);
          JOptionPane.showMessageDialog(this,"Please enter the correct password","Authority Validation Window",JOptionPane.ERROR_MESSAGE);
        } //ok button close
      }
           if(ae.getSource()==b3)
      { new Project(); } //cancel button close
       } //ActionListener close
     public static void main(String[] args) 
     {
      new Authority();
     }
    }
    i have cannot find error inthis pro...pls help
     
    Last edited by a moderator: Mar 7, 2011

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice