📄 j03120e3cstudentcard.java
字号:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class j03120e3cStudentCard extends Applet implements ActionListener
{
int cardNumber=1103101120;
private static int password=123456;
static double balance=0.0;
Label prompt1;
TextField input1;
Label prompt2;
TextField input2;
Button btn;
Maininterface frame9=new Maininterface();//定义功能窗口
public void init()
{
setLayout(new FlowLayout());//安排布局
prompt1=new Label("请输入卡号:");
input1=new TextField(10);
prompt2=new Label("输入密码");
input2=new TextField(6);
btn=new Button("确定");
input2.setEchoChar('*');
add(prompt1);
add(input1);
add(prompt2);
add(input2);
add(btn);
btn.addActionListener(this);
setSize(200,220);
}
public void paint(Graphics g)
{
g.drawImage(getImage(getDocumentBase(),"1.jpg"),0,0,this);
}
static void setpwd(int data)
{
password=data;
}
boolean performConnection(int cn,int pw)//连接验证
{
if(cn==cardNumber&&pw==password)
return true;
else
return false;
}
public void actionPerformed(ActionEvent e)
{
// if(e.getSource()==btn)//
try
{
if(performConnection(Integer.parseInt(input1.getText()),
Integer.parseInt(input2.getText())))
{
frame9.show();//显示功能窗口
}
}catch(Exception e6)//出错处理
//else
{ JOptionPane.showMessageDialog(btn,"请输入正确的卡号或密码","Reminder",0);//显示提示框
input1.setText("");
input2.setText("");
}
}
}
class Maininterface extends Frame implements ActionListener
{
Button btn1;
Button btn2;
Button btn3;
Button btn4;
Button btn5;
// Button btn6;
Button btn7;
// Button btn8;
Button btn9;
boolean connected;
Inquire frame1=new Inquire();//定义查询窗口
Changepassword frame2=new Changepassword();//定义修改密码窗口
Consume frame3=new Consume();//定义消费窗口
Sufficient frame4=new Sufficient();//定义充值窗口
CET frame5=new CET();//
// book frame6=new book();//
message frame7=new message();//
// see frame8=new see();//
// exit frame9=new exit();//
Maininterface()
{
setLayout(new FlowLayout());
btn1=new Button("查询余额");
btn2=new Button("修改密码");
btn3=new Button("消费");
btn4=new Button("充值");
btn5=new Button("等级考试");
//btn6=new Button("图书借阅");
btn7=new Button("个人信息");
//btn8=new Button("");
btn9=new Button("退出");
add(btn1);
add(btn2);
add(btn3);
add(btn4);
add(btn5);
//add(btn6);
add(btn7);
//add(btn8);
add(btn9);
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
btn4.addActionListener(this);
btn5.addActionListener(this);
//btn6.addActionListener(this);
btn7.addActionListener(this);
//btn8.addActionListener(this);
btn9.addActionListener(this);
setSize(300,300);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btn1)
frame1.show();//显示查询余额窗口
if(e.getSource()==btn2)
frame2.show();//显示修改密码窗口
if(e.getSource()==btn3)
frame3.show();//显示消费窗口
if(e.getSource()==btn4)
frame4.show();//显示充值窗口
if(e.getSource()==btn5)
frame5.show();//
// if(e.getSource()==btn6)
// frame6.show();//
if(e.getSource()==btn7)
frame7.show();//
//if(e.getSource()==btn8)
// frame8.show();//
if(e.getSource()==btn9)
dispose();//退出
}
}
class Inquire extends Frame implements ActionListener
{
public void paint(Graphics g)
{
g.drawString("您的余额为:"+j03120e3cStudentCard.balance,60,100);
}
Button btn=new Button("关闭");
Inquire()//初始化
{
setLayout(new FlowLayout());
btn.addActionListener(this);
add(btn);
setSize(220,200);
}
public void actionPerformed(ActionEvent e)
{
dispose();
}
}
class Changepassword extends Frame implements ActionListener
{
Label prompt1;
TextField input1;
Label prompt2;
TextField input2;
Button btn1;
Button btn2;
Changepassword()
{
setLayout(new FlowLayout());
prompt1=new Label("请输入新密码: ");
input1=new TextField(10);
input1.setEchoChar('*');
setLayout(new FlowLayout());
prompt2=new Label("再次输入密码:");
input2=new TextField(10);
input2.setEchoChar('*');
setLayout(new FlowLayout());
btn1=new Button("确定");
btn2=new Button("关闭");
add(prompt1);
add(input1);
add(prompt2);
add(input2);
add(btn1);
add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
setSize(300,300);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btn1)
{
if(Integer.parseInt(input1.getText())==Integer.parseInt(input2.getText()))
{
j03120e3cStudentCard.setpwd(Integer.parseInt(input1.getText()));
JOptionPane.showMessageDialog(btn1,"修改密码成功","show message",1);
dispose();
input1.setText("");
input2.setText("");
}
else
JOptionPane.showMessageDialog(btn1,"请输入两个相同的数","Reminder",0);
}
if(e.getSource()==btn2)
{
input1.setText("");
input2.setText("");
dispose();
}
}
}
class Consume extends Frame implements ActionListener
{
Label prompt;
TextField input;
Button btn;
int c;
Consume()
{
super("消费窗口");
setLayout(new FlowLayout());
prompt=new Label("请输入你消费金额:");
input=new TextField(10);
btn=new Button("确定");
add(prompt);
add(input);
add(btn);
btn.addActionListener(this);
setSize(220,200);
}
public void actionPerformed(ActionEvent e)
{
// int c;
try{
c=Integer.parseInt(input.getText());
if (c>0)
{
JOptionPane.showMessageDialog(null,"你消费了"+input.getText(),"show message",1);
}
else
JOptionPane.showMessageDialog(null,"小样,你是来砸场子的吧。","show message",2);
}catch(Exception e9){JOptionPane.showMessageDialog(null,"输入含有非法字符!","",2);}
}
}
//class book extends Frame implements ActionListener{
// public void actionPerformed(ActionEvent e){
// }
//}
//class see extends Frame implements ActionListener{
// public void actionPerformed(ActionEvent e){
// }
//}
class message extends Frame implements ActionListener{
Label prompt;
//TextField output;
Button btn;
message(){
setLayout(new FlowLayout());
prompt=new Label("个人信息:马守文 男 21 计算机系 031班");
//output=new TextField(20);
btn=new Button("关闭");
add(prompt);
//add(output);
add(btn);
//output.addActionListener(this);
btn.addActionListener(this);
setSize(520,200);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==btn){
dispose();
}
}
}
class exit extends Frame implements ActionListener{
public void actionPerformed(ActionEvent e){
}
}
class Sufficient extends Frame implements ActionListener
{
Label prompt;
TextField input;
Button btn1;
Button btn2;
Sufficient()//初始化
{
setLayout(new FlowLayout());
prompt=new Label("请输入欲充值数额:");
input=new TextField(6);
btn1=new Button("确定");
btn2=new Button("关闭");
add(prompt);
add(input);
add(btn1);
add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
setSize(220,200);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btn1)
{
j03120e3cStudentCard.balance+=Integer.parseInt(input.getText());
JOptionPane.showMessageDialog(null,"您成功充值了"+Integer.parseInt(input.getText())+"元。","show message",1);//
input.setText("");
}
if(e.getSource()==btn2)
{
dispose();
}
}
}
class CET extends Frame implements ActionListener{
Label prompt;
Button btna;
Button btnb ;
CET()
{
super("等级考试");
setLayout(new FlowLayout());
btna=new Button("英语四级");
btnb=new Button("英语六级");
add(btna);
add(btnb);
btna.addActionListener(this);
btnb.addActionListener(this);
setSize(220,200);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==btna){
JOptionPane.showMessageDialog(null,"报名成功","show message",1);}
if(e.getSource()==btnb){
JOptionPane.showMessageDialog(null,"报名成功","show message",1);}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -