翻阅古今
import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;class Login extends JFrame implements ActionListener{JLabel accountLabel=new JLabel("账号:");JLabel pwdLabel=new JLabel("密码:");JTextField name=new JTextField(10);JPasswordField password=new JPasswordField();JButton butnSure=new JButton("确定");JButton butnCancel= new JButton("取消");;public Login(String s) {super(s);setLayout(null);add(accountLabel);accountLabel.setBounds(45, 20, 100, 25);add(pwdLabel);pwdLabel.setBounds(45, 60, 100, 25);add(name);name.setBounds(105, 20, 110, 25);add(password);password.setBounds(105, 60, 110, 25);add(butnSure);butnSure.setBounds(45, 100, 80, 25);add(butnCancel);butnCancel.setBounds(135, 100, 80, 25);butnSure.addActionListener(this);butnCancel.addActionListener(this);setVisible(true);setSize(300, 200);setLocation(Toolkit.getDefaultToolkit().getScreenSize().width / 3,Toolkit.getDefaultToolkit().getScreenSize().width / 6);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);validate();//刷新}public static void main(String[] args) {Login log = new Login("用户登陆");}public void actionPerformed(ActionEvent e) {if (e.getSource() ==butnSure){System.out.println("用户名:"+name.getText());System.out.println("密码:"+name.getText());if("wyjwsj".equals(name.getText().trim())&&"12345".equals(password.getText().trim())){this.dispose();new MainFrm("用户界面",name.getText().trim(),password.getText().trim());}else {JOptionPane.showMessageDialog(this, "用户名或密码不对,用户名为 wyjwsj,密码为 12345");}}else if(e.getSource()==butnCancel){System.exit(1);}}}class MainFrm extends JFrame{private JLabel info;public MainFrm(String s,String name,String password) {super(s);setBounds(400, 200, 500, 400);setLayout(new FlowLayout());info=new JLabel("登陆成功,用户名:"+name+",密码:"+password);add(info);setVisible(true);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);validate();}}