把前两天做的实验用GUI实现...
主要的接口都没有变,所以实现比较容易...
代码如下:
主要的接口都没有变,所以实现比较容易...
代码如下:
1
/** *//**
2
*title 模拟银行存储实验——GUI实现
3
*@author realsmy
4
*date 2006-10-26 8:10
5
*/
6
7
import java.io.*;
8
import java.awt.*;
9
import javax.swing.*;
10
import java.awt.event.*;
11
import javax.swing.JPanel.*;
12
13
//login applicatiion
14
class Login extends JFrame
{
15
Container c;
16
JTextField text;
17
JPasswordField password;
18
MyPanel panel;
19
JLabel label_name,label_password;
20
JButton button1,button2;
21
String lg_name,lg_password;
22
File fl;//帐户资料文件声明
23
Login()
{
24
super("模拟银行存储系统");
25
c = getContentPane();
26
c.setLayout(new BorderLayout());
27
//初始化组件
28
text = new JTextField();
29
password = new JPasswordField();
30
label_name = new JLabel("教工号 :");
31
label_password = new JLabel("密 码 :");
32
panel = new MyPanel();
33
button1 = new JButton("LOGIN");
34
button2 = new JButton("RESET");
35
//添加监听
36
button1.addActionListener(new ActionListener()
37
{
38
public void actionPerformed(ActionEvent e)
39
{
40
lg_name = text.getText();
41
lg_password = password.getText();
42
if ( lg_name.equals("admin") && lg_password.equals("admin"))
{
43
setVisible(false);
44
GuanLi gl = new GuanLi();
45
gl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
46
}
47
else
{
48
try
{
49
fl = new File("frozen",lg_name+".txt");
50
if(fl.exists())
{
51
JOptionPane.showMessageDialog(null,"对不起,您的帐户已被冻结!");
52
}
53
else
{
54
fl = new File(lg_name+".txt");
55
//判断帐户是否存在
56
if(!fl.exists())
{
57
JOptionPane.showMessageDialog(null,"对不起,您输入的帐户并不存在,请重新输入:");
58
}
59
else
{
60
//帐户存在,开始判断密码
61
BufferedReader reader = new BufferedReader(new FileReader( lg_name + ".txt"));
62
String pw = reader.readLine();
63
int money = Integer.parseInt(reader.readLine());
64
//判断密码
65
if(lg_password.equals(pw))
{
66
JOptionPane.showMessageDialog(null,"登陆成功\n"+"您的用户尚有余额"+money+"元");
67
ZhangHu zh = new ZhangHu(lg_name,lg_password,money);
68
setVisible(false);
69
YongHu yh = new YongHu(zh);
70
yh.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
71
}
72
else
{
73
JOptionPane.showMessageDialog(null,"对不起,您输入的密码不正确,请重新输入:");
74
}
75
}
76
}
77
}catch(HeadlessException a)
{}catch(IOException b)
{}
78
}
79
}
80
});
81
button2.addActionListener(new ActionListener()
82
{
83
public void actionPerformed(ActionEvent e)
84
{
85
text.setText("");
86
password.setText("");
87
}
88
});
89
90
//设置容器
91
panel.setLayout(new GridLayout(3,2,10,15));
92
panel.add(label_name);
93
panel.add(text);
94
panel.add(label_password);
95
panel.add(password);
96
panel.add(button1);
97
panel.add(button2);
98
99
c.add(panel,BorderLayout.CENTER);
100
setSize(300,200);
101
setLocation(300,200);
102
setVisible(true);
103
}
104
}
105
106
//定义管理界面
107
class GuanLi extends JFrame
{
108
private Container c;
109
JButton button1,button2,button3,button4;
110
MyPanel panel;
111
JLabel label1,label2;
112
Manager manager;
113
//String name,password,password2;
114
//int money;
115
GuanLi()
{
116
super("模拟银行存储系统");
117
c = getContentPane();
118
c.setLayout(new BorderLayout());
119
//数据初始化
120
//button = new JButton("");
121
panel = new MyPanel();
122
label1 = new JLabel("欢迎光临赵家银行!");
123
label2 = new JLabel("请选择你要进行的操作:");
124
button1 = new JButton("1.添加帐户");
125
button2 = new JButton("2.删除用户");
126
button3 = new JButton("3.冻结用户");
127
button4 = new JButton("4.退出");
128
129
//按钮监听
130
button1.addActionListener(new ActionListener()
{
131
public void actionPerformed(ActionEvent e)
{
132
manager = new Manager();
133
manager.add();
134
}
135
});
136
button2.addActionListener(new ActionListener()
{
137
public void actionPerformed(ActionEvent e)
{
138
manager = new Manager();
139
manager.del();
140

/** *//**2
*title 模拟银行存储实验——GUI实现3
*@author realsmy4
*date 2006-10-26 8:105
*/6

7
import java.io.*;8
import java.awt.*;9
import javax.swing.*;10
import java.awt.event.*;11
import javax.swing.JPanel.*;12

13
//login applicatiion14

class Login extends JFrame
{15
Container c;16
JTextField text;17
JPasswordField password;18
MyPanel panel;19
JLabel label_name,label_password;20
JButton button1,button2;21
String lg_name,lg_password;22
File fl;//帐户资料文件声明23

Login()
{24
super("模拟银行存储系统");25
c = getContentPane();26
c.setLayout(new BorderLayout());27
//初始化组件28
text = new JTextField();29
password = new JPasswordField();30
label_name = new JLabel("教工号 :");31
label_password = new JLabel("密 码 :");32
panel = new MyPanel();33
button1 = new JButton("LOGIN");34
button2 = new JButton("RESET");35
//添加监听36
button1.addActionListener(new ActionListener()37

{38
public void actionPerformed(ActionEvent e)39

{40
lg_name = text.getText();41
lg_password = password.getText();42

if ( lg_name.equals("admin") && lg_password.equals("admin"))
{43
setVisible(false);44
GuanLi gl = new GuanLi(); 45
gl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);46
}47

else
{48

try
{49
fl = new File("frozen",lg_name+".txt");50

if(fl.exists())
{51
JOptionPane.showMessageDialog(null,"对不起,您的帐户已被冻结!");52
}53

else
{54
fl = new File(lg_name+".txt");55
//判断帐户是否存在56

if(!fl.exists())
{57
JOptionPane.showMessageDialog(null,"对不起,您输入的帐户并不存在,请重新输入:");58
}59

else
{60
//帐户存在,开始判断密码61
BufferedReader reader = new BufferedReader(new FileReader( lg_name + ".txt"));62
String pw = reader.readLine();63
int money = Integer.parseInt(reader.readLine());64
//判断密码65

if(lg_password.equals(pw))
{66
JOptionPane.showMessageDialog(null,"登陆成功\n"+"您的用户尚有余额"+money+"元");67
ZhangHu zh = new ZhangHu(lg_name,lg_password,money);68
setVisible(false);69
YongHu yh = new YongHu(zh);70
yh.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);71
}72

else
{73
JOptionPane.showMessageDialog(null,"对不起,您输入的密码不正确,请重新输入:");74
}75
}76
} 77

}catch(HeadlessException a)
{}catch(IOException b)
{}78
}79
}80
});81
button2.addActionListener(new ActionListener()82

{83
public void actionPerformed(ActionEvent e)84

{85
text.setText("");86
password.setText("");87
}88
});89

90
//设置容器91
panel.setLayout(new GridLayout(3,2,10,15));92
panel.add(label_name);93
panel.add(text);94
panel.add(label_password);95
panel.add(password);96
panel.add(button1);97
panel.add(button2);98
99
c.add(panel,BorderLayout.CENTER);100
setSize(300,200);101
setLocation(300,200);102
setVisible(true);103
}104
}105

106
//定义管理界面107

class GuanLi extends JFrame
{108
private Container c;109
JButton button1,button2,button3,button4;110
MyPanel panel;111
JLabel label1,label2;112
Manager manager;113
//String name,password,password2;114
//int money;115

GuanLi()
{116
super("模拟银行存储系统");117
c = getContentPane();118
c.setLayout(new BorderLayout());119
//数据初始化120
//button = new JButton("");121
panel = new MyPanel();122
label1 = new JLabel("欢迎光临赵家银行!");123
label2 = new JLabel("请选择你要进行的操作:");124
button1 = new JButton("1.添加帐户");125
button2 = new JButton("2.删除用户");126
button3 = new JButton("3.冻结用户");127
button4 = new JButton("4.退出");128
129
//按钮监听130

button1.addActionListener(new ActionListener()
{131

public void actionPerformed(ActionEvent e)
{132
manager = new Manager();133
manager.add();134
}135
});136

button2.addActionListener(new ActionListener()
{137

public void actionPerformed(ActionEvent e)
{138
manager = new Manager();139
manager.del();140
模拟银行系统GUI登录实现
本文介绍了一个使用Java Swing实现的模拟银行系统的图形用户界面登录模块。该模块能够验证用户的账号和密码,并根据不同情况显示相应的提示信息。文章提供了完整的代码示例。
1611

被折叠的 条评论
为什么被折叠?



