importjavax.swing.*;importjava.awt.*;publicclasss1extendsJFrame{JTextFieldjTextField;JPasswordFieldjPasswordField;JLabelc1,c2;JPanela1,a2,a3;JButtonb1,b2;//创建按钮public...
import javax.swing.*;
import java.awt.*;
public class s1 extends JFrame{
JTextField jTextField ;
JPasswordField jPasswordField;
JLabel c1,c2;
JPanel a1,a2,a3;
JButton b1,b2;//创建按钮
public s1(){
jTextField = new JTextField(12);
jPasswordField = new JPasswordField(13);
c1 = new JLabel("用户名");
c2 = new JLabel("密码");
b1 = new JButton("确认");
b2 = new JButton("取消");
a1 = new JPanel();
a2 = new JPanel();
a3 = new JPanel();
this.setLayout(new GridLayout(3,1));
a1.add(c1);
a1.add(jTextField);
JTextField n=new JTextField();
String x=n.getText();
a2.add(c2);
a2.add(jPasswordField);
JTextField m=new JTextField();
String y=m.getText();
a3.add(b1);
a3.add(b2);
this.add(a1);
this.add(a2);
this.add(a3);
this.setSize(300, 200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.setTitle("我的桌面小秘书登录程序");
abcd(x,y);
}
private void abcd(String x2, String y2) {
String userName = "张三";
String userPassword = "1234";
if(x2==userName && y2==userPassword)
JOptionPane.showMessageDialog(null, "登陆成功误", "提示", JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(null, "错误", "提示", JOptionPane.ERROR_MESSAGE);
}
public static void main(String[] args){
new s1();
}
}
每次运行都是直接显示错误,输入账户密码后点击确认或取消也不能使用
展开