package pac1;import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class Jlogin extends JFrame implements ActionListener{JButton ok=new JButton("确定");JButton cancel=new JButton("取消");JTextField userNameText=new JTextField(15);JTextField userPwdText=new JTextField(15);JDialog dialog=new JDialog(this,"提示信息");JLabel tishi=new JLabel("登陆成功!");public Jlogin(){dialog.setSize(200,400);dialog.setLocation(200,400);dialog.setLayout(new FlowLayout());dialog.add(tishi);this.setTitle("登陆窗口");this.setLayout(new FlowLayout());this.setSize(260,200);this.setLocation(300,300);JLabel userNameLabel=new JLabel("用户名:");JLabel userPwdLabel=new JLabel("密码");this.add(userNameLabel);this.add(userNameText);this.add(userPwdLabel);this.add(userPwdText);this.add(ok);this.add(cancel);ok.addActionListener(this);cancel.addActionListener(this);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true);}public static void main(String[] args) {new Jlogin();}@Overridepublic void actionPerformed(ActionEvent e) {if(e.getSource()==ok){String userName=userNameText.getText();String userPwd=userPwdText.getText();if(userName.equals("tom")&&userPwd.equals("123")){dialog.setVisible(true);}else{tishi.setText("用户名或密码错误,请重新输入!");dialog.setVisible(true);}}if(e.getSource()==cancel){userNameText.setText("");userPwdText.setText("");}}}