Java to achieve a simple login screen

the java.awt * Import;. // import awt package 
Import in javax.swing with *;. // Import swing package 
Import the java.awt. Event .ActionListener; // import listener events awt package package 
Import the java.awt. Event .ActionEvent; // import an ActionEvent awt-packets 

public  class EnterScreen the extends the JFrame {
     static  int S = 0 ;
     public EnterScreen () { 
        Yanzhencode VCODE = new new   Yanzhencode (); 
        the setSize ( 300 , 290 is ); // design form the size 
        setTitle (" Login " ); 
        setBackground (Color.RED); // set the background color 
        JLabel = A new new JLabel ( " login " ); // instantiate a JLabel 
        JLabel B = new new JLabel ( " Password " ); 
        JLabel G = new new the JLabel ( " Forgot your username / password? " ); 
        the JLabel H = new new the JLabel ( " code " ); 
        g.setForeground (Color.BLUE); 
        JTextField c = new newThe JTextField ( 15 ); // instantiate user name text box 
        the JPasswordField D = new new the JPasswordField ( 15 ); // Example cryptographic block 
        the JTextField K = new new the JTextField ( . 4 ); // instantiate verification box 
        d.setEchoChar ( ' * ' ); // input * password box is displayed to 
        the JButton E = new new the JButton ( " Login " ); 
        the JButton F = new new the JButton ( " rEGISTRATION " ); 
        e.setBackground (Color.YELLOW,); //Set Font Color login button 
        f.setForeground (Color.GRAY); // Set the fill color fast login button 
        setVisible ( to true ); // make the form visualized 
        Container m = the getContentPane (); // get a container 
        . GetContentPane () setBackground (Color.WHITE); // set the fill color form
 //         user name, user name and password Jlabel JTextField textbox, a password and the password box JPasswordField JButton determining, quickly added to the register JButton container inside the container                          //
         m.add (A); 
        m.add (B); 
        m.add (C); 
        m.add (D); 
        m.add (E); 
        m.add (F); 
        m.add (G); 
        m.add ( H); 
        m.add (K);
        m.add (VCODE);
        the setBounds (  );300 , 300 , 300 , 300 ); // set the length and width of the form to appear in the 300,300 to 300,300 in the upper left 
        m.setLayout ( null );
 //         A, B, C, d, e, f, positional coordinates in the container vessel 
        a.setBounds ( 10 , 40 , 50 , 18 is ); 
        b.setBounds ( 10 , 80 , 50 , 18 is ); 
        c.setBounds ( 60 , 40 , 130. , 18 is 
        d.setBounds ( 60 ,80,130,18);
        h.setBounds(10,120,50,18);
        k.setBounds(60,120,80,18);
        e.setBounds(90,180,100,30);
        f.setBounds(90,220,100,30);
        g.setBounds(190,75,100,30);
        vcode.setBounds(140,110,80,30);
        e.addActionListener(new ActionListener() {//对登录按钮添加监听事件
             
            @SuppressWarnings("deprecation")
            @Override
            public void actionPerformed(ActionEvent arg0) {
                // TODO Auto-generated method stub
                
                if(c.getText().trim().equals("xiaoyang")&&new String(d.getPassword()).equals("123456" )&&s==. 1 ) { // the equals function matching the user name and password 
                    JOptionPane.showMessageDialog ( null , " Login Successful " ); 
                    
                    new new newFrame (); // into the form newFrame 
                } the else  IF (c.getText (). . TRIM () the equals ( " Xiaoyang " ) && new new String (d.getPassword ()) the equals (. " 123456 " ) && S == 0 ) { 
                    JOptionPane.showMessageDialog ( null , " enter the code error " ); 
                }the else { 
                    JOptionPane.showMessageDialog ( null , " Login failed for user name, password or verification code input error " ); 
                } 
            } 
                
        }); 
        f.addActionListener ( new new ActionListener () { // quick registration button to add event listeners 
            @SuppressWarnings ( " deprecation " ) 
            @Override 
            public  void the actionPerformed (the ActionEvent the arg0) {
                 // the TODO Auto-Generated Method Stub 
                new new zhuce (); // into the form are to zhuce 
            } 
            
        });
        // determines if the input PIN is correct 
            IF (k.getText () == null ) { 
                S = 0 ; 
            } the else  IF (vcode.getCode () == null ) { 
                S = . 1 ; 
            } the else  IF (vcode.getCode ( ) .equals (k.getText ())) { 
                S = . 1 ; 
            } the else { 
            S = 0 ;     
        } 
    } 
    
        public  static  void main (String [] args) {
             new new EnterScreen();
            
        }
        
    }

Screenshot

Guess you like

Origin www.cnblogs.com/xk1013/p/12151878.html