《java-超市收银系统.docx》由会员分享,可在线阅读,更多相关《java-超市收银系统.docx(6页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上package software; import java.awt.*; import java.awt.event.*;import javax.swing.*;class shangpinString SId;String Smane;int jiage;public shangpin(String a,String b,int c)SId=a;Smane=b;jiage=c;class huiyuanString HId;String Hname;public huiyuan(String a,String b)HId=a;Hname=b;public clas
2、s chaoshi extends JFrame static int key=0; /会员static int sum1=0; /总消费static int sum2=0; /当天合计static int huiyuansum=0; /会员人数static int Spinsum1=0; /商品1合计 static int Spinsum2=0; /商品2合计static int Spinsum3=0; /商品3合计static int Spinsum4=0; /商品4合计static int Spinsum5=0; /商品5合计public static void main(String
3、agrs)JFrame frame =new JFrame(超市);frame.setSize(400,250);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);Container c=frame.getContentPane(); c.add(pan(); frame.setVisible(true);static JPanel pan ()JPanel panel=new JPanel();JPanel part1=new JPanel();part1.add(new JLabel(会员卡号:);final JTextField t
4、ext1=new JTextField();text1.setHorizontalAlignment(JTextField.RIGHT);text1.setColumns(11);JButton button1=new JButton(确定);part1.add(text1); part1.add(button1);part1.setVisible(true);final JLabel JLabel00 =new JLabel(非会员);part1.add(JLabel00); panel.add(part1);JPanel part2=new JPanel();part2.add(new J
5、Label(商品代号:);final JTextField text2=new JTextField();text2.setHorizontalAlignment(JTextField.RIGHT);text2.setColumns(15);JButton button2=new JButton(确定);part2.add(text2); part2.add(button2);panel.add(part2);JPanel part3=new JPanel();final JLabel JLabel0=new JLabel( );final JLabel JLabel1=new JLabel(
6、000);final JLabel JLabel2=new JLabel(0000);part3.add(new JLabel(商品名); part3.add(JLabel0);part3.add(new JLabel(商品价格); part3.add(JLabel1);part3.add(new JLabel(元);part3.add(new JLabel(总价格); part3.add(JLabel2);part3.add(new JLabel(元);part3.add(new JLabel( ); panel.add(part3);JPanel part4=new JPanel();JB
7、utton button3=new JButton(结账);JButton button4=new JButton(总汇); part4.add(button3);part4.add(new JLabel( );part4.add(button4); panel.add(part4);button1.addActionListener(new ActionListener() huiyuan huiyuan1=new huiyuan(00001,会员甲);huiyuan huiyuan2=new huiyuan(00002,会员乙);huiyuan huiyuan3=new huiyuan(0
8、0003,会员丙); public void actionPerformed(ActionEvent e) String kahao=text1.getText(); if(kahao.equals(huiyuan1.HId) JLabel00.setText(huiyuan1.Hname); key=1; if(kahao.equals(huiyuan2.HId) JLabel00.setText(huiyuan2.Hname); key=1; if(kahao.equals(huiyuan3.HId) JLabel00.setText(huiyuan3.Hname); key=1;); b
9、utton2.addActionListener(new ActionListener() shangpin shangpin1=new shangpin(001,商品1,10);shangpin shangpin2=new shangpin(002,商品2,11);shangpin shangpin3=new shangpin(003,商品3,12);shangpin shangpin4=new shangpin(004,商品4,13);shangpin shangpin5=new shangpin(005,商品5,14);public void actionPerformed(Action
10、Event e) String shangpinhao=text2.getText(); if(shangpinhao.equals(shangpin1.SId) JLabel0.setText( +shangpin1.Smane); String str = String.format(%04d,shangpin1.jiage); JLabel1.setText(str); sum1=sum1+shangpin1.jiage; sum2=sum2+shangpin1.jiage; String str1 = String.format(%04d,sum1); JLabel2.setText(
11、str1); Spinsum1+; ; if(shangpinhao.equals(shangpin2.SId) JLabel0.setText( +shangpin2.Smane); String str = String.format(%04d,shangpin2.jiage); JLabel1.setText(str); sum1=sum1+shangpin2.jiage; sum2=sum2+shangpin2.jiage; String str1 = String.format(%04d,sum1); JLabel2.setText(str1); Spinsum2+; ; if(sh
12、angpinhao.equals(shangpin3.SId) JLabel0.setText( +shangpin3.Smane); String str = String.format(%04d,shangpin3.jiage); JLabel1.setText(str); sum1=sum1+shangpin3.jiage; sum2=sum2+shangpin3.jiage; String str1 = String.format(%04d,sum1); JLabel2.setText(str1); Spinsum3+; ; if(shangpinhao.equals(shangpin
13、4.SId) JLabel0.setText( +shangpin4.Smane); String str = String.format(%04d,shangpin4.jiage); JLabel1.setText(str); sum1=sum1+shangpin4.jiage; sum2=sum2+shangpin4.jiage; String str1 = String.format(%04d,sum1); JLabel2.setText(str1); Spinsum4+; ; if(shangpinhao.equals(shangpin5.SId) JLabel0.setText( +
14、shangpin5.Smane); String str = String.format(%04d,shangpin5.jiage); JLabel1.setText(str); sum1=sum1+shangpin5.jiage; sum2=sum2+shangpin5.jiage; String str1 = String.format(%04d,sum1); JLabel2.setText(str1); Spinsum5+; ; );button3.addActionListener(new ActionListener() public void actionPerformed(Act
15、ionEvent e)if(sum1!=0) huiyuansum+;JDialog duox=new JDialog(); JPanel duoxP=new JPanel();duox.getContentPane().add(duoxP);duox.setTitle(消费总额); duoxP.setVisible(true);duoxP.setLayout(new GridLayout(4,1,0,0);duox.setSize(200,300); duox.setVisible(true);JPanel panel1=new JPanel(); JPanel part11=new JPa
16、nel();JPanel part12=new JPanel();String str1 = String.format(%04d,sum1); JLabel Label11=new JLabel(str1); Label11.setText(str1);part11.add(new JLabel(消费总额:);part11.add(Label11);if(key!=1)&sum1=200) part12.add(new JLabel(消费达200元发放一张会员卡);panel1.add(part12);panel1.add(part11); duoxP.add(panel1);key=0;
17、sum1=0;JLabel0.setText( ); JLabel1.setText(000);JLabel2.setText(0000); JLabel00.setText(非会员);text1.setText(); text2.setText(); ); button4.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e)JDialog duox=new JDialog(); JPanel duoxP=new JPanel();duox.getContentPane().add(d
18、uoxP); duox.setTitle(消费总额);duoxP.setVisible(true);duoxP.setLayout(new GridLayout(8,1,0,0);duox.setSize(200,400); duox.setVisible(true);JPanel part21=new JPanel();JPanel part22=new JPanel();JPanel part23=new JPanel();JPanel part24=new JPanel();JPanel part25=new JPanel();JPanel part26=new JPanel();JPa
19、nel part27=new JPanel();JButton button5=new JButton(全部清零);final JLabel label21=new JLabel();part21.add(new JLabel(总消费额);String str21 = String.format(%04d,sum2); label21.setText(str21); part21.add(label21);final JLabel label22=new JLabel();part22.add(new JLabel(商品1消费量);String str22 = String.format(%0
20、4d,Spinsum1); label22.setText(str22); part22.add(label22); final JLabel label23=new JLabel();part23.add(new JLabel(商品2消费量);String str23 = String.format(%04d,Spinsum2); label23.setText(str23); part23.add(label23); final JLabel label24=new JLabel();part24.add(new JLabel(商品3消费量);String str24 = String.f
21、ormat(%04d,Spinsum3); label24.setText(str24); part24.add(label24); final JLabel label25=new JLabel();part25.add(new JLabel(商品4消费量);String str25 = String.format(%04d,Spinsum4); label25.setText(str25); part25.add(label25); final JLabel label26=new JLabel();part26.add(new JLabel(商品5消费量);String str26 =
22、String.format(%04d,Spinsum5); label26.setText(str26); part26.add(label26); final JLabel label27=new JLabel();part27.add(new JLabel(消费人次);String str27 = String.format(%04d,huiyuansum); label27.setText(str27); part27.add(label27); button5.addActionListener(new ActionListener() public void actionPerfor
23、med(ActionEvent e) sum2=0; Spinsum1=0; Spinsum2=0; Spinsum3=0; Spinsum4=0; Spinsum5=0; huiyuansum=0; label21.setText(0000);label22.setText(0000);label23.setText(0000); label24.setText(0000);label25.setText(0000);label26.setText(0000); label27.setText(0000); ); duoxP.add(part21);duoxP.add(part22);duoxP.add(part23);duoxP.add(part24); duoxP.add(part25);duoxP.add(part26); duoxP.add(part27);duoxP.add(button5); ); return panel;专心-专注-专业