超收银系统Java语言实现#.docx
- 文档编号:10316896
- 上传时间:2023-02-10
- 格式:DOCX
- 页数:47
- 大小:26.79KB
超收银系统Java语言实现#.docx
《超收银系统Java语言实现#.docx》由会员分享,可在线阅读,更多相关《超收银系统Java语言实现#.docx(47页珍藏版)》请在冰豆网上搜索。
超收银系统Java语言实现#
packagecashier。
importjava.awt.BorderLayout。
importjava.awt.FlowLayout。
importjava.awt.GridLayout。
importjava.awt.event.ActionEvent。
importjava.awt.event.ActionListener。
importjava.io.File。
importjava.io.FileInputStream。
importjava.io.FileOutputStream。
importjava.io.IOException。
importjava.io.ObjectInputStream。
importjava.io.ObjectOutputStream。
importjava.text.DateFormat。
importjava.text.SimpleDateFormat。
importjava.util.Date。
importjava.util.HashMap。
importjavax.swing.JLabel。
importjavax.swing.JOptionPane。
importjavax.swing.JTextArea。
importjavax.swing.JTextField。
importjavax.swing.Timer。
importjavax.swing.JButton。
importjavax.swing.JFrame。
importjavax.swing.JPanel。
@SuppressWarnings("serial">
publicclassSystemWindowextendsJFrameimplementsActionListener{
staticCheckstandcheckstand。
//此变量单纯为了保存读至保存HashMap文件中的数据,相当于一个中间媒介
/**
*供显示的商品信息
*/
Goodsgood。
/**
*保存收银台信息的文件
*/
staticFilefile。
staticCheckstandc。
//放在此处并不和前面的checkstand相矛盾,此变量是为了读取、保存柜台信息
staticLongnumber。
//输入的卡号
Timertime。
//获取系统时间
JPanelleftPanel。
JButtonmember。
//会员服务
JButtoncommon。
//普通服务
JButtonfindMemberInfo。
//查找会员信息
JButtonfindAllMemberInfo。
//查看所有会员信息
JButtonfindGoodsSurplus。
//查看商品剩余量
JButtonfindSaleroom。
//查看柜台销售额
JPanelrightPanel。
JTextFieldshowTime。
JPanelrightPanelSon。
publicSystemWindow(>{
super("欢迎使用超市收银系统">。
file=newFile("checkstand.dat">。
SystemWindow.readCheckstandInfo(>。
//读取柜台信息
Goods.getSurplusFromFile(>。
//这一步很重要!
good=newGoods(>。
time=newTimer(1000,this>。
//时间
time.start(>。
this.setLayout(newGridLayout(1,2,4,4>>。
leftPanel=newJPanel(>。
leftPanel.setLayout(newGridLayout(6,1,4,4>>。
member=newJButton("会员服务">。
common=newJButton("普通服务">。
findMemberInfo=newJButton("查找会员信息">。
findAllMemberInfo=newJButton("查看所有会员信息">。
findGoodsSurplus=newJButton("查看商品剩余量">。
findSaleroom=newJButton("查看柜台销售额">。
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=newJPanel(>。
showTime=newJTextField(12>。
rightPanelSon=newJPanel(>。
showTime.setEditable(false>。
rightPanel.setLayout(newBorderLayout(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"}>
publicstaticHashMap
Filefile=Checkstand.file。
if(file.length(>==0>{
checkstand=newCheckstand(>。
checkstand.definedForSystemWindow(>。
}
elsetry{
ObjectInputStreamin=newObjectInputStream(newFileInputStream(file>>。
checkstand.cardAndCustomer=(HashMap
in.close(>。
}
catch(IOExceptione>{System.err.println(e.getMessage(>>。
}
catch(ClassNotFoundExceptione1>{System.err.println("文件未找到!
">。
}
returncheckstand.cardAndCustomer。
}
/**
*保存柜台信息对象串行化
*/
publicstaticvoidAddCheckstandInfo(>{
try{
if(c==null>
c=newCheckstand(>。
ObjectOutputStreamout=newObjectOutputStream(newFileOutputStream(file>>。
out.writeObject(c>。
out.close(>。
}
catch(IOExceptione>{System.out.println(e.getMessage(>>。
}
}
/**
*从文件中读取柜台信息对象串行化
*@throwsClassNotFoundException
*/
publicstaticvoidreadCheckstandInfo(>{
try{
ObjectInputStreamin=newObjectInputStream(newFileInputStream(file>>。
Objecto=in.readObject(>。
if(o!
=null>
c=(Checkstand>o。
else
c=newCheckstand(>。
//在此处生成柜台对象再合适不过来
in.close(>。
}
catch(IOExceptione>{System.out.println(e.getMessage(>>。
}
catch(ClassNotFoundExceptione1>{System.out.println("文件未找到!
">。
}
}
publicstaticvoidmain(String[]args>{
newSystemWindow(>。
}
@Override
publicvoidactionPerformed(ActionEvente>{
//TODOAuto-generatedmethodstub
DateFormatformat=newSimpleDateFormat(>。
Datedate=newDate(>。
showTime.setText("北京时间:
"+format.format(date>>。
finalStringPrintTime=format.format(date>。
//将信息打印在顾客的消费信息上
if(e.getSource(>==member>{
rightPanelSon.removeAll(>。
//事先先移除rightPanelSon中的所有的组件
this.paintAll(getGraphics(>>。
//相当于重画的功能,此部骤相当重要
rightPanelSon.setLayout(newFlowLayout(>>。
rightPanelSon.add(newJPanel(>>。
rightPanelSon.add(newJPanel(>>。
finalJTextAreagoodsInfo=newJTextArea(>。
//显示商品信息
rightPanelSon.add(goodsInfo>。
goodsInfo.setEditable(false>。
//不可编辑
goodsInfo.setText(good.toString(>>。
Stringid=JOptionPane.showInputDialog("请输入会员卡卡号:
">。
try{
number=Long.parseLong(id>。
}
catch(NumberFormatExceptione1>{
JOptionPane.showMessageDialog(null,"输入格式有误!
">。
return。
}
finalHashMap
if(c1==null>{
JOptionPane.showMessageDialog(null,"会员信息不存在!
",null,JOptionPane.WARNING_MESSAGE>。
return。
}
else{
intflag=0。
Customercustomer1=null。
ClubCardcard2=null。
for(ClubCardcard:
c1.keySet(>>{
if(number.equals(card.getId(>>>{
JTextAreaarea=newJTextArea(>。
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。
}
finalClubCardcard1=card2。
finalintflag1=flag。
finalCustomercustomer=customer1。
JPanelpane1=newJPanel(>。
pane1.setLayout(newGridLayout(6,2,2,2>>。
JLabelj1=newJLabel("购"+good.getGoodsNames(>.get(0>+"的数量">。
finalJTextFieldjt1=newJTextField(>。
JLabelj2=newJLabel("购"+good.getGoodsNames(>.get(1>+"的数量">。
finalJTextFieldjt2=newJTextField(>。
JLabelj3=newJLabel("购"+good.getGoodsNames(>.get(2>+"的数量">。
finalJTextFieldjt3=newJTextField(>。
JLabelj4=newJLabel("购"+good.getGoodsNames(>.get(3>+"的数量">。
finalJTextFieldjt4=newJTextField(>。
JLabelj5=newJLabel("购"+good.getGoodsNames(>.get(4>+"的数量">。
finalJTextFieldjt5=newJTextField(>。
JLabelj6=newJLabel("购"+good.getGoodsNames(>.get(5>+"的数量">。
finalJTextFieldjt6=newJTextField(>。
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">。
finalJButtoncal=newJButton("计算">。
finalJButtonempty=newJButton("归零">。
finalJLabelhint=newJLabel(>。
//对计算所得总额进行反应
rightPanelSon.add(cal>。
rightPanelSon.add(hint>。
rightPanelSon.add(empty>。
cal.addActionListener(newActionListener(>{
@SuppressWarnings({"static-access"}>
@Override
publicvoidactionPerformed(ActionEvente>{
Doubletotal=0.0。
//TODOAuto-generatedmethodstub
if(e.getSource(>==cal>{
try{
Strings1=jt1.getText(>。
intnum1=Integer.parseInt(s1>。
Strings2=jt2.getText(>。
intnum2=Integer.parseInt(s2>。
Strings3=jt3.getText(>。
intnum3=Integer.parseInt(s3>。
Strings4=jt4.getText(>。
intnum4=Integer.parseInt(s4>。
Strings5=jt5.getText(>。
intnum5=Integer.parseInt(s5>。
Strings6=jt6.getText(>。
intnum6=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>{
JOptionPane.showMessageDialog(null,"恭喜该顾客会员卡升级为\"蓝钻卡\",此后购物享受9折优惠!
">。
newCard2(>。
customer.getCustomeCard(>.setGrade(4>。
//在后面统一保存信息
}
elseif(total>=2000&&total<4000>{
JOptionPane.showMessageDialog(null,"恭喜该顾客会员卡升级为\"贵族卡\",此后购物享受8.5折优惠!
">。
newCard3(>。
customer.getCustomeCard(>.setGrade(3>。
//在后面统一保存信息
}
elseif(total>=4000&&total<10000>{
JOptionPane.showMessageDialog(null,"恭喜该顾客会员卡升级为\"白钻卡\",此后购物享受8折优惠!
">。
newCard4(>。
customer.getCustomeCard(>.setGrade(2>。
//在后面统一保存信息
}
elseif(total>=10000>{
JOptionPane.showMessageDialog(null,"恭喜该顾客会员卡升级为\"至尊卡\",此后购物享受7折优惠!
">。
newCard5(>。
customer.getCustomeCard(>.setGrade(1>。
//在后面统一保存信息
}
}
elseif(flag1==4>{
hint.setText("该顾客享受9折优惠,本应收¥"+total+"实收¥"+(total*0.9>>。
//更改柜台销售量
c.getSaleroomFromFile(>。
c.setSaleroom(c.getSaleroom(>+total>。
SystemWindow.AddCheckstandInfo(>。
customer.addCu
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 收银 系统 Java 语言 实现