Java Second Job

Source: Internet
Author: User

Package Javazuoye;
Import javax.swing.*;

Import java.awt.*;
Import java.awt.event.*;
public class Denglujiemian {

public static void Main (string[] args) {
TODO auto-generated Method Stub
Logindialog lo = new Logindialog ();
Lo.setvisible (TRUE);
}

}
public class MainWindow extends jframe{

    JLabel but1;
    MainWindow () {
       
         settitle ("System login");
        setbounds (400,200,300,180);
        setdefaultcloseoperation (jframe.do_nothing_on_close);
//        setlayout (null);


        Addwindowlistener (New Windowadapter () {
             public void windowclosing (WindowEvent e) {
                 system.exit (0);
           }
       });
        but1 = new JLabel ("Login Successful! ");
        This.add (BUT1);
   
   }
   
   
}

public class Logindialog extends JDialog {
JLabel name;
JLabel A2;
JComboBox A3;
JPasswordField password;
JButton Shi;
JButton Fou;

Logindialog () {
Method1 ();
}

private void Method1 () {
TODO auto-generated Method Stub
Settitle ("Login System");
SetBounds (500,250,220,140);
Setdefaultcloseoperation (Jdialog.do_nothing_on_close);
SetLayout (NULL);
Setmodal (TRUE);
This.setresizable (FALSE);

name = new JLabel ("User name:");
Name.setbounds (20,10,50,20);
This.add (name);
A2 = new JLabel ("Password:");
A2.setbounds (20,32,50,20);
This.add (A2);

a3 = new JComboBox ();
A3.additem ("Huakaihualuo");
A3.additem ("Hellow");
A3.setbounds (75,10,105,20);
This.add (A3);
Password = new JPasswordField ("666666");
Password.setbounds (75,33,105,20);
Password.setechochar (' * ');
This.add (password);

Shi = new JButton ("login");
Shi.setbounds (25,60,60,20);
Add (shi);
Shi.addactionlistener (new ActionListener () {

@Override
public void actionperformed (ActionEvent e) {
TODO auto-generated Method Stub
Login ();
}
});
Fou =new JButton ("exit");
Fou.setbounds (110,60,60,20);
Add (fou);
Fou.addactionlistener (new ActionListener () {

@Override
public void actionperformed (ActionEvent e) {
TODO auto-generated Method Stub
Logout ();
}
});

}
void Login () {
String accout = A3.getselecteditem (). toString ();
string pwd = new string (Password.getpassword ());
if (Accout.equals ("Huakaihualuo") &&pwd.equals ("666666")) {
SetVisible (FALSE);
Showmainwindow ();
}else{
Joptionpane.showmessagedialog (This, "username is" +accout + ", password is" + pwd ");
}
}
void Logout () {
int ret = Joptionpane.showconfirmdialog (this, "quit login?") "," Cancel Login ", joptionpane.yes_no_option);
if (ret ==joptionpane.yes_no_option) {
Dispose ();
}
}
void Showmainwindow () {
MainWindow frm = new MainWindow ();
Frm.setvisible (TRUE);
}
}


Java Second Job

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.