java商品管理系统4_第1页
java商品管理系统4_第2页
java商品管理系统4_第3页
java商品管理系统4_第4页
java商品管理系统4_第5页
已阅读5页,还剩29页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、.专业整理.代表各的主页面package com.gui;import java.awt.*;import javax.swi ng.*;import java.awt.eve nt.*;import java.io.*;import java .ni o.cha nn els.ClosedSelectorExcepti on;import java.sql.*;import javax.swi ng.JFileChooser;import javax.swi ng.plaf.ScrollBarUI;import javax.swi ng.table.DefauItT ableColu mnM

2、 odel;import javax.sw in g.table.DefauItT ableModel;import com.DateSystem.Good_data;import com.DateSystem.Goods;import com.DateSystem.Userdate;import java.util.List;public class Main exte nds JFrame impleme nts Actio nListe ner,Adjustme ntListe ner* param args*/主窗体组件Men uBar men uBar;Menu menu _xit

3、on g,me nu _gua nli,me nu_gon gju,me nu _Help;Men ultem item_up_password5 item_reLa ndin g, item_exit;Men ultem item_ in put, item_fi nd, item_delete;Men ultem itemjisua nqi, itemjishibe n, item_beiji ng;Men ultem item_LookHelp, item_About;/录入界面要用的组件JPa nel jp_bt njp_mai nJ p_tablejp_text;JLabel Ibl

4、jd, lbl_ name, lbl_address5 lbl_ in _price, lbl_out_price, lbl_kuc un, IblJ in huo, lbl_chuhuo;TextFieldtext_id5text_ name,text_address,text_i n_price,text_out_price,text_kuc un ,textj in huo5text_ch uhuo;JButt on submit,reset5delete;JScrollPa ne jsp;JTable table;DefauItT ableModel model;CardLayout

5、c=new CardLayout();JPa nel card;查找页面要用的组件JPa nel jp1,jp2,jp3;JPa nel jp2_ma in;J Butt on fin d_id5fi nd_n ame,fi nd_delete,fi nd_all;JTextField text_fi nd;JScrollPa ne jsp_fi nd;JTable table_fi nd;DefauItT ableModel model_find;背景更改要用的组件int r =255,g=255,b=255;TextField tfr,tfg,tfb;Scrollbar sbr,sbg,s

6、bb;Panel display;JPa nel jp3_ma in;public Mai n () super ("主窗口 ”);men uBar =new Men uBar ();menu_gongju=new Men u (“ 工具”);.学习帮手.menu_guanli=new Menu ("管理”);menu_Help=new Menu ("帮助");menu_xitong=new Menu ("系统");item_About= new Menuitem C 关于“);item_beijing=new Menuitem C背

7、景设置”);item_LookHelp=new Menuitem (" 查看帮助item_up_password=new Menuitem (" 修改密码”);item_reLanding=new Menuitem (“ 重新登录”);item exit= new Menuitem C退出系统”);itemjishiben=new MenuitemC记事本“);itemjisuanqi=new Menuitem(“计算器”);item find=new Menuitem(”查找“);item_ in put=new Men ultem C 录入”);item_delete=

8、new Menuitem ("删除“);注册监听item_About.addAct ion Liste ner(this);item_beiji ng.add Act ion Liste ner(this);item_LookHelp.addActio nListe ner(this); item_up_password.addAct ion Liste ner(this);item_reLa ndin g.addActi on Liste ner(this); item_exit.addActio nListe ner(this);itemjishibe n. addActi on

9、 Liste ner(this); itemjisua nqi.addActi on Liste ner(this);nd.addAct ion Liste ner(this);item_ in put.addAct ion Liste ner(this);item_delete.addActio nListe ner(this);menu _xit on g. add (i te m_u p_pass wo rd);menu _xit on g.add(item_reLa ndin g);menu _xit on g.add(item_exit);menu _gua nli.add(item

10、_i nput);menu _gua nli.add(item_fi nd);/me nu _gua nli.add(item_delete);menu_gon gju.add(itemjisua nqi); menu_gon gju.add(itemjishibe n);menu_gon gju.add(item_beiji ng);menu _Help.add(item_About);menu _Help.add(item_LookHelp);men uBar.add(me nu _xit on g);men uBar.add(me nu _gua nli);men uBar.add(me

11、 nu_gon gju);men uBar.add(me nu_ Help);setMe nuBar(me nuBar);setResizable(false);in itCompo nen ts(); 调用方法初始化界面Fin d();cha nge_color();/查找功能的布局以及组建/this.setLayout (new CardLayout();card=new JPa nel();card.setLayout(c);card.add(n1", jp_ma in);card.add("2H, jp2_mai n);card.add(M3", jp3_

12、mai n);/this.getCo nten tPa ne().add("Ce nter", jp_ma in);this.add(card);this.setSize(1000, 500);this.setLocati on RelativeTo (n ull);this.setVisible(true);this.setDefaultCloseOperatio n(JFrame.EXIT_ON_CLOSE);)录入界面初始化private void in itComp onen ts() /构造面板System.out.pri ntln ("pass&quo

13、t;);lbljd=new JLabel("商品编号 w,JLabeLCENTER);lbl_name=new JLabel("商品名称 n,JLabeLCENTER);lbl_address=new JLabel("商品产地 JLabel.CENTER); lbl_in_price=new JLabel("进 价 M,JLabeLCENTER); lbl_out_price=new JLabel。售价 H,JLabeLCENTER); Ibl J nhuo=new JLabel("进货量 n,JLabel.CENTER); lbl_chuhu

14、o=new JLabel(" 销售 量 n,JLabeLCENTER);lbl_kucun=new JLabel(M 库存量 n,JLabel.CENTER); text_id=new TextField();text_ name = new TextField();text_address=new TextField();text_ in _price=new TextField();text_out_price=new TextField();textj in huo=new T extField();text_chuhuo=new TextField();text_kuc un

15、=new TextField();jp_table=new JPa nel( new BorderLayout();jp_text =new JPa nel( new GridLayout(2,8);jp_text.add(lbl_id);jp_text.add(lbl_ name);jp_text.add(lbl_address);jp_text.add(lbl_ in _price);jp_text.add(lbl_out_price);jp_text.add(lblj in huo);jp_text.add(lbl_chuhuo);jp_text.add(lbl_kuc un);jp_t

16、ext.add(text_id);jp_text.add(text_ name);jp_text.add(text_address);jp_text.add(text_i n_price);jp_text.add(text_out_price);jp_text.add(textj in huo);jp_t©xt.add(text_chuhuo);jp_text.add(text_kuc un);model = new DefauItT ableModel( new Object , new String口 “商品编号”商品名称7商品产地,”进价售价7库存量 ,“进货量“,“出货量;t

17、able =new JTable(model);jsp=new JScrollPa ne(table);submit =new JButton(" 录入商品reset= new JButton(n 重置信息”);delete=new JButtonf删除所选商品1submit.addAct ion Liste ner(this);reset.addAct ion Liste ner(this);delete.addAct ion Liste ner(this);jp_bt n=n ew JPa nel(new GridLayout(1,3);jp_bt n.add(submit);j

18、p_bt n.add(delete);jp_bt n.add(reset);jp_table.add("Ce nterH,jp_text); jp_table.add(,South,jp_bt n);jp_ma in=new JPa nel( new BorderLayout(10,10);jp_mai n.add(,fCe nterMJsp);jp_mai n. add("North"Jp_table);System.out.pri ntln (“pass”);)/查找面板初始化面板private void Fin d() jp1 = new JPa nel(n

19、ew GridLayout(1 J);jp2=n ew JPa nel(new GridLayout(1,4);jp3=new JPa nel( new BorderLayout();fin d_id =n ew JButto n("根据商品编号查询”);find_n ame=new JButt on (" 根据商品名称查询”);find_all=new J Button(n查询所有信息”);find_delete=new JButton(n 删除所选信息”);text_fi nd=new JTextField();jsp_fi nd=new JScrollPa ne();

20、table_find=new JT able();model _fin d=new DefauItT ableModel();model_fi nd = new DefaultTableModel( new Object , new String "商品编号/商品名称7商品产地“,”进价售价7库存量”,进货量”,“出货量");table_fi nd =new JTable(model_fi nd);jsp_fi nd=new JScrollPa ne(table_fi nd);fin d id.addAct ion Liste ner(this);find_n ame.ad

21、dActi on Liste ner(this);fin d all.addAct ion Liste ner(this);fin d_delete.addActi on Liste ner(this);jp1 .add(text_fi nd);jp2.add(fi nd J d);jp2.add(fi nd_n ame);jp2.add(fi nd_all);jp2.add(fi nd_delete);jp3.add("North”,jp1);jp3.add("Ce ntern,jp2);jp2_mai n=n ew JPan el( new BorderLayout(1

22、0,10); jp2_ma in. add("Ce nter",jsp_fi nd);jp2_mai n. add(,'North,Jp3);)背景更改private void cha nge_color() jp3_ma in=new JPa nel();display =new Pan el();display.setBackgrou nd(Color.WHITE);Panel pcolor =new Pan el();pcolor.setLayout (new BorderLayout();Panel pw=new Pan el();pw.setLayout

23、(new GridLayout(3,2,0,0);jp3_ma in. setLayout (new BorderLayout();tfr= new TextField("255");tfg=new TextField("255");tfb=new TextField(n255H);tfr.setEditable(false);tfg.setEditable(false);tfb.setEditable(false);sbr= new Scrollbar(Scrollbar.HORIZONTAL,255,0,0,255);sbg=new Scrollba

24、r(Scrollbar.HORIZONTAL,255,0,0,255);sbb=new Scrollbar(Scrollbar.HORIZONTAL,255,0,0,255);sbr.setName(HSBRH);sbg.setName("SBG");sbb.setNamef'SBB*');sbr.setBackgro un d(Color.red);sbg.setBackgro un d(Color.gree n);sbb.setBackgro un d(Color.blue);sbr.addAdjustme ntListe ner(this);sbg.a

25、ddAdjustme ntListe ner(this);sbb.addAdjustme ntListe ner(this);pw.add( new Label(“红色”);pw.add(tfr);pw.add( new Label(“绿色”);pw.add(tfg);pw.add( new Label(“蓝色");pw.add(tfb);Panel pc= new Pan el();pc.setLayout (new GridLayout(3, 1,0, 0);pc.add(sbr);pc.add(sbg);pc.add(sbb);pcolor.add(pw5BorderLayou

26、t.WEST);pcolor.add(pc,BorderLayout.CENTER);jp3_mai n.add(display,BorderLayout.CENTER);jp3_ma in. add(pcolor5BorderLayout.SOUTH); )查看帮助文档,调用本地的程序,查看帮助文档public void useCMDComma nd() throws lOExceptio nRun time.getR un time().exec( newStrin g"cmd.exe',JVc'*,保定商场商品管理系统项目帮助.doc");)主函数pu

27、blic static void main( Stri ng args) / TODO Auto-ge nerated method stubjava.awt.Eve ntQueue.i nvokeLater( new Runn able() public void run() new Ma in( ).setVisible(true); ) );)监听方法public void action Performed(Acti onEvent e) /得到事件源String btStri ng=e.getAct ion Comma nd();录入功能if (btString.equals(n录入商

28、品")追加到最后一行if(!text_id.getText().equals(f,H)&&!text_address.getText().equals("")&&!text_out_price.getText().equals(n")&&!text_ name.getText().equals(,H,)&& !text_in_price.getText().equals("")&&Itextji nhuo.getText().equals("&q

29、uot;)&& !text_chuhuo.getText().equals(,H,) && !text_kucu n.getText().equals(,f,t) 获取文本框信息int idStri ng=l nteger.parsel nt(text_id.getText();Stri ng ids=text_id.getText();Stri ng n ameStri ng=text_ name.getText();String addresStri ng=text_address.getText();double in_priceStri ng=Doubl

30、e.parseDouble(text_in_price.getText();double out_priceStri ng=Double.parseDouble(text_out_price.getText();int jin huoStri ng=ln teger.parse In t(textj in huo.getT ext();int chuhuoStri ng=ln teger.parse In t(text_chuhuo.getText();int kuc un=ln teger.parse In t(text_kuc un. getText();if (in _priceStri

31、 ng<=0) JOptionPane.showMessageDialog(this,M 亲,进价要大于零哦! *');else if (in _priceStri ng>=out_priceStri ng) JOptionPane.showMessageDialog(this, “亲要有盈利的,销售价格要大于进价! ”);else System.out.print(n 录入商品”);if (idStri ng!=O&&!n ameStri ng.equals(巧&& laddresStri ng.equals。”')&&am

32、p; in_priceStri ng!=O && out_priceStri ng!=O &&jin huoStri ng!=0 && chuhuoStri ng!=0 && kucu n!=0) 对数据库的操作String sql="i nsert into result values("'+ids +H7" +n ameStri ng+”'J'+addresStri ng+,",n+in_priceStri ng+”J+out_priceStri ng+"

33、;J+jin huoStri ng+”J+chuhuoStri ng+”,”+kucun+);Userdate userdate=new Userdate();boolea n flag=userdate.add_goods(sql);if (flag) /对表格的操作model.i nsertRow(model.getRowCou nt(),newObjectids,n ameStri ng,addresStri ng,i n_priceStri ng,out_priceStri ngji nhuoStri ng,chuhuoStri ng,kuc un );else JOptio nPan

34、 e.showMessageDialog(this," 商品编号重复!)else JOptio nPa ne.showMessageDialog (this, ”请输入商品详细 信息! “);)else JOptionPane.showMessageDialog (this," 请输入商品的详细信息!”);)删除功能else if (btString.equals ("删除所选商品")获取要删除的行,没有选择是-1int row=table.getSelectedRow ();System.out.print ("删除商品操作”);System

35、.out.pri nt (row);if (row=-1) JOptionPane.showMessageDialog (this,"请选择要删除商品的商品名!”);else /System.out.pri nt(row);/数据库删除商品操作0);/int sha ngpin Jd= In teger.parsel nt(Stri ng) modeLgetValueAt(row,String sha ngpin _id=(Stri ng) model.getValueAt(row, 0);System.out.pri nt(row);Stri ng sql=ndelete from

36、 result where id=H,+shangpin_id+n,f,;Userdate userdate=new Userdate();boolea n flag=userdate.add_goods(sql);if (flag) model.removeRow(row);)重置功能else 计(btString.equals("重置信息")text_id.setText(,H);text_ name.setText("");text_address.setText('n,); text_in_price.setText('n,);

37、text_out_price.setText(',n);text Ji nhuo.setText("");text_chuhuo.setText("H);text_kucu n.setText(,n');else if(btString.equals(M修改密码”)UpData data=new UpData(); data.setVisible(true);else if(btString.equals(M 计算器”)Calculator calculator = new Calculatoro ; calculator.setSize(250,

38、350);calculator.setLocati on RelativeTo (nu II); calculator.setVisible(true);calculator.setResizable(false);else if(btString.equals("退出系统")System.exit(O);else if (btString.equals(M 记事本”)NotePad notePad=n ew NotePad();no tePad.setVisible(true);else if(btString.equals(n 查看帮助”)/System.out.pri

39、 ntl n("help_pss");t»useCMDComma nd();System.out.pri ntl n(Hhelp_pssH); catch (lOException e1) / TODO Auto-ge ne rated catch blockel.pri ntStackTrace();)else if(btString.equals(n 关于")About about =new About(); about.setVisible(true);else if(btSting.equals("重新登录") System.

40、out.print(n 重新登录");Landing landing = newLandin g(); landin g.setVisible(true);this.dispose();else if(btStri ng.equals。查找”)c.show(card,"2");else if(btStri ng.equals,'录入")c.show(card;T);else if(btStri ng.equals。删除")c.show(card,"2");JOptionPane.showMessageDialog(t

41、his,"请先查找所要删除的商品信息! ”);else if(btString.equals(n 背景设置")c.show(card;'3H);查找功能else if(btStri ng.equalsf 根据商品编号查询")if (text_fi nd.getText().equals("") JOptionPane.showMessageDialog(this,M 查询信息为空!” else int id =1 nteger.parsel nt(text_fi nd.getText().trim();Stri ng id =text_

42、fi nd.getText().trim();Good_data data=new Good_data();Goods goods =data.fi ndStude ntByld(id);/Stri ng id_s=ln teger.toStri ng(id);/获取文本框信息 int idStri ng=goods.getld();/Stri ng ids=ln teger.toStri ng(goods.getld();String idStri ng=goods.getld();String n ameStri ng=goods.getName();String addresStri n

43、g=goods.getAddress();double in _priceStri ng=goods.getl n_price();double out_priceStri ng=goods.getOut_price();int jin huoStri ng=goods.getJ in huo();int chuhuoStri ng=goods.getChuhuo();int kuc un=goods.getKuc un();/判断用户所输入的商品编号数据库中是否有if (idStri ng=null) JOptionPane.showMessageDialog(this,"对不起,

44、小编没有从数据库中找到商品编号为:"+id+”的信息! ”);else /对表格的操作model_fi nd.i nsertRow(model_fi nd.getRowCo un t(), new ObjectidStri ng,n ameStri ng,addresStri ngj n_priceStri ng,out_priceStri ngji nhuoStri ng,chuhuoStri ng,kuc un );)else if(btStri ng.equalsf 根据商品名称查询”)Stri ng n ame =text_fi nd.getText().trim();Goo

45、d_data data=new Good_data();Stri ng sql=Mselect * from result where nam like '%"+name+"%"4;List<Goods> datalist=data.fi ndGoods(sql);获取文本框信息if (n ame.equals,"')JOptionPane.showMessageDialog(this,"查询信息为空! ”);else if (datalist.size()<=0) JOptionPane.showMessag

46、eDialog(this," 对不起,小编没有从数据库中找到商品名为:”+name+”的信息!for(Goods d:datalist) 遍历数据,将查询所得到的数据逐一赋值到表中 int idStri ng=d.getld();Stri ng idStri ng=d.getld();Stri ng n ameStri ng=d.getName();String addresStri ng=d.getAddress();double in _priceStri ng=d.getl n_price();double out_priceStri ng=d.getOut_price();i

47、nt jin huoStri ng=d.getJ in huo();int chuhuoStri ng=d.getChuhuo();int kuc un=d.getKuc un();/对表格的操作model_fi nd.i nsertRow(model_fi nd.getRowCo un t(), new ObjectidStri ng,n ameStri ng,addresStri ngj n_priceStri ng,out_priceStri ngji nhuoStri ng,chuhuoStri ng,kuc un );)else if(btString.equalsC 删除所选信息")获取要删除的行,没有选择是-1int row=table_fi nd.getSelectedRow();System.out.print("删除商品操作”);System.out.pri nt(row);if (row=-1) JOptionPane.showMessageDialog(this,H 请选择要删除商品! ”);else /System.out.pri nt(row);/数据库删除商品操作&q

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论