这是我写的一段小的代码!!!麻烦各位大侠帮忙看看packageHomework;importjava.awt.BorderLayout;importjava.awt.Button;importjava.awt.Color;importjava.awt.GridLayout;importjav...
这是我写的一段小的代码!!!麻烦各位大侠帮忙看看
package Homework;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class ATM {
final JFrame a=new JFrame();
public void ATM(){
final Title8 aa=new Title8();
//aa.cunkuan();
final String c0="duanqiao";
final String b0="123456";
a.setSize(300,200);
a.setBackground(Color.yellow);
a.setVisible(true);
a.setTitle("海涛系统欢迎你的登录");
JPanel dd=new JPanel();
a.add(dd);
dd.setVisible(true);
dd.setLayout(new GridLayout(3,3));
final Label c=new Label("用户名:");
final JTextField user=new JTextField();
final Label d=new Label("密码:");
final JTextField code=new JTextField();
dd.add(c);
dd.add(user);
dd.add(d);
dd.add(code);
Button a1=new Button("确定");
Button a2=new Button("取消");
dd.setVisible(true);
dd.add(a1);
dd.add(a2);
a.add(dd,BorderLayout.CENTER);
// a.add(dd,BorderLayout.SOUTH);
a1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand()=="确定"){
System.out.println("测试");
if(user.getText()==c0 && code.getText()==b0){
System.out.println("right");
atmsystem();
}else{
JPanel cc=new JPanel();
JOptionPane.showMessageDialog(cc, "用户名或密码错误!", "警告", JOptionPane.WARNING_MESSAGE);
//System.out.println("你输入的密码或者用户名错误");
JFrame hh=new JFrame();
hh.setVisible(true);
//System.out.println("wrong");
hh.add(cc);
//hh.setBounds(2,2,30,20);
hh.setSize(300, 150);
hh.setLayout(new GridLayout(3,3));
JButton a2=new JButton("返回主页");
cc.add(a2);
cc.setLayout(new GridLayout(2,2));
TextField gg=new TextField("你输入的用户名或者密码有错,请重新确认之后再输入");
cc.add(gg);
cc.add(a2);
cc.setVisible(true);
}
}else{
if(e.getActionCommand()=="取消")
{
System.out.println("cancer");
//user.remove(null);
user.setText("");
code.setText("");
}
}
}
});
a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void atmsystem(){
System.out.println("w");
}
public void cunkuan(){
//System.out.println("w");
}
public void qukuan(){
}
public void zhuanzhuang(){
}
public void grope(){
}
public void exit(){
System.exit(0);
}
public static void main(String[] args){
ATM gg=new ATM();
gg.ATM();
}
}
展开