1、超市收银课程设计目录1 设计时间 32 设计目的 33设计任务 33.1任务说明 33.2系统目标 33.3使用范围 34 设计内容 34.1界面构建 34.2详细设计 34.2.1模块设计 44.2.2运行调试 44.2.3部分源程序 85 总结与展望 28参考文献 29成绩评定 291 设计时间2011年6月11日-2011年6月15日2 设计目的通过实践加深学生对面向对象程序设计的理论、方法和基础知识的理解,掌握使用Java语言进行面向对象设计的基本方法,提高运用面向对象知识分析实际问题、解决实际问题的能力,提高学生的应用能力。3设计任务3.1任务说明设计出一个超市收银程序(1)使用图形
2、用户界面实现。信息返回给收银台,计算出该顾客所购商品的总价格。(3)每天营业结束把该收银台的销售总额进行统计汇总(要求包括商品种类、数量、销售总额、结账人次等信息,其余可自行丰富)并存储在数据库中。(4)所有持卡顾客的消费商品情况存储到文件以供查询。(5)对没有卡的消费情况不记录该顾客的消费情况等个人信息。如果一个未持卡顾客一次购物满200元,结完账后系统提示可为其发放一张会员卡3.2系统目标该软件开发的用途是用来方便超市的收银管理,提高办事效率。3.3使用范围本程序用于超市对会员和非会员的销售管理4 设计内容 4.1界面构建为了便于各种操作,软件采用多窗口的模式。用户可在不同窗口进行相应操作
3、。4.2详细设计4.2.1模块设计 4.2.2运行调试图1登录界面图2操作界面图3.1修改数量图3.2 填入要修改数量的商品号图3.3输入新数量图4.1 普通结算图4.2会员结算图5销售情况图6系统时间4.2.3部分源程序登录import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.StringTokenizer;
4、import javax.swing.*;public class land public static void main(String args) landframe frame = new landframe(); frame.setTitle(收营员登陆); frame.setLocation(300,300); frame.setSize(270, 170); frame.setVisible(true); class landframe extends JDialog implements ActionListener public landframe() label1 = new
5、 JLabel(JAVA超市收营系统 请登陆); label2 = new JLabel(用户名:); label3 = new JLabel(密码:); hbox1 = Box.createHorizontalBox(); hbox2 = Box.createHorizontalBox(); vbox = Box.createVerticalBox(); jf1 = new JTextField(); JPF= new JPasswordField(); JPF.addActionListener(this); land = new JButton(登陆); land.addActionLi
6、stener(this); panel1 = new JPanel(); panel2 = new JPanel(); hbox1.add(label2); hbox1.add(Box.createHorizontalStrut(5); hbox1.add(jf1); hbox2.add(label3); hbox2.add(Box.createHorizontalStrut(18); panel2.add(land, Center); hbox2.add(JPF); vbox.add(label1); vbox.add(Box.createVerticalStrut(10); vbox.ad
7、d(hbox1); vbox.add(Box.createVerticalStrut(10); vbox.add(hbox2); vbox.add(Box.createVerticalStrut(10); vbox.add(panel2); panel1.add(vbox); getContentPane().add(panel1, Center); public void actionPerformed(ActionEvent evt) Object source = evt.getSource(); if (source = land | source = JPF) / 登陆按纽及第二个文
8、本输入框ENTER功能实现 String a = , b, read; boolean denglusuccees = false; try FileReader fr = new FileReader(denglu.txt); BufferedReader br = new BufferedReader(fr); while (read = br.readLine() != null) StringTokenizer sto = new StringTokenizer(read); a = sto.nextToken(); b = sto.nextToken(); if (jf1.getTe
9、xt().equals(a) & JPF.getText().equals(b) denglusuccees = true; break; / 验证登陆员号码及密码 catch (IOException ie) System.err.println(ie.getMessage(); if (denglusuccees = true) setVisible(false); mainview mw = new mainview(); mw.setTitle(a + 为您服务); mw.setSize(850, 500); mw.setLocation(200, 180); mw.setVisibl
10、e(true); else jf1.setText(); JPF.setText(); JOptionPane.showMessageDialog(null, 非法用户); private JLabel label1, label2, label3; private Box hbox1, hbox2, vbox; private JTextField jf1; private JPasswordField JPF; private JButton land; private JPanel panel1, panel2;物价计算public class draw double a; double
11、 b; String c; public draw(double fnum, double all, String information) / 构造函数 a = fnum;/ 获得指定商品当销售额 b = all;/ 获得当天总销售额 c = information;/ 获得指定商品的编号 DrawJDialog frame = new DrawJDialog(); frame.setSize(400, 300); frame.setLocation(400, 300); frame.setVisible(true); class DrawJDialog extends JDialog im
12、plements ActionListener/ 界面及功能实现 JButton shut; JTextArea one = new JTextArea(); DrawPanel panel = new DrawPanel(); shut = new JButton(关闭); shut.addActionListener(this); double rate = 100 * a / b; DecimalFormat df = new DecimalFormat(#.00); rate = Double.parseDouble(df.format(rate);/ 格式化小数显示 one.setT
13、ext( + c + n + 占今天销售额 + rate + %); panel.add(one); panel.add(shut); Container contentPane = getContentPane(); contentPane.add(panel); setTitle(销售情况); public void actionPerformed(ActionEvent evt) Object source = evt.getSource(); setVisible(false); class DrawPanel extends JPanel/ 画饼图 public void paint
14、Component(Graphics g) g.clearRect(30, 40, 150, 150); double x1 = a; double x2 = b; int angle; super.paintComponent(g); angle = (int) (360 * x1 / x2); g.setColor(Color.blue); g.drawArc(30, 100, 150, 150, 0, angle); g.fillArc(30, 100, 150, 150, 0, angle); g.setColor(Color.GREEN); g.drawArc(30, 100, 15
15、0, 150, 0 + angle, 360 - angle); g.fillArc(30, 100, 150, 150, 0 + angle, 360 - angle); 应用操作import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import java.awt.*;import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.*;class mainview ex
16、tends JFrame implements ActionListener DataManagement mydata = new DataManagement(); sellcount mysell = new sellcount(); judge myjudge = new judge(); int dcount = 1; public mainview() changeButton1 = new JButton(修改价格); changeButton1.addActionListener(this); changeButton1.setEnabled(false); changeBut
17、ton2 = new JButton(修改数量); changeButton2.addActionListener(this); changeButton2.setEnabled(false); deleteButton = new JButton(删除商品); deleteButton.addActionListener(this); deleteButton.setEnabled(false); finishButton = new JButton(完成结算); finishButton.addActionListener(this); finishButton.setEnabled(fa
18、lse); cheapButton = new JButton(会员结算); cheapButton.addActionListener(this); cheapButton.setEnabled(false); recordButton = new JButton(记录清单); recordButton.addActionListener(this); recordButton.setEnabled(false); moneyButton = new JButton(找零计算); moneyButton.addActionListener(this); moneyButton.setEnab
19、led(false); clearButton = new JButton(清除清单); clearButton.addActionListener(this); textAll = new JTextField(0); textAll.setEditable(false); textAll.setBorder(BorderFactory.createEtchedBorder(); textChange = new JTextArea(7, 0); textChange.setEditable(false); textChange.setBorder(BorderFactory.createE
20、tchedBorder(); hbox2 = Box.createHorizontalBox(); vbox2 = Box.createVerticalBox(); vbox2.add(Box.createVerticalStrut(9); vbox2.add(changeButton1); vbox2.add(Box.createVerticalStrut(9); vbox2.add(changeButton2); vbox2.add(Box.createVerticalStrut(9); vbox2.add(deleteButton); vbox2.add(Box.createVertic
21、alStrut(9); vbox2.add(finishButton); vbox2.add(Box.createVerticalStrut(9); vbox2.add(cheapButton); vbox2.add(Box.createVerticalStrut(9); vbox2.add(textAll); vbox2.add(moneyButton); vbox2.add(textChange); vbox2.setBorder(BorderFactory.createEtchedBorder(); textArea = new JTextArea(24, 37); textArea.s
22、etMaximumSize(textArea.getPreferredSize(); textArea.setEditable(false); scrollPane = new JScrollPane(textArea); textAdd = new JTextField(20); textAdd.addActionListener(this); vbox1 = Box.createVerticalBox(); hbox1 = Box.createHorizontalBox(); label1 = new JLabel(此处输入商品编号 ); label2 = new JLabel(商品信息显
23、示:); drawButton = new JButton(单天商品销售情况); drawButton.addActionListener(this); vbox1.add(label1); vbox1.add(textAdd); hbox1.add(label2); hbox1.add(drawButton); vbox1.add(hbox1); vbox1.add(scrollPane); vbox1.setBorder(BorderFactory.createLoweredBevelBorder(); vbox3 = Box.createVerticalBox(); hbox3 = Bo
24、x.createHorizontalBox(); label3 = new JLabel(最终清单); label4 = new JLabel(版权所属); label4.setBorder(BorderFactory.createEtchedBorder(); textFinish = new JTextArea(24, 30); textFinish.setEditable(false); textFinish.setBorder(BorderFactory.createEtchedBorder(Color.WHITE, Color.BLACK); hbox3.add(recordButt
25、on); hbox3.add(Box.createHorizontalStrut(10); hbox3.add(clearButton); hbox3.add(Box.createHorizontalStrut(10); hbox3.add(label4); vbox3.add(new clock(); vbox3.add(label3); hbox3.setBorder(BorderFactory.createEtchedBorder(); vbox3.add(textFinish); vbox3.add(hbox3); vbox3.setBorder(BorderFactory.creat
26、eLoweredBevelBorder(); hbox2.add(vbox1); hbox2.add(vbox2); hbox2.add(vbox3); getContentPane().add(hbox2); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0); ); public void actionPerformed(ActionEvent evt) Object source = evt.getSource(); if (source = textA
27、dd) / 商品添加 String log = textAdd.getText(); StringTokenizer sto = new StringTokenizer(log); String dcode = sto.nextToken(); boolean inputwrite = true; int dnum = 1; if (sto.hasMoreTokens() try int tempnum=Integer.parseInt(sto.nextToken(); if(tempnum0)dnum = Integer.parseInt(sto.nextToken(); else inpu
28、twrite=false; catch (NumberFormatException e) JOptionPane.showMessageDialog(null, 请输入数字); inputwrite = false; if (inputwrite = true) if (myjudge.find(dcode) = -1) String wrong = Cant find + dcode; JOptionPane.showMessageDialog(null, wrong); textAdd.setText(); else int location = myjudge.find(dcode);
29、 String dname = myjudge.judgeDatalocation.getName(); double dprice = myjudge.judgeDatalocation.getPrice(); mydata.add(dcode, dname, dprice, dnum); textArea.setText(); for (int i = 0; i mydata.acount; i+) textArea.insert(商品 + (i + 1) + 编号: + mydata.productDatai.getCode() + 商品名称: + mydata.productDatai.getName() + 商品价格: + mydata.productDatai.getPrice() + 元/单位 + mydata.productDatai.getNum() + 个