继承接口:
public class ButtonListener implements ActionListener
{
public String user="123";
public String pass="321";
public JTextField userText;
public JTextField pwdText;
public void actionPerformed(ActionEvent e)
{
System.out.println("按钮被点击了");
String userName= userText.getText();
String pwd=pwdText.getText();
if(user.equals(userName)&&pass.equals(pwd))
{
System.out.println("密码和账号输入正确");
JFrame jf1 = new JFrame();
jf1.setSize(500, 500);
jf1.setTitle("登录成功");
ImageIcon image = new ImageIcon("D:\\JAVAproject\\2.jpg");
JLabel right = new JLabel(image);
Dimension dim=new Dimension(250,250);
right.setPreferredSize(dim);
jf1.add(right);
jf1.setVisible(true);
//显示登录成功界面
}
else
{
System.out.println("账户或密码输入错误");
JFrame jf2 = new JFrame();
jf2.setSize(500, 500);
jf2.setTitle("登录失败");
ImageIcon image = new ImageIcon("D:\\JAVAproject\\3.jpg");
JLabel wrong = new JLabel(image);
Dimension dim=new Dimension(370,300);
wrong.setPreferredSize(dim);
jf2.add(wrong);
jf2.setVisible(true);
//显示登录失败界面
}
}