




免费预览已结束,剩余26页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
package cashier;import java.awt.BorderLayout;import java.awt.FlowLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.text.DateFormat;import java.text.SimpleDateFormat;import java.util.Date;import java.util.HashMap;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JTextArea;import javax.swing.JTextField;import javax.swing.Timer;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JPanel;SuppressWarnings(serial)public class SystemWindow extends JFrame implements ActionListenerstatic Checkstand checkstand;/此变量单纯为了保存读至保存HashMap文件中的数据,相当于一个中间媒介/* * 供显示的商品信息 */Goods good;/* * 保存收银台信息的文件 */static File file; static Checkstand c;/放在此处并不和前面的checkstand相矛盾,此变量是为了读取、保存柜台信息 static Long number;/输入的卡号 Timer time;/获取系统时间JPanel leftPanel;JButton member;/会员服务JButton common;/普通服务 JButton findMemberInfo;/查找会员信息JButton findAllMemberInfo;/查看所有会员信息JButton findGoodsSurplus;/查看商品剩余量JButton findSaleroom;/查看柜台销售额JPanel rightPanel;JTextField showTime;JPanel rightPanelSon;public SystemWindow() super(欢迎使用超市收银系统);file=new File(checkstand.dat);SystemWindow.readCheckstandInfo();/读取柜台信息Goods.getSurplusFromFile();/这一步很重要!good=new Goods();time=new Timer(1000,this);/时间time.start();this.setLayout(new GridLayout(1,2,4,4);leftPanel=new JPanel();leftPanel.setLayout(new GridLayout(6,1,4,4);member=new JButton(会员服务);common=new JButton(普通服务);findMemberInfo=new JButton(查找会员信息);findAllMemberInfo=new JButton(查看所有会员信息);findGoodsSurplus=new JButton(查看商品剩余量);findSaleroom=new JButton(查看柜台销售额);member.addActionListener(this);common.addActionListener(this);findMemberInfo.addActionListener(this);findAllMemberInfo.addActionListener(this);findGoodsSurplus.addActionListener(this);findSaleroom.addActionListener(this);leftPanel.add(member);leftPanel.add(common);leftPanel.add(findMemberInfo);leftPanel.add(findAllMemberInfo);leftPanel.add(findGoodsSurplus);leftPanel.add(findSaleroom);rightPanel=new JPanel();showTime=new JTextField(12);rightPanelSon=new JPanel();showTime.setEditable(false);rightPanel.setLayout(new BorderLayout(1,1);rightPanel.add(showTime,BorderLayout.NORTH);rightPanel.add(BorderLayout.CENTER,rightPanelSon);this.add(leftPanel);this.add(rightPanel);this.setSize(600,500);this.setLocation(500,127);this.setVisible(true);/* * * return 返回文件中的记录 */SuppressWarnings( unchecked, static-access )public static HashMap getHashMap()File file=Checkstand.file;if(file.length()=0) checkstand=new Checkstand();checkstand.definedForSystemWindow();else try ObjectInputStream in=new ObjectInputStream(new FileInputStream(file);checkstand.cardAndCustomer=(HashMap)in.readObject();in.close();catch(IOException e)System.err.println(e.getMessage();catch(ClassNotFoundException e1)System.err.println(文件未找到!);return checkstand.cardAndCustomer;/* * 保存柜台信息 对象串行化 */public static void AddCheckstandInfo() try if(c=null)c=new Checkstand();ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream(file);out.writeObject(c);out.close();catch(IOException e)System.out.println(e.getMessage();/* * 从文件中读取柜台信息 对象串行化 * throws ClassNotFoundException */public static void readCheckstandInfo() try ObjectInputStream in=new ObjectInputStream(new FileInputStream(file); Object o=in.readObject(); if(o!=null) c=(Checkstand)o; else c=new Checkstand();/在此处生成柜台对象再合适不过来 in.close(); catch(IOException e)System.out.println(e.getMessage();catch(ClassNotFoundException e1)System.out.println(文件未找到!); public static void main(String args) new SystemWindow(); Overridepublic void actionPerformed(ActionEvent e) / TODO Auto-generated method stubDateFormat format=new SimpleDateFormat();Date date=new Date();showTime.setText( 北京时间:+format.format(date);final String PrintTime=format.format(date);/将信息打印在顾客的消费信息上if(e.getSource()=member) rightPanelSon.removeAll();/事先先移除rightPanelSon中的所有的组件this.paintAll(getGraphics();/相当于重画的功能,此部骤相当重要rightPanelSon.setLayout(new FlowLayout();rightPanelSon.add(new JPanel();rightPanelSon.add(new JPanel();final JTextArea goodsInfo=new JTextArea();/显示商品信息rightPanelSon.add(goodsInfo);goodsInfo.setEditable(false);/不可编辑 goodsInfo.setText(good.toString(); String id=JOptionPane.showInputDialog(请输入会员卡卡号:); try number=Long.parseLong(id); catch(NumberFormatException e1) JOptionPane.showMessageDialog(null, 输入格式有误!); return; final HashMap c1=SystemWindow.getHashMap(); if(c1=null) JOptionPane.showMessageDialog(null, 会员信息不存在!,null, JOptionPane.WARNING_MESSAGE); return; else int flag=0; Customer customer1=null; ClubCard card2 = null; for(ClubCard card:c1.keySet() if(number.equals(card.getId() JTextArea area=new JTextArea(); rightPanelSon.add(area); area.setText(c1.get(card).toString();/输出顾客信息 customer1=c1.get(card); flag=customer1.getCustomeCard().getGrade(); card2=card; /if /for if(customer1=null) JOptionPane.showMessageDialog(null, 会员信息不存在!,null, JOptionPane.WARNING_MESSAGE); return; final ClubCard card1 = card2; final int flag1=flag; final Customer customer=customer1; JPanel pane1=new JPanel(); pane1.setLayout(new GridLayout(6,2,2,2); JLabel j1=new JLabel(购+good.getGoodsNames().get(0)+的数量);final JTextField jt1=new JTextField(); JLabel j2=new JLabel(购+good.getGoodsNames().get(1)+的数量);final JTextField jt2=new JTextField(); JLabel j3=new JLabel(购+good.getGoodsNames().get(2)+的数量);final JTextField jt3=new JTextField(); JLabel j4=new JLabel(购+good.getGoodsNames().get(3)+的数量);final JTextField jt4=new JTextField(); JLabel j5=new JLabel(购+good.getGoodsNames().get(4)+的数量);final JTextField jt5=new JTextField(); JLabel j6=new JLabel(购+good.getGoodsNames().get(5)+的数量);final JTextField jt6=new JTextField(); pane1.add(j1);pane1.add(jt1); pane1.add(j2);pane1.add(jt2); pane1.add(j3);pane1.add(jt3); pane1.add(j4);pane1.add(jt4); pane1.add(j5);pane1.add(jt5); pane1.add(j6);pane1.add(jt6); rightPanelSon.add(pane1); jt1.setText(0);/商品件数都默认设为0件 jt2.setText(0); jt3.setText(0); jt4.setText(0); jt5.setText(0); jt6.setText(0); final JButton cal=new JButton(计算); final JButton empty=new JButton(归零); final JLabel hint=new JLabel();/对计算所得总额进行反应 rightPanelSon.add(cal); rightPanelSon.add(hint); rightPanelSon.add(empty); cal.addActionListener(new ActionListener() SuppressWarnings( static-access) Override public void actionPerformed(ActionEvent e) Double total=0.0; / TODO Auto-generated method stub if(e.getSource()=cal) try String s1=jt1.getText();int num1=Integer.parseInt(s1); String s2=jt2.getText();int num2=Integer.parseInt(s2); String s3=jt3.getText();int num3=Integer.parseInt(s3); String s4=jt4.getText();int num4=Integer.parseInt(s4); String s5=jt5.getText();int num5=Integer.parseInt(s5); String s6=jt6.getText();int num6=Integer.parseInt(s6); total+=num1*good.getPrice().get(0)+ num2*good.getPrice().get(1)+ num3*good.getPrice().get(2)+ num4*good.getPrice().get(3)+ num5*good.getPrice().get(4)+ num6*good.getPrice().get(5); /更新商品剩余量 good.updateSurplus(0, num1); good.updateSurplus(1, num2); good.updateSurplus(2, num3); good.updateSurplus(3, num4); good.updateSurplus(4, num5); good.updateSurplus(5, num6); /保存商品剩余信息到文件 good.updateSurplusFromFile(); /显示商品信息要发生变化 goodsInfo.setText(good.toString(); if(flag1=5) hint.setText(该顾客享受9.5折优惠,本应收¥+total+实收¥+(total*0.95); /更改柜台销售量 c.getSaleroomFromFile(); c.setSaleroom(c.getSaleroom()+total); SystemWindow.AddCheckstandInfo(); customer.addCustomeInfo(PrintTime+消费¥+total+,享受9.5折优惠后实收¥+(total*0.95); if(total=1000&total=2000&total=4000&total=10000) JOptionPane.showMessageDialog(null, 恭喜该顾客会员卡升级为至尊卡,此后购物享受7折优惠!); new Card5(); customer.getCustomeCard().setGrade(1);/在后面统一保存信息 else if(flag1=4) hint.setText(该顾客享受9折优惠,本应收¥+total+实收¥+(total*0.9); /更改柜台销售量 c.getSaleroomFromFile(); c.setSaleroom(c.getSaleroom()+total); SystemWindow.AddCheckstandInfo(); customer.addCustomeInfo(PrintTime+消费¥+total+,享受9折优惠后实收¥+(total*0.9); if(total=2000&total=4000&total=10000) JOptionPane.showMessageDialog(null, 恭喜该顾客会员卡升级为至尊卡,此后购物享受7折优惠!); new Card5(); customer.getCustomeCard().setGrade(1);/在后面统一保存信息 else if(flag1=3) hint.setText(该顾客享受8.5折优惠,本应收¥+total+实收¥+(total*0.85); /更改柜台销售量 c.getSaleroomFromFile(); c.setSaleroom(c.getSaleroom()+total); SystemWindow.AddCheckstandInfo(); customer.addCustomeInfo(PrintTime+消费¥+total+,享受8.5折优惠后实收¥+(total*0.85); if(total=4000&total=10000) JOptionPane.showMessageDialog(null, 恭喜该顾客会员卡升级为至尊卡,此后购物享受7折优惠!); new Card5(); customer.getCustomeCard().setGrade(1);/在后面统一保存信息 else if(flag1=2) hint.setText(该顾客享受8折优惠,本应收¥+total+实收¥+(total*0.8); /更改柜台销售量 c.getSaleroomFromFile(); c.setSaleroom(c.getSaleroom()+total); SystemWindow.AddCheckstandInfo(); customer.addCustomeInfo(PrintTime+消费¥+total+,享受8折优惠后实收¥+(total*0.8); if(total=10000) JOptionPane.showMessageDialog(null, 恭喜该顾客会员卡升级为至尊卡,此后购物享受7折优惠!); new Card5(); customer.getCustomeCard().setGrade(1);/在后面统一保存信息 else if(flag1=1) hint.setText(该顾客享受7折优惠,本应收¥+total+实收¥+(total*0.7); /更改柜台销售量 c.getSaleroomFromFile(); c.setSaleroom(c.getSaleroom()+total); SystemWindow.AddCheckstandInfo(); customer.addCustomeInfo(PrintTime+消费¥+total+,享受7折优惠后实收¥+(total*0.7); /try catch(NumberFormatException e1)JOptionPane.showMessageDialog(null, 输入格式有误!); c1.put(card1, customer);/放在此处-统一保存 Checkstand.save(); /if ); empty.addActionListener(new ActionListener() Override public void actionPerformed(ActionEvent e) / TODO Auto-generated method stub if(e.getSource()=empty) jt1.setText(0);/商品件数清空 jt2.setText(0); jt3.setText(0); jt4.setText(0); jt5.setText(0); jt6.setText(0); ); /else else if(e.getSource()=common) rightPanelSon.removeAll();/事先先移除rightPanelSon中的所有的组件this.paintAll(getGraphics();/相当于重画的功能,此部骤相当重要rightPanelSon.setLayout(new FlowLayout();final JTextArea goodsInfo=new JTextArea();/显示商品信息rightPanelSon.add(goodsInfo);goodsInfo.setEditable(false);/不可编辑 goodsInfo.setText(good.toString(); JPanel pane1=new JPanel(); pane1.setLayout(new GridLayout(6,2,2,2); JLabel j1=new JLabel(购+good.getGoodsNames().get(0)+的数量);final JTextField jt1=new JTextField(); JLabel j2=new JLabel(购+good.getGoodsNames().get(1)+的数量);final JTextField jt2=new JTextField(); JLabel j3=new JLabel(购+good.getGoodsNames().get(2)+的数量);final JTextField jt3=new JTextField(); JLabel j4=new JLabel(购+good.getGoodsNames().get(3)+的数量);final JTextField jt4=new JTextField(); JLabel j5=new JLabel(购+good.getGoodsNames().get(4)+的数量);final JTextField jt5=new JTextField(); JLabel j6=new JLabel(购+good.getGoodsNames().get(5)+的数量);final JTextField jt6=new JTextField(); pane1.add(j1);pane1.add(jt1); pane1.add(j2);pane1.add(jt2); pane1.add(j3);pane1.add(jt3); pane1.add(j4);pane1.add(jt4); pane1.add(j5);pane1.add(jt5); pane1.add(j6);pane1.add(jt6); rightPanelSon.add(pane1); jt1.setText(0);/商品件数都默认设为0件 jt2.setText(0); jt3.setText(0); jt4.setText(0); jt5.setText(0); jt6.setText(0); final JButton cal=new JButton(计算); final JButton empty=new JButton(归零); final JLabel hint=new JLabel();/对计算所得总额进行反应 rightPanelSon.add(cal); rightPanelSon.add(hint); rightPanelSon.add(empty); cal.addActionListener(new A
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 钢结构施工防水与排水方案
- 消防设施消防系统数据同步方案
- 氢能产业园氢能产业市场的供应与需求分析
- 建筑工程项目临时用水与排水系统方案
- 混凝土施工中的原材料质量检测方案
- 施工人员培训方案
- 水电站安全知识培训课件讲座
- 知识点2.2熟悉色彩的体系设计构成设计色彩60课件
- 水电师傅基础知识培训课件
- 二零二五年园艺绿化苗木种植与养护合同样本
- 肾内科常见病诊疗与管理
- 口腔医生岗前培训课件
- 小学一年级升二年级暑假数学作业-58套计算
- 驾考题库及答案大全
- 康复科疾病护理
- 4S店员工职业卫生培训
- 地下通道水泵房管理制度
- 溺水患者急救培训
- 2026版步步高大一轮高考数学复习讲义第十章 §10.1 计数原理与排列组合含答案
- 人力公司营销策划方案
- 医院医疗用房管理制度
评论
0/150
提交评论