文档库 最新最全的文档下载
当前位置:文档库 › 登陆页面首窗口设计代码

登陆页面首窗口设计代码

?)登陆页面首窗口设计代码:
class WindowBox extends Frame implements ActionListener{
Box baseBox,box1,box2;
TextField tf1,tf2;
Button button1;
Button button2;
WindowBox(String s){ //构造方法
super(s);
tf1 = new TextField(6);
tf2 = new TextField(6);
box1= Box.createVerticalBox;
box1.add(new Label("请输入你的卡号")); //输入卡号
box1.add(Box.createVerticalStrut(8));
box1.add(new Label("请输入你的密码"));//输入密码
box2=Box.createVerticalBox();
box2.add(tf1);
//box2.add(new TextField(16));
box2.add(Box.createVerticalStrut(8));
box2.add(tf2);
//box2.add(new TextField(16));
baseBox=Box.createHorizontalBox();
baseBox.add(box1);
baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(box2);
add(baseBox);
button1= new Button("确定");//加入按钮
button1.addActionListener(this);
add(button1);
button2 = new Button("退卡");//退卡按钮
button2.addActionListener(this);
add(button2);
setLayout(new FlowLayout());
(2)监听器设计代码:
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
setBounds(120,125,200,175);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
Account act;
String card;
String pwd;
act=new Account("000000","Devil","123456",50000);//初始化
(3)选择各种服务设计代码:
if(e.getSource() == button1){
String number1,number2;//输入的两个卡号和密码的变量
number1=tf1.getText();
number2=tf2.getText();
/*判断两次输入的卡号和密码是否正确*/ if((act.get_Code().equals(number1))&&(act.get_Password().equals(number2))){
dispose();
Selection s = new Selection("选择服务",act);
}else{
dispose();
ErrorWarn ew = new ErrorWarn("消息!",act);//报输入密码或卡号不正确
}
} if(e.getSource()==button2){
System.exit(0);
dispose();//退出
}
}
}
(4)主函数设计代码:
class ATM{
public static void main(String [] args){
new WindowBox("登录页面");
}
}
(5)选择服务设计代码:
import java.awt.*;
import java.awt.event.*;
class Selection extends Frame implements ActionListener{
Button button1,button2,button3,button4,button5;
Panel p1 = new Panel();
Panel p2 = new Panel();
Panel p3 = new Panel();
Panel p4 = new Panel();
Panel p5 = new Panel();
Panel p = new Panel();
Account act;
public Selection(){}
Selection(String s,Account act){
super(s);
this.act=act;
this.setLayout(null);
this.setLayout(new GridLayout(6,1));
p.add(new Label("请选择你要的服务"));
this.add(p);
(6)各种服务功能设计代码:
button1 = new Button("存款");
p1.add(button1);
this.add(p1);
button2 = new Button("取款");
p2.add(button2);
this.add(p2);
button3 = new Button("查询余额");
p3.a

dd(button3);
this.add(p3);
button4 = new Button("退出");
p4.add(button4);
this.add(p4);
button5 = new Button("修改密码");
p5.add(button5);
this.add(p5);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
button5.addActionListener(this);
setBounds(150,150,200,200);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==button2){//取款
dispose();
GetBalance gb = new GetBalance("取款",act);
}
if(e.getSource()==button3){//查询余额
Query q =new Query("查询余额",act);
dispose();
}
else if(e.getSource()==button4){//退出
System.exit(0);
dispose();
}
else if(e.getSource()==button5){//修改密码
ChangePassword cp = new ChangePassword("修改密码",act);
dispose();
}
}
}
(7)取款功能设计代码:
import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;
import java.awt.event.*;
class GetBalance extends Frame implements ActionListener{
Box baseBox, box1,box2;
Button button;
TextField tf;
Account act;
GetBalance(String s,Account act){//构造函数
super(s);
this.act=act;
button=new Button("确定");
Panel panel = new Panel();
Panel panel1 = new Panel();
tf = new TextField(6);
this.setLayout(new GridLayout(2,1));
panel1.add(new Label("请输入你想取钱的数目"));
panel1.add(tf);
panel.add(button);
this.add(panel1);
this.add(panel);
button.addActionListener(this);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
setBounds(200,200,150,150);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e){
//System.out.println(e.getActionCommand());
double money;
money = Double.parseDouble(tf.getText().trim());
if(e.getSource()==button){
if(act.get_Money()<0){//判断余额是否为负
dispose();
ErrorWarn4 ew4 = new ErrorWarn4("消息!",act);
}
else if(money<=act.get_Money()){//取钱的数额不大于余额
if((money%100!=0)||(money>=5000)){//取钱数为100的倍数或不大于5000
dispose();
ErrorWarn6 ew6 = new ErrorWarn6("消息!",act);
}
act.set_Balance(money);//重置余额
this.setVisible(false);
Selection s = new Selection("选择服务",act);//返回选择服务窗口
//dispose();
}else if(money>act.get_Money()){判断取款数额是否大于余额
dispose();
ErrorWarn5 ew5 = new ErrorWarn5("消息!",act);
}
}
}
}
public static void main(String[] args){
GetBalance test = new GetBalance("dfdf");
GetBalance gb = new GetBalance("取款");
}
}
(8)修改密码设计代码:
import javax.swing

.*;
import java.awt.*;
import javax.swing.border.*;
import java.awt.event.*;
class ChangePassword extends Frame implements ActionListener{
Panel panel1 = new Panel();
Panel panel2 = new Panel();
Panel panel3 = new Panel();
Panel panel = new Panel();
TextField tf4,tf5,tf6;
Button button;
Account act;
ChangePassword(String s,Account act){
super(s);
this.act=act;
tf4 = new TextField(6);
tf5 = new TextField(6);
tf6 = new TextField(6);
button = new Button("确定");
button.addActionListener(this);
(9)建立新密码设计代码:
panel1.add(new Label("请输入你的旧密码:"));
panel1.add(tf4);
panel2.add(new Label("请输入你的新密码:"));
panel2.add(tf5);
panel3.add(new Label("请再次输入你的新密码"));
panel3.add(tf6);
panel.add(button);
this.add(panel1);
this.add(panel2);
this.add(panel3);
this.add(panel);
setLayout(new GridLayout(4,1));
setBounds(200,200,250,250);
this.setVisible(true);
(10)窗口事件设计代码:
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
(12)查询余额功能设计代码:
import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;
import java.awt.event.*;
class Query extends Frame implements ActionListener{
Button button;
Account act;
Query(String s,Account act){//构造函数
super(s);
this.act = act;
button=new Button("确定");
//TextField tf = new TextField(6);
Panel panel1 = new Panel();
Panel panel = new Panel();
panel1.add(new Label("你的余额为: " + act.get_Money()));//查询余额的方法
//panel1.add(tf);
button.addActionListener(this);
panel.add(button);
this.add(panel);
this.add(panel1);


相关文档
相关文档 最新文档