




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、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.Objec
2、tInputStream;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;imp
3、ort javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JPanel;SuppressWarnings(serial)public class SystemWindow extends JFrame implements ActionListenerstatic Checkstand checkstand;/此變量單純?yōu)榱吮4孀x至保存HashMap文件中的數(shù)據(jù),相當于一個中間媒介/* * 供顯示的商品信息 */Goods good;/* * 保存收銀臺信息的文件 */static File file; stati
4、c Checkstand c;/放在此處并不和前面的checkstand相矛盾,此變量是為了讀取、保存柜臺信息 static Long number;/輸入的卡號 Timer time;/獲取系統(tǒng)時間JPanel leftPanel;JButton member;/會員服務(wù)JButton common;/普通服務(wù) JButton findMemberInfo;/查找會員信息JButton findAllMemberInfo;/查看所有會員信息JButton findGoodsSurplus;/查看商品剩余量JButton findSaleroom;/查看柜臺銷售額JPanel rightPan
5、el;JTextField showTime;JPanel rightPanelSon;public SystemWindow() super(歡迎使用超市收銀系統(tǒng));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=ne
6、w JPanel();leftPanel.setLayout(new GridLayout(6,1,4,4);member=new JButton(會員服務(wù));common=new JButton(普通服務(wù));findMemberInfo=new JButton(查找會員信息);findAllMemberInfo=new JButton(查看所有會員信息);findGoodsSurplus=new JButton(查看商品剩余量);findSaleroom=new JButton(查看柜臺銷售額);member.addActionListener(this);common.addActionL
7、istener(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(findGo
8、odsSurplus);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(leftPan
9、el);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.definedForSystemW
10、indow();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;/* *
11、 保存柜臺信息 對象串行化 */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
12、*/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(ClassNotFoundExc
13、eption 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 Pr
14、intTime=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 JT
15、extArea();/顯示商品信息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=
16、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.a
17、dd(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=fl
18、ag; final Customer customer=customer1; JPanel pane1=new JPanel(); pane1.setLayout(new GridLayout(6,2,2,2); JLabel j1=new JLabel(購+good.getGoodsNames().get(0)+的數(shù)量);final JTextField jt1=new JTextField(); JLabel j2=new JLabel(購+good.getGoodsNames().get(1)+的數(shù)量);final JTextField jt2=new JTextField(); JLa
19、bel j3=new JLabel(購+good.getGoodsNames().get(2)+的數(shù)量);final JTextField jt3=new JTextField(); JLabel j4=new JLabel(購+good.getGoodsNames().get(3)+的數(shù)量);final JTextField jt4=new JTextField(); JLabel j5=new JLabel(購+good.getGoodsNames().get(4)+的數(shù)量);final JTextField jt5=new JTextField(); JLabel j6=new JLab
20、el(購+good.getGoodsNames().get(5)+的數(shù)量);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);/商
21、品件數(shù)都默認設(shè)為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();/對計算所得總額進行反應(yīng) rightPanelSon.add(cal); rightPanelSon.add(hint); rightPanelSon.add(empty); cal.addActionListe
22、ner(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); St
23、ring 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.getPric
24、e().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.
25、updateSurplusFromFile(); /顯示商品信息要發(fā)生變化 goodsInfo.setText(good.toString(); if(flag1=5) hint.setText(該顧客享受9.5折優(yōu)惠,本應(yīng)收¥+total+實收¥+(total*0.95); /更改柜臺銷售量 c.getSaleroomFromFile(); c.setSaleroom(c.getSaleroom()+total); SystemWindow.AddCheckstandInfo(); customer.addCustomeInfo(PrintTime+消費¥+total+,享受9.5折優(yōu)惠后實
26、收¥+(total*0.95); if(total=1000&total=2000&total=4000&total=10000) JOptionPane.showMessageDialog(null, 恭喜該顧客會員卡升級為至尊卡,此后購物享受7折優(yōu)惠!); new Card5(); customer.getCustomeCard().setGrade(1);/在后面統(tǒng)一保存信息 else if(flag1=4) hint.setText(該顧客享受9折優(yōu)惠,本應(yīng)收¥+total+實收¥+(total*0.9); /更改柜臺銷售量 c.getSaleroomFromFile(); c.set
27、Saleroom(c.getSaleroom()+total); SystemWindow.AddCheckstandInfo(); customer.addCustomeInfo(PrintTime+消費¥+total+,享受9折優(yōu)惠后實收¥+(total*0.9); if(total=2000&total=4000&total=10000) JOptionPane.showMessageDialog(null, 恭喜該顧客會員卡升級為至尊卡,此后購物享受7折優(yōu)惠!); new Card5(); customer.getCustomeCard().setGrade(1);/在后面統(tǒng)一保存信息
28、 else if(flag1=3) hint.setText(該顧客享受8.5折優(yōu)惠,本應(yīng)收¥+total+實收¥+(total*0.85); /更改柜臺銷售量 c.getSaleroomFromFile(); c.setSaleroom(c.getSaleroom()+total); SystemWindow.AddCheckstandInfo(); customer.addCustomeInfo(PrintTime+消費¥+total+,享受8.5折優(yōu)惠后實收¥+(total*0.85); if(total=4000&total=10000) JOptionPane.showMessage
29、Dialog(null, 恭喜該顧客會員卡升級為至尊卡,此后購物享受7折優(yōu)惠!); new Card5(); customer.getCustomeCard().setGrade(1);/在后面統(tǒng)一保存信息 else if(flag1=2) hint.setText(該顧客享受8折優(yōu)惠,本應(yīng)收¥+total+實收¥+(total*0.8); /更改柜臺銷售量 c.getSaleroomFromFile(); c.setSaleroom(c.getSaleroom()+total); SystemWindow.AddCheckstandInfo(); customer.addCustomeInf
30、o(PrintTime+消費¥+total+,享受8折優(yōu)惠后實收¥+(total*0.8); if(total=10000) JOptionPane.showMessageDialog(null, 恭喜該顧客會員卡升級為至尊卡,此后購物享受7折優(yōu)惠!); new Card5(); customer.getCustomeCard().setGrade(1);/在后面統(tǒng)一保存信息 else if(flag1=1) hint.setText(該顧客享受7折優(yōu)惠,本應(yīng)收¥+total+實收¥+(total*0.7); /更改柜臺銷售量 c.getSaleroomFromFile(); c.setSal
31、eroom(c.getSaleroom()+total); SystemWindow.AddCheckstandInfo(); customer.addCustomeInfo(PrintTime+消費¥+total+,享受7折優(yōu)惠后實收¥+(total*0.7); /try catch(NumberFormatException e1)JOptionPane.showMessageDialog(null, 輸入格式有誤!); c1.put(card1, customer);/放在此處-統(tǒng)一保存 Checkstand.save(); /if ); empty.addActionListener(
32、new ActionListener() Override public void actionPerformed(ActionEvent e) / TODO Auto-generated method stub if(e.getSource()=empty) jt1.setText(0);/商品件數(shù)清空 jt2.setText(0); jt3.setText(0); jt4.setText(0); jt5.setText(0); jt6.setText(0); ); /else else if(e.getSource()=common) rightPanelSon.removeAll();/
33、事先先移除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.setLayou
34、t(new GridLayout(6,2,2,2); JLabel j1=new JLabel(購+good.getGoodsNames().get(0)+的數(shù)量);final JTextField jt1=new JTextField(); JLabel j2=new JLabel(購+good.getGoodsNames().get(1)+的數(shù)量);final JTextField jt2=new JTextField(); JLabel j3=new JLabel(購+good.getGoodsNames().get(2)+的數(shù)量);final JTextField jt3=new JT
35、extField(); JLabel j4=new JLabel(購+good.getGoodsNames().get(3)+的數(shù)量);final JTextField jt4=new JTextField(); JLabel j5=new JLabel(購+good.getGoodsNames().get(4)+的數(shù)量);final JTextField jt5=new JTextField(); JLabel j6=new JLabel(購+good.getGoodsNames().get(5)+的數(shù)量);final JTextField jt6=new JTextField(); pan
36、e1.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);/商品件數(shù)都默認設(shè)為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();/對計算所得總額進行反應(yīng) rightPanelSon.add(cal); rightPanelSon.add(hint); rightPanelSon.add(empty); cal.addActionListener(new A
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 國有土地開發(fā)建設(shè)合同范文
- 國際商標使用權(quán)轉(zhuǎn)讓合同標準格式
- 合資成立分公司合同書
- 成都市房屋租賃簡易合同模板
- 項目出資合同模板
- 水產(chǎn)養(yǎng)殖基地建設(shè)承包合同范本
- 建筑工程施工合同樣本(律師審核版)
- 訴訟離婚合同范本
- 廣播電視設(shè)備智能生物藥品臨床應(yīng)用技術(shù)考核試卷
- 信息技術(shù)創(chuàng)新與數(shù)字化轉(zhuǎn)型考核試卷
- 2024年單招計算機試題題庫及答案
- 肝癌科普講座課件
- 中國航天“大總師-孫家棟”
- 機電運輸安全基本知識
- 基于51單片機的無功補償裝置
- 幼兒園公開課:大班語言《相反國》課件(優(yōu)化版)
- 水利設(shè)施維護投標方案(技術(shù)標)
- 2024屆湖南省長沙市湖南師大附中等校高三上學(xué)期月考(二)語文試題(解析版)
- 上海科技版小學(xué)二年級下冊綜合實踐活動全冊教案
- 氣缸磨損的測量說課教案
- 《高鐵乘務(wù)安全管理及應(yīng)急處置》課程教案-崔藝琳編寫
評論
0/150
提交評論