📄 j04404e3studentcard.java
字号:
/******************************************************************************
*本程序是基于图形界面的校园卡管理系统,很多方面有待改进。 *
* *
* 有部分功能和实际有一定差距,希望以后可以完善。 * *
* *
* 编写者:计044 陈峰 *
* *
* 日期:2006—10—5 *
* *
*******************************************************************************/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class j04404e3StudentCard extends Applet implements ActionListener //定义主类
{
int cardNumber=110411404;
private static int password=123456;
static double balance=100.0;
Label prompt1,prompt2;
TextField input1,input2;
Button btn1,btn2;
Maininterface frame6=new Maininterface();//定义功能
public void init( )
{
setLayout(new FlowLayout( )); //安排布局
prompt1=new Label("请输入卡号:");
prompt2=new Label("请输入密码:");
input1=new TextField(15);
input2=new TextField(15);
input2.setEchoChar('*');
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(150,200);
setBackground(Color.pink);
}
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)
{
AudioClip bgmusic;
bgmusic=getAudioClip(getDocumentBase(),"我的野蛮女友.mid");//添加本文件夹中的“我的野蛮女友”为音乐
if(bgmusic!=null) //循环音乐
bgmusic.loop();
if(e.getSource( )==btn1)
{
if(performConnection(Integer.parseInt(input1.getText()),
Integer.parseInt(input2.getText())))
{
frame6.show();//显示功能窗口
// setVisible(false);
}
else
JOptionPane.showMessageDialog(null,"请输入正确的卡号或密码","show message",1);//显示提示框
input1.setText("");//输入框清空
input2.setText("");//输入框清空
}
}
}
class Maininterface extends Frame implements ActionListener //主窗口的定义
{
Button btn1,btn2,btn3,btn4,btn5,btn6;
TextArea output;
boolean connected;
Inquire frame1=new Inquire( );
Changepassword frame2=new Changepassword( );
Consume frame3=new Consume( );
Sufficient frame4=new Sufficient( );
Baoming frame5=new Baoming( );
Maininterface( )
{
super("校园卡使用窗口");
btn1=new Button("查询余额");
btn2=new Button("修改密码");
btn3=new Button("消费");
btn4=new Button("充值");
btn5=new Button("考试报名");
btn6=new Button("退出");
output=new TextArea("学号:110411404"+"\n"+"姓名:陈峰"+"\n"+"出生年月:1986-1-23"+"\n"+"系别:计算机系"+"\n"+"班级:计044"+"\n"+"家庭地址:湖北省咸宁市崇阳县"+"\n"+"爱好:上网,篮球,音乐",20,30);
setLayout(new FlowLayout());
add(btn1);
add(btn2);
add(btn3);
add(btn4);
add(btn5);
add(output);
add(btn6);
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
btn4.addActionListener(this);
btn5.addActionListener(this);
btn6.addActionListener(this);
setSize(300,300);
setBackground(Color.pink);
}
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)
dispose( );
}
}
class Inquire extends Frame implements ActionListener //查询窗口的定义
{
Button btn=new Button("关闭");
public void paint(Graphics g)
{
g.drawString("您的余额为:"+j04404e3StudentCard.balance,60,100);
}
Inquire( )
{
super("查询余额");
setLayout(new FlowLayout( ));
add(btn);
btn.addActionListener(this);
setSize(220,200);
setBackground(Color.pink);
}
public void actionPerformed(ActionEvent e)
{
dispose( );
}
}
class Changepassword extends Frame implements ActionListener //修改密码窗口的定义
{
Label prompt1,prompt2;
TextField input1,input2;
Button btn1,btn2;
Changepassword( )
{
super("修改密码");
prompt1=new Label("请输入新密码:");
prompt2=new Label("再次输入新密码:");
input1=new TextField(10);
input1.setEchoChar('*');
input2=new TextField(10);
input2.setEchoChar('*');
btn1=new Button("确定");
btn2=new Button("关闭");
setLayout(new FlowLayout());
add(prompt1);
add(input1);
add(prompt2);
add(input2);
add(btn1);
add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
setSize(220,200);
setBackground(Color.pink);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource( )==btn1)
{
if(Integer.parseInt(input1.getText( ))==Integer.parseInt(input2.getText( )))
{
j04404e3StudentCard.setpwd(Integer.parseInt(input1.getText( )));
JOptionPane.showMessageDialog(null,"修改密码成功!","show message",1);
dispose( );
input1.setText("");
input2.setText("");
}
else
JOptionPane.showMessageDialog(null,"你两次输入的密码不同,请重新输入!","show message",1);
}
if(e.getSource( )==btn2)
{
input1.setText("");
input2.setText("");
dispose( );
}
}
}
class Consume extends Frame implements ActionListener //消费窗口的定义
{
Label prompt;
TextField input;
Button btn1,btn2;
Consume( )
{
super("消费窗口");
prompt=new Label("请输入消费金额");
input= new TextField(6);
btn1=new Button("确定");
btn2=new Button("关闭");
setLayout(new FlowLayout( ));
add(prompt);
add(input);
add(btn1);
add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
setSize(220,200);
setBackground(Color.pink);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btn1)
{
double CostMoney=0;
try{
CostMoney=Double.parseDouble(input.getText());
}catch(NumberFormatException g)
{
JOptionPane.showMessageDialog(null,"你的输入中含有非法字符!请重试!","Warning Message",JOptionPane.WARNING_MESSAGE);
return;
}
if(CostMoney>j04404e3StudentCard.balance)
{
JOptionPane.showMessageDialog(null,"你的卡中余额不足!","Error Message",JOptionPane.ERROR_MESSAGE);
return;
}
else
{
j04404e3StudentCard.balance-=CostMoney;
JOptionPane.showMessageDialog(null,"这次你消费了"+Integer.parseInt(input.getText())+"元。","show message",1);
input.setText("");
}
}
if(e.getSource()==btn2)
{
dispose( );
}
}
}
class Sufficient extends Frame implements ActionListener //充值窗口的定义
{
Label prompt;
TextField input;
Button btn1,btn2;
Sufficient( )
{
super("充值窗口");
prompt=new Label("请输入欲充值数额");
input=new TextField(6);
btn1=new Button("确定");
btn2=new Button("关闭");
setLayout(new FlowLayout( ));
add(prompt);
add(input);
add(btn1);
add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
setSize(220,200);
setBackground(Color.pink);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btn1)
{
double CostMoney=0;
try{
CostMoney=Double.parseDouble(input.getText());
}catch(NumberFormatException g)
{
JOptionPane.showMessageDialog(null,"你的输入中含有非法字符!请重试!","Warning Message",JOptionPane.WARNING_MESSAGE);
return;
}
j04404e3StudentCard.balance+=CostMoney;
JOptionPane.showMessageDialog(null,"您成功充值了"+Integer.parseInt(input.getText())+"元。","show message",1);
input.setText("");
}
if(e.getSource()==btn2)
{
dispose( );
}
}
}
class Baoming extends Frame implements ActionListener //报名窗口的定义
{
Button btn1,btn2,btn3,btn4;
Baoming( )
{
super("考试报名");
setLayout(new FlowLayout());
btn1=new Button("1: 英语四级 ");
btn2=new Button("2: 英语六级 ");
btn3=new Button("3: 计算机二级 ");
btn4=new Button(" 关闭 ");
add(btn1);
add(btn2);
add(btn3);
add(btn4);
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
btn4.addActionListener(this);
setSize(150,200);
setBackground(Color.pink);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btn1)
{
if(j04404e3StudentCard.balance>=30.0)
{
j04404e3StudentCard.balance-=30.0;
JOptionPane.showMessageDialog(null,"你已经成功报名英语四级!报名费30元","show message",1);
}
else
JOptionPane.showMessageDialog(null,"余额不足请充值!","show message",1);
}
if(e.getSource()==btn2)
{
if(j04404e3StudentCard.balance>=40.0)
{
j04404e3StudentCard.balance-=40.0;
JOptionPane.showMessageDialog(null,"你已经成功报名英语六级!报名费30元","show message",1);
}
else
JOptionPane.showMessageDialog(null,"余额不足请充值!","show message",1);
}
if(e.getSource()==btn3)
{
if(j04404e3StudentCard.balance>=15.0)
{
j04404e3StudentCard.balance-=15.0;
JOptionPane.showMessageDialog(null,"你已经成功报名计算机二级!报名费15元","show message",1);
}
else
JOptionPane.showMessageDialog(null,"余额不足请充值!","show message",1);
}
if(e.getSource()==btn4)
{
dispose();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -