⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fram4.java

📁 校园卡模拟程序
💻 JAVA
字号:
/*****************************************************************************/
/************校园卡服务界面窗口类***********************************************/
/*****************************************************************************/


import java.applet.Applet;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class Fram4  extends JFrame implements ActionListener        //校园卡服务界面窗口类
{
	private Button1  button1,button2,button3,button4;                  //声明私有一系列组件
	private Button1 button5 ,button6 ,button7 , button8,button9;


   Fram4()
   {
	   super("校园卡服务界面");                                            //调用父类方法
	   button1=new Button1("查阅余额");                                    //定义按钮对象
	   button2=new Button1("开始消费");
	   button3=new Button1("退出系统");
	   button4=new Button1("更改密码");
	   button5=new Button1("更改卡号");
	   button6=new Button1("更改姓名");
	   button7=new Button1("添加金额");
	   button8=new Button1("查看姓名");
       button9=new Button1("返    回");
	   Container container=getContentPane();                            //得到容器对象
       container.setBackground(new Color(117,224,227));                //设置容器的背景色
	   container.setLayout(new FlowLayout(FlowLayout.LEFT,10,20));      //设置布局样式
	   container.add(button1);                                           //将各种 组件  放在容器中
	   container.add(button2);
	   container.add(button3);
	   container.add(button4);
	   container.add(button5);
	   container.add(button6);
	   container.add(button7);
	   container.add(button8);
	   container.add(button9);
	   button1.addActionListener(this);                                 //给各种组件添加监视器
	   button2.addActionListener(this);
	   button3.addActionListener(this);
	   button4.addActionListener(this);
	   button5.addActionListener(this);
	   button6.addActionListener(this);
	   button7.addActionListener(this);
	   button8.addActionListener(this);
	   button9.addActionListener(this);
	   setSize(450,400);                                                 //设置窗体大小
	   setVisible(false);                                                //设置窗体不可见属性

   }
   	public void actionPerformed(ActionEvent e)                                //定义监视器响应函数

   	{
   		  if(e.getSource()==button1)                                         //响应查阅余额
	     {
			 JOptionPane.showMessageDialog(null,"您的余额为"+J02323.card.getMoney()+"元");
		 }
		 else if(e.getSource()==button2)                                     //响应消费
		 {
			   float f;
			 f=Float.valueOf(JOptionPane.showInputDialog("消费金额")).floatValue();
			 if(J02323.card.Consume(f))
			 {
				  JOptionPane.showMessageDialog(null,"消费成功");           //提示对话筐
			 }
			 else
			 {
				  JOptionPane.showMessageDialog(null,"金额不足消费");           //提示对话筐
			 }

		  }
		 else if(e.getSource()==button4)                                      //响应更改密码
		 {
			 String  str;

			 str=JOptionPane.showInputDialog("新密码:");
			 if(J02323.card.setPassword(str))
			 {
				 JOptionPane.showMessageDialog(null,"成功更改");                  //提示对话筐
			 }
			 else
			    JOptionPane.showMessageDialog(null,"密码不可为空");               //提示对话筐

		 }
		 else if(e.getSource()==button3)
		 {
			  dispose();
		    System.exit(0);
		 }
		 else if(e.getSource()==button6)                                      //响应更改姓名操作
		 {
			 String str;
			str=JOptionPane.showInputDialog("新姓名:");                       //输入对话筐
			if(J02323.card.setName(str))
			  {
				   JOptionPane.showMessageDialog(null,"成功更改");             //提示对话筐

			  }
			  else
			  JOptionPane.showMessageDialog(null,"姓名不可为空");               //提示对话筐

		 }
		 else if(e.getSource()==button5)
		 {
			 int no;

			  no=Integer.parseInt(JOptionPane.showInputDialog("新卡号:"));   //响应更改卡号操作
			  if(J02323.card.setCardno(no))
			  {
				  JOptionPane.showMessageDialog(null,"成功更改");             //提示对话筐
			  }
			  else
			      JOptionPane.showMessageDialog(null,"卡号不可为空");           //提示对话筐

		 }
		 else if(e.getSource()==button7)                                    //响应添加金额操作

		 {
			 float mone;
			 mone= Float.valueOf(JOptionPane.showInputDialog("添加金额:")).floatValue();
			if( J02323.card.setMoney(J02323.card.getMoney()+mone))
			{
				JOptionPane.showMessageDialog(null,"成功更改");              //提示对话筐
			}

		 }
		 else  if(e.getSource()==button8)                                  //响应查询姓名操作
		 {
			  JOptionPane.showMessageDialog(null,"卡主的姓名为"+J02323.card.getName());
		 }
		 else
		 {
			 J02323.fram2.setVisible(true);                   //响应返回操作
			 this.setVisible(false);
		 }

	 }
 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -