当前位置:文档之家› 超市管理系统设计代码

超市管理系统设计代码

import java.awt.*;import java.awt.event.*;import javax.swing.table.*;import javax.swing.event.*;import javax.swing.*;import java.sql.*;import java.util.*;import java.io.*;class Myframe1 extends JFrame //设置主界面{JFrame f=new JFrame();JLabel L1,L2;JButton btn1,btn2,btn3,btn4;public Myframe1(){f=new JFrame("主界面");L1=new JLabel("超市商品管理系统欢迎您");L1.setFont(new Font("TimesRoman",Font.BOLD,18));L2=new JLabel("您辛苦了~~~~");L2.setFont(new Font("TimesRoman",Font.BOLD,18));btn1=new JButton("进货管理系统");btn2=new JButton("售货管理系统");btn3=new JButton("商品信息管理");btn4=new JButton("管理系统帮助");Container container=this.getContentPane();container.setLayout(new GridLayout(9,3,0,50));for(int i=0;i<3;i++)container.add(new JLabel());container.add(new JLabel()); container.add(L1);container.add(new JLabel());container.add(new JLabel()); container.add(btn1);container.add(new JLabel());container.add(new JLabel()); container.add(btn2);container.add(new JLabel());container.add(new JLabel()); container.add(btn3);container.add(new JLabel());container.add(new JLabel()); container.add(btn4);container.add(new JLabel());container.add(new JLabel()); container.add(L2);container.add(new JLabel());container.setBackground(Color.cyan);f.add(container);f.setLocation(60,60);f.setSize(750,650);f.setVisible(true);Montior bn=new Montior();btn1.addActionListener(bn);btn2.addActionListener(bn);btn3.addActionListener(bn);btn4.addActionListener(bn);}class Montior implements ActionListener{public void actionPerformed(ActionEvent e1) {if(e1.getSource()==btn1){new Myframe2();}if(e1.getSource()==btn2){new Myframe3();}if(e1.getSource()==btn3){new Myframe4();}if(e1.getSource()==btn4){new bangzhu();}}}}class bangzhu extends JFrame{JTextPane ta=new JTextPane();JScrollPane sp=new JScrollPane(ta);public bangzhu(){super("管理系统帮助");ta.setFont(new Font("TimesRoaman",Font.BOLD+Font.PLAIN,20));ta.setText(" 1.初次进入登录系统,系统中没有售货员信息,可以进入系统但是为了以后能够使用方便\n"+" 还是增加售货员信息,以便下次登录。

"+" 2.通过编号和密码验证后,进入系统主界面,但是为了能方便的进行操作,要在添加商品信息"+" 3.添加了商品信息和售货员信息,即可根据信息进行填写别的表操作。

");ta.setEditable(false);Container container=this.getContentPane();container.setLayout(new BorderLayout());container.add(new JLabel(),BorderLayout.NORTH);container.add(new JLabel(),BorderLayout.WEST);container.add(new JLabel(),BorderLayout.EAST);container.add(new JLabel(),BorderLayout.SOUTH);container.add(sp,BorderLayout.CENTER);this.setSize(400,330);this.setVisible(true);}}class Myframe2 extends JFrame //设置进货系统的界面{Pstock stock=new Pstock();Ptrademan trademan=new Ptrademan();JTabbedPane pane;Myframe2(){super("进货管理系统");pane=new JTabbedPane(JTabbedPane.TOP);pane.add("进货单信息",stock);pane.add("进货商信息",trademan);this.add(pane);this.setSize(700,550);this.setLocation(100,100);this.setVisible(true);}class Pstock extends JPanel implements ActionListener //添加进货单管理的组件 {private database db=new database();ResultSet rs;Panel p;Panel p1;JTextArea t;JButton btn1,btn2,btn3,btn4,btn5,btn6;JLabel L1,L2;//表格设置JTable table;JScrollPane scrollpane;Vector vector;AbstractTableModel tm;String title[]={"条形码","供应商名","进货价","进货日期","进货量"}; Pstock(){create();p=new Panel();p1=new Panel();btn1=new JButton("填写新的进货单");btn2=new JButton("解除购买某商品");btn3=new JButton("修改进货单信息");btn4=new JButton("查询进货单信息");btn5=new JButton("显示进货单所有信息");btn6=new JButton("进货商品的总金额");L1=new JLabel("进货单的信息显示栏",JLabel.CENTER);L1.setFont(new Font("TimesRoman",Font.BOLD,16));L2=new JLabel("进货单信息管理",JLabel.CENTER);L2.setFont(new Font("TimesRoman",Font.BOLD,16));p.setLayout(new GridLayout(9,1,20,20));p.add(L2);p.add(btn1);p.add(btn2);p.add(btn3);p.add(btn4);p.add(btn6);p.add(btn5);p.add(new JLabel());p.add(new JLabel());p1.setLayout(new BorderLayout());p1.add(L1,BorderLayout.NORTH);p1.add(scrollpane,BorderLayout.CENTER);this.setLayout(new BorderLayout());this.add(p1,BorderLayout.CENTER);this.add(p,BorderLayout.EAST);btn1.addActionListener(this);btn2.addActionListener(this);btn3.addActionListener(this);btn4.addActionListener(this);btn5.addActionListener(this);btn6.addActionListener(this);}public void actionPerformed(ActionEvent e2) {if(e2.getSource()==btn1){new tianxie();}if(e2.getSource()==btn2){new shanchu();}if(e2.getSource()==btn3){new xiugai();}if(e2.getSource()==btn4){new chaxun();}if(e2.getSource()==btn5) //数据库区显示进货单所有信息 { int flag=0;try{rs=db.select("select * from stocklist");vector.removeAllElements();while(rs.next()){flag=1;Vector rec_vector=new Vector();rec_vector.addElement(rs.getString(1));rec_vector.addElement(rs.getString(2));rec_vector.addElement(rs.getString(3));rec_vector.addElement(rs.getString(4));rec_vector.addElement(rs.getString(5));vector.addElement(rec_vector);}tm.fireTableStructureChanged();if(flag==0){JOptionPane.showMessageDialog(null,"还没有进货单信息");}}catch(SQLException ee){ee.printStackTrace();}}if(e2.getSource()==btn6){new jine();}}void create(){vector = new Vector();tm = new AbstractTableModel(){public int getColumnCount(){return title.length; //取得表格列数}public int getRowCount(){return vector.size(); //取得表格行数}public Object getValueAt(int row,int column){if(!vector.isEmpty()) //取得单元格中的属性值return ((Vector)vector.elementAt(row)).elementAt(column); elsereturn null;}public String getColumnName(int column){return title[column]; //设置表格列名}public void setValueAt(Object value,int row,int column){//数据模型不可编辑,该方法设置为空}public Class getColumnClass(int c){return getValueAt(0,c).getClass(); //取得列所属对象类}public boolean isCellEditable(int row,int column){return false;//设置单元格不可编辑,为缺省实现}};table=new JTable(tm);table.setToolTipText("显示内容");table.setAutoResizeMode(table.AUTO_RESIZE_OFF);table.setCellSelectionEnabled(false);table.setShowHorizontalLines(true);table.setShowVerticalLines(true);scrollpane=new JScrollPane(table);}}class Ptrademan extends JPanel implements ActionListener //进货商管理信息 {private database db=new database();ResultSet rs;Panel p;Panel p1;JButton btn1,btn2,btn3,btn4,btn5;JLabel L1,L2;//表格设置JTable table;JScrollPane scrollpane;Vector vector;AbstractTableModel tm;String title[]={"供应商名","电话","条形码","进货价"};Ptrademan(){create();p=new Panel();p1=new Panel();btn1=new JButton("填写新的进货商");btn2=new JButton("删除进货商信息");btn3=new JButton("修改进货商信息");btn4=new JButton("查询进货商信息");btn5=new JButton("显示进货商所有信息");L1=new JLabel("进货商信息显示栏",JLabel.CENTER);L1.setFont(new Font("TimesRoman",Font.BOLD,16));L2=new JLabel("进货商信息管理",JLabel.CENTER);L2.setFont(new Font("TimesRoman",Font.BOLD,16));p.setLayout(new GridLayout(9,1,20,20));p.add(L2);p.add(btn1);p.add(btn2);p.add(btn3);p.add(btn4);p.add(new JLabel());p.add(btn5);p.add(new JLabel());p.add(new JLabel());p1.setLayout(new BorderLayout());p1.add(L1,BorderLayout.NORTH);p1.add(scrollpane,BorderLayout.CENTER);this.setLayout(new BorderLayout());this.add(p1,BorderLayout.CENTER);this.add(p,BorderLayout.WEST);btn1.addActionListener(this);btn2.addActionListener(this);btn3.addActionListener(this);btn4.addActionListener(this);btn5.addActionListener(this);}void create(){vector = new Vector();tm = new AbstractTableModel(){public int getColumnCount(){return title.length; //取得表格列数}public int getRowCount(){return vector.size(); //取得表格行数}public Object getValueAt(int row,int column){if(!vector.isEmpty()) //取得单元格中的属性值return ((Vector)vector.elementAt(row)).elementAt(column); elsereturn null;}public String getColumnName(int column){return title[column]; //设置表格列名}public void setValueAt(Object value,int row,int column){//数据模型不可编辑,该方法设置为空}public Class getColumnClass(int c){return getValueAt(0,c).getClass(); //取得列所属对象类}public boolean isCellEditable(int row,int column){return false;//设置单元格不可编辑,为缺省实现}};table=new JTable(tm);table.setToolTipText("显示内容");table.setAutoResizeMode(table.AUTO_RESIZE_OFF);table.setCellSelectionEnabled(false);table.setShowHorizontalLines(true);table.setShowVerticalLines(true);scrollpane=new JScrollPane(table);}public void actionPerformed(ActionEvent e2){if(e2.getSource()==btn1){new tianxieshang();}if(e2.getSource()==btn2){new shanchushang();}if(e2.getSource()==btn3){new xiugaishang();}if(e2.getSource()==btn4){new chaxunshang();}if(e2.getSource()==btn5) //完成数据库区显示进货商所有信息 {try{int flag=0;rs=db.select("select * from tradesman");vector.removeAllElements();while(rs.next()){flag=1;Vector rec_vector=new Vector();rec_vector.addElement(rs.getString(1));rec_vector.addElement(rs.getString(2));rec_vector.addElement(rs.getString(3));rec_vector.addElement(rs.getString(4));vector.addElement(rec_vector);}tm.fireTableStructureChanged();if(flag==0){JOptionPane.showMessageDialog(null,"还没有任何进货商信息");}}catch(SQLException ee){ee.printStackTrace();}}}}}class Myframe3 extends JFrame //设置售货系统的界面{Plist list=new Plist();Psalesman salesman=new Psalesman();JTabbedPane pane;Myframe3(){super("售货管理系统");pane=new JTabbedPane(JTabbedPane.TOP);pane.add("收银清单信息",list);pane.add("售货员信息",salesman);this.add(pane);this.setSize(700,550);this.setLocation(100,100);this.setVisible(true);}class Plist extends JPanel implements ActionListener //添加收银清单的组件 {private database db=new database();ResultSet rs;JPanel p1=new JPanel();JPanel p2=new JPanel();JButton btn1,btn2,btn3,btn4,btn5;JLabel L=new JLabel("显示信息栏",JLabel.CENTER);//表格设置JTable table;JScrollPane scrollpane;Vector vector;AbstractTableModel tm;String title[]={"条形码","零售价","售货员编号","售出量"};Plist(){create();btn1=new JButton("填写新的清单");btn2=new JButton("删除清单");btn3=new JButton("修改清单");btn4=new JButton("收银清单金额");btn5=new JButton("全部清单信息");p1.setLayout(new GridLayout(1,4,20,20));p1.add(btn1); p1.add(btn2); p1.add(btn3); p1.add(btn4); p1.add(btn5);p2.setLayout(new BorderLayout());p2.add(L,BorderLayout.NORTH);p2.add(scrollpane,BorderLayout.CENTER);this.setLayout(new BorderLayout());this.add(p1,BorderLayout.NORTH);this.add(p2,BorderLayout.CENTER);this.setVisible(true);btn1.addActionListener(this);btn2.addActionListener(this);btn3.addActionListener(this);btn4.addActionListener(this);btn5.addActionListener(this);}void create(){vector = new Vector();tm = new AbstractTableModel(){public int getColumnCount(){return title.length; //取得表格列数}public int getRowCount(){return vector.size(); //取得表格行数}public Object getValueAt(int row,int column){if(!vector.isEmpty()) //取得单元格中的属性值return ((Vector)vector.elementAt(row)).elementAt(column); elsereturn null;}public String getColumnName(int column){return title[column]; //设置表格列名}public void setValueAt(Object value,int row,int column){//数据模型不可编辑,该方法设置为空}public Class getColumnClass(int c){return getValueAt(0,c).getClass(); //取得列所属对象类}public boolean isCellEditable(int row,int column){return false;//设置单元格不可编辑,为缺省实现}};table=new JTable(tm);table.setToolTipText("显示内容");table.setAutoResizeMode(table.AUTO_RESIZE_OFF);table.setCellSelectionEnabled(false);table.setShowHorizontalLines(true);table.setShowVerticalLines(true);scrollpane=new JScrollPane(table);}public void actionPerformed(ActionEvent e){if(e.getSource()==btn1){new addlist();}if(e.getSource()==btn2){new deletelist();}if(e.getSource()==btn3){new updatelist();}if(e.getSource()==btn4){new tongji();}if(e.getSource()==btn5) //完成查询所有收银清单信息的功能{int flag=0;try{rs=db.select("select * from list");vector.removeAllElements();while(rs.next()==true){flag=1;Vector rec_vector=new Vector();rec_vector.addElement(rs.getString(1));rec_vector.addElement(rs.getString(2));rec_vector.addElement(rs.getString(3));rec_vector.addElement(rs.getString(4));vector.addElement(rec_vector);}tm.fireTableStructureChanged();if(flag==0){JOptionPane.showMessageDialog(null,"系统还没有任何收银清单信息");}}catch(SQLException ee){ee.printStackTrace();}}}}class Psalesman extends JPanel implements ActionListener //售货员信息管理 {private database db=new database();ResultSet rs;JButton btn1,btn2,btn3,btn4,btn5;JLabel L;JPanel p1=new JPanel();JPanel p2=new JPanel();//表格设置JTable table;JScrollPane scrollpane;Vector vector;AbstractTableModel tm;String title[]={"售货员姓名","售货员编号","密码","所在机号"};Psalesman(){create();btn1=new JButton("增加售货员");btn2=new JButton("删除售货员");btn3=new JButton("查询售货员");btn4=new JButton("售货员业绩");btn5=new JButton("全部售货员信息");L=new JLabel("显示信息栏",JLabel.CENTER);p1.setLayout(new GridLayout(1,5,20,20));p1.add(btn1);p1.add(btn2);p1.add(btn3);p1.add(btn4);p1.add(btn5);p2.setLayout(new BorderLayout());p2.add(L,BorderLayout.NORTH);p2.add(scrollpane,BorderLayout.CENTER);this.setLayout(new BorderLayout());this.add(p1,BorderLayout.NORTH);this.add(p2,BorderLayout.CENTER);this.setVisible(true);btn1.addActionListener(this);btn2.addActionListener(this);btn3.addActionListener(this);btn4.addActionListener(this);btn5.addActionListener(this);}void create(){vector = new Vector();tm = new AbstractTableModel(){public int getColumnCount(){return title.length; //取得表格列数}public int getRowCount(){return vector.size(); //取得表格行数}public Object getValueAt(int row,int column){if(!vector.isEmpty()) //取得单元格中的属性值return ((Vector)vector.elementAt(row)).elementAt(column); elsereturn null;}public String getColumnName(int column){return title[column]; //设置表格列名}public void setValueAt(Object value,int row,int column){//数据模型不可编辑,该方法设置为空}public Class getColumnClass(int c){return getValueAt(0,c).getClass(); //取得列所属对象类}public boolean isCellEditable(int row,int column){return false;//设置单元格不可编辑,为缺省实现}};table=new JTable(tm);table.setToolTipText("显示内容");table.setAutoResizeMode(table.AUTO_RESIZE_OFF);table.setCellSelectionEnabled(false);table.setShowHorizontalLines(true);table.setShowVerticalLines(true);scrollpane=new JScrollPane(table);}public void actionPerformed(ActionEvent e){if(e.getSource()==btn1){new addsalesman();}if(e.getSource()==btn2){new deletesalesman();}if(e.getSource()==btn3){new selectsalesman();}if(e.getSource()==btn4){new shouchujine();}if(e.getSource()==btn5) //完成显示全部信息的功能{try{rs=db.select("select * from salesman");vector.removeAllElements();while(rs.next()==true){Vector rec_vector=new Vector();rec_vector.addElement(rs.getString(1));rec_vector.addElement(rs.getString(2));rec_vector.addElement(rs.getString(3));rec_vector.addElement(rs.getString(4));vector.addElement(rec_vector);}tm.fireTableStructureChanged();rs=db.select("select * from salesman");if(rs.next()==false){JOptionPane.showMessageDialog(null,"系统还没有任何售货员信息");}}catch(SQLException ee){ee.printStackTrace();}}}}}class shouchujine extends JFrame implements ActionListener {private database db=new database();ResultSet rs;JLabel L;JLabel L1,L2;JButton btn1,btn2;JTextField t1,t2;JPanel p=new JPanel();shouchujine(){L=new JLabel("售货员售出金额",JLabel.CENTER);L1=new JLabel("输入售货员编号",JLabel.CENTER);L2=new JLabel("共售出金额(元)",JLabel.CENTER);btn1=new JButton("确定");btn2=new JButton("关闭");t1=new JTextField(20);t2=new JTextField(20);p.setLayout(new GridLayout(2,3,30,30));p.add(L1); p.add(t1); p.add(btn1);p.add(L2); p.add(t2); p.add(btn2);this.setLayout(new BorderLayout());this.add(L,BorderLayout.NORTH);this.add(p,BorderLayout.CENTER);this.setLocation(200,200);this.setSize(330,120);this.setVisible(true);btn1.addActionListener(this);btn2.addActionListener(this);}public void actionPerformed(ActionEvent e){if(e.getSource()==btn2){this.setVisible(false);}if(e.getSource()==btn1){if(t1.getText().equals("")){JOptionPane.showMessageDialog(null,"请输入要查看的售货员编号");}else{t2.setText("");String sno2=t1.getText();try{rs=db.select("select * from list where sno='"+sno2+"'");if(rs.next()==true){ResultSet rr=db.select("select SUM(gcost) from list where sno='"+sno2+"'"); if(rr.next()==true){t2.setText(rs.getString(1));}}else{JOptionPane.showMessageDialog(null,"此售货员并没有业绩");}}catch(SQLException ee){ee.printStackTrace();}}}}}class Myframe4 extends JFrame //设置商品信息系统的界面{Padd add=new Padd();Pupdate update=new Pupdate();Pselect select=new Pselect();JTabbedPane pane;Myframe4(){super("商品信息管理系统");pane=new JTabbedPane(JTabbedPane.TOP);pane.add("添加商品信息",add);pane.add("修改商品信息",update);pane.add("查找商品信息",select);this.add(pane);this.setSize(700,550);this.setLocation(100,100);this.setVisible(true);}class Padd extends JPanel implements ActionListener{private database db=new database();ResultSet rs;JPanel p1=new JPanel();JPanel p2=new JPanel();JPanel p3=new JPanel();JPanel p4=new JPanel();JLabel L;JLabel L1,L2,L3,L4,L5,L6;JButton btn1,btn2;JTextField t1,t2,t3,t4,t5,t6;//表格设置JTable table;JScrollPane scrollpane;Vector vector;AbstractTableModel tm;String title[]={"商品名","条形码","商品类型","零售价","所在仓库号","商品数量"};Padd(){create();L=new JLabel("显示结果",JLabel.CENTER);L1=new JLabel("商品名",JLabel.CENTER);L2=new JLabel("条形码",JLabel.CENTER);L3=new JLabel("商品类型",JLabel.CENTER);L4=new JLabel("零售价",JLabel.CENTER);L5=new JLabel("所存仓库号",JLabel.CENTER);L6=new JLabel("商品数量",JLabel.CENTER);t1=new JTextField(10);t2=new JTextField(10);t3=new JTextField(10);t4=new JTextField(10);t5=new JTextField(10);t6=new JTextField(10);btn1=new JButton("提交");btn2=new JButton("显示所有商品信息");p1.setLayout(new GridLayout(6,2));p1.add(L1); p1.add(t1);p1.add(L2); p1.add(t2);p1.add(L3); p1.add(t3);p1.add(L4); p1.add(t4);p1.add(L5); p1.add(t5);p1.add(L6); p1.add(t6);p2.setLayout(new FlowLayout());p2.add(btn1);p2.add(btn2);p3.setLayout(new BorderLayout());p3.add(p1,BorderLayout.CENTER);p3.add(p2,BorderLayout.SOUTH);p4.setLayout(new BorderLayout());p4.add(L,BorderLayout.NORTH);p4.add(scrollpane,BorderLayout.CENTER);this.setLayout(new BorderLayout());this.add(p3,BorderLayout.NORTH);this.add(p4,BorderLayout.CENTER);this.setVisible(true);btn1.addActionListener(this);btn2.addActionListener(this);}void create(){vector = new Vector();tm = new AbstractTableModel(){public int getColumnCount(){return title.length; //取得表格列数}public int getRowCount(){return vector.size(); //取得表格行数}public Object getValueAt(int row,int column){if(!vector.isEmpty()) //取得单元格中的属性值return ((Vector)vector.elementAt(row)).elementAt(column); elsereturn null;}public String getColumnName(int column){return title[column]; //设置表格列名}public void setValueAt(Object value,int row,int column){//数据模型不可编辑,该方法设置为空}public Class getColumnClass(int c){return getValueAt(0,c).getClass(); //取得列所属对象类}public boolean isCellEditable(int row,int column){return false;//设置单元格不可编辑,为缺省实现}};table=new JTable(tm);table.setToolTipText("显示内容");table.setAutoResizeMode(table.AUTO_RESIZE_OFF);table.setCellSelectionEnabled(false);table.setShowHorizontalLines(true);table.setShowVerticalLines(true);scrollpane=new JScrollPane(table);}public void actionPerformed(ActionEvent e5){if(e5.getSource()==btn1){try{String gname=t1.getText();String gno=t2.getText();String gtype=t3.getText();String gcost=t4.getText();String gwarehouse = t5.getText();String gnu = t6.getText();if(t1.getText().equals("")||t2.getText().equals("")||t3.getText().equals("")||t4.getText().equal s("")||t5.getText().equals("")||t6.getText().equals("")){JOptionPane.showMessageDialog(null,"请将所有信息填写完整!");t1.setText("");t2.setText("");t3.setText("");t4.setText("");t5.setText("");t6.setText("");}else{rs=db.select("select * from goods where gno='"+gno+"'");if(rs.next()==false){db.update("insert into goods values('"+gname+"','"+gno+"','"+gtype+"','"+gcost+"','"+gwarehouse+"','"+gnu+"')");JOptionPane.showMessageDialog(null,"插入成功!");t1.setText("");t2.setText("");t3.setText("");t4.setText("");t5.setText("");t6.setText("");}else{JOptionPane.showMessageDialog(null,"已经有此售货员!");}}}catch(SQLException ee){ee.printStackTrace();}}if(e5.getSource()==btn2) //完成显示所有商品信息的功能{try{rs=db.select("select * from goods");if(rs.next()==false){JOptionPane.showMessageDialog(null,"系统还没有任何商品信息");}rs=db.select("select * from goods");vector.removeAllElements();while(rs.next()){Vector rec_vector=new Vector();rec_vector.addElement(rs.getString(1));rec_vector.addElement(rs.getString(2));rec_vector.addElement(rs.getString(3));rec_vector.addElement(rs.getString(4));rec_vector.addElement(rs.getString(5));rec_vector.addElement(rs.getString(6));vector.addElement(rec_vector);}tm.fireTableStructureChanged();}catch(SQLException ee){ee.printStackTrace();}}}}class Pselect extends JPanel implements ActionListener{private database db=new database();ResultSet rs;JPanel p1=new JPanel();JPanel p2=new JPanel();JPanel p3=new JPanel();JPanel p4=new JPanel();JPanel p5=new JPanel();JLabel L;JLabel L1,L2,L4;JTextField t1,t2,t4;JLabel L5=new JLabel("显示信息栏",JLabel.CENTER);JButton btn1=new JButton("提交");JButton btn2=new JButton("显示全部信息");JButton btn3=new JButton("商品数量及商品金额");//表格设置JTable table;JScrollPane scrollpane;Vector vector;AbstractTableModel tm;String title[]={"商品名","条形码","商品类型","零售价","所在仓库号","商品数量"};Pselect(){create();L=new JLabel("查找商品信息",JLabel.CENTER);L.setFont(new Font("TimesRoman",Font.BOLD,16));L1=new JLabel("商品名",JLabel.CENTER);L2=new JLabel("条形码",JLabel.CENTER);L4=new JLabel("商品类型",JLabel.CENTER);t1=new JTextField(10);t2=new JTextField(10);t4=new JTextField(10);p1.setLayout(new GridLayout(4,2));p1.add(L1); p1.add(t1);p1.add(L2); p1.add(t2);p1.add(L4); p1.add(t4);p2.setLayout(new FlowLayout());p2.add(btn1); p2.add(btn2); p2.add(btn3);p3.setLayout(new BorderLayout());p3.add(L,BorderLayout.NORTH);p3.add(p1,BorderLayout.CENTER);p3.add(p2,BorderLayout.SOUTH);p5.setLayout(new BorderLayout());p5.add(L5,BorderLayout.NORTH);p5.add(scrollpane,BorderLayout.CENTER);this.setLayout(new BorderLayout());this.add(p3,BorderLayout.NORTH);this.add(p5,BorderLayout.CENTER);this.setVisible(true);btn1.addActionListener(this);btn2.addActionListener(this);btn3.addActionListener(this);}void create(){vector = new Vector();tm = new AbstractTableModel(){public int getColumnCount(){return title.length; //取得表格列数}public int getRowCount(){return vector.size(); //取得表格行数}public Object getValueAt(int row,int column){if(!vector.isEmpty()) //取得单元格中的属性值return ((Vector)vector.elementAt(row)).elementAt(column);elsereturn null;}public String getColumnName(int column){return title[column]; //设置表格列名}public void setValueAt(Object value,int row,int column){//数据模型不可编辑,该方法设置为空}public Class getColumnClass(int c){return getValueAt(0,c).getClass(); //取得列所属对象类}public boolean isCellEditable(int row,int column){return false;//设置单元格不可编辑,为缺省实现}};table=new JTable(tm);table.setToolTipText("显示内容");table.setAutoResizeMode(table.AUTO_RESIZE_OFF);table.setCellSelectionEnabled(false);table.setShowHorizontalLines(true);table.setShowVerticalLines(true);scrollpane=new JScrollPane(table);}public void actionPerformed(ActionEvent e){if(e.getSource()==btn1) //完成查询商品信息中的条形码的功能 {String gname,gno,gtype,gcost,gwarehouse,gnu;if(t2.getText().equals("")&&t4.getText().equals("")){int flag=0;try{gname=t1.getText();rs=db.select("select * from goods where gname='"+gname+"'");vector.removeAllElements();while(rs.next()==true){flag=1;Vector rec_vector=new Vector();rec_vector.addElement(rs.getString(1));rec_vector.addElement(rs.getString(2));rec_vector.addElement(rs.getString(3));rec_vector.addElement(rs.getString(4));rec_vector.addElement(rs.getString(5));rec_vector.addElement(rs.getString(6));vector.addElement(rec_vector);}tm.fireTableStructureChanged();if(flag==0){JOptionPane.showMessageDialog(null,"没有这个商品!");}}catch(SQLException ee){ee.printStackTrace();}。

相关主题