java商品管理系統(tǒng)4_第1頁
java商品管理系統(tǒng)4_第2頁
java商品管理系統(tǒng)4_第3頁
已閱讀5頁,還剩11頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

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.DefaultTableColu mnM odel;

2、import javax.sw in g.table.DefaultTableModel;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 on g,m

3、e nu _gua nli,me nu_gon gju,me nu _Help;Men ultem item_up_password, item_reLa ndin g, item_exit;Men ultem item_ in put, item_fi nd, item_delete;Men ultem item_jisua nqi, item_jishibe n, item_beiji ng;Men ultem item_LookHelp, item_About;/錄入界面要用的組件lbl_kuc un,JPa nel jp_bt n,jp_mai n,j p_table,jp_text;

4、JLabel lbl_id,lbl_name, lbl_address,lbl_in_price,lbl_out_price,lbl_jin huo, lbl_chuhuo;TextFieldtext_id,text_ name,text_address,text_i n_price,text_out_price,text_kuc un ,text_j in huo,text_chuhuo;JButt on submit,reset,delete;JScrollPa ne jsp;JTable table;DefaultTableModel model;CardLayout c=new Car

5、dLayout();JPa nel card;/查找頁面要用的組件JPa nel jp1,jp2,jp3;JPa nel jp2_ma in;JButt on fin d_id,fi nd_n ame,fi nd_delete,fi nd_all; JTextField text_fi nd;JScrollPa ne jsp_fi nd; JTable table_fi nd; DefaultTableModel model_fi nd;/背景更改要用的組件int r =255,g=255,b=255;TextField tfr,tfg,tfb; Scrollbar sbr,sbg,sbb;

6、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(” 系統(tǒng)");item_About= new Menultem(” 關(guān)于"); item_beijing=new Menulte

7、m(”背景設(shè)置");item_LookHelp=new Menultem(” 查看幫助"); item_up_password=new Menultem(” 修改密碼"); item_reLanding=new Menultem(”重新登錄");item_exit= new Menultem(”退出系統(tǒng)");item_jishiben=new Menultem(”記事本");item_jisuanqi=new Menultem(”計(jì)算器");item_find=new Menultem(”查找");item_ in

8、 put=new Men ultem(”錄入");item_delete=new Men ultem(”刪除");/注冊監(jiān)聽item_About.addAct ion Liste ner(this); item_beiji ng.addAct 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.addAct

9、io nListe ner(this); item_jishibe n. addActi on Liste ner(this); item_jisua nqi.addActi on Liste ner(this); item_fi 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(item_up_password); menu _xit on g.add(item_reLa ndin g)

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

11、nu _xit on g); men uBar.add(me nu _gua nli); men uBar.add(me nu_gon gju); men uBar.add(me nu_ Help);setMe nuBar(me nuBar);setResizable(false);in itCompo nen ts();/調(diào)用方法初始化界面Fin d();cha nge_color();/查找功能的布局以及組建/this.setLayout (new CardLayout();card=new JPa nel();card.setLayout(c);card.add("1"

12、;, jp_ma in);card.add("2", jp2_mai n);card.add("3", jp3_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);構(gòu)造面板

13、號(hào) ”,JLabel.CENTER);商品名稱 ”,JLabel.CENTER);商品產(chǎn)地 ”,JLabel.CENTER)進(jìn)價(jià) ”,JLabel.CENTER);售價(jià) ”,JLabel.CENTER);進(jìn)貨量 ”,JLabel.CENTER);銷售量 ”,JLabel.CENTER);庫存量 ”,JLabel.CENTER);/錄入界面初始化商品編,private void in itComp onen ts() / System.out.pri ntln ("pass"); lbl_id=new JLabel(" lbl_ name=new JLabel(&q

14、uot; lbl_address=new JLabel(" lbl_ in _price=new JLabel(" lbl_out_price=new JLabel(" lbl_j in huo=new JLabel(" lbl_chuhuo=new JLabel(" lbl_kucu n=new JLabel("text_id=new TextField(); text_ name = new TextField(); text_address=new TextField(); text_ in _price=new TextFie

15、ld(); text_out_price=new TextField(); text_j in huo=new TextField(); text_chuhuo=new TextField(); text_kuc un=new TextField();jp_table=new JPa nel( new BorderLayout(); jp_text =n ew 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 _

16、price);jp_text.add(lbl_out_price);jp_text.add(lbl_j in huo);jp_text.add(lbl_chuhuo);jp_text.add(lbl_kuc un);jp_text.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(text_j in huo);jp_text.add(text_chuhuo);jp_text.add(t

17、ext_kuc un);model = new DefaultTableModel( new Object , new String "商品編號(hào)","商品名稱","商品產(chǎn)地”,”進(jìn)價(jià)","售價(jià)","庫存量","進(jìn)貨量","出貨量” );table =new JTable(model);jsp=new JScrollPa ne(table);submit =new JButton(”錄入商品”);reset= new JButton(”重置信息”);delete=ne

18、w JButton(”刪除所選商品”);submit.addAct ion Liste ner(this);reset.addAct ion Liste ner(this);delete.addAct ion Liste ner(this);jp_bt n=new JPa nel(new GridLayout(1,3);jp_bt n.add(submit);jp_bt n.add(delete);jp_bt n.add(reset);jp_table.add("Ce nter",jp_text);jp_table.add("South",jp_bt n

19、);jp_ma in=new JPa nel( new BorderLayout(10,10);jp_mai n.add("Ce nter",jsp);jp_mai n. add("North",jp_table);System.out.pri ntln ("pass");/查找面板初始化面板private void Fin d() jp1= new JPa nel(new GridLayout(1,1); jp2=n ew JPa nel(new GridLayout(1,4); jp3=new JPa nel( new Borde

20、rLayout();fin d_id =new JButto n(”根據(jù)商品編號(hào)查詢 ”);find_n ame=new JButt on (”根據(jù)商品名稱查詢”);find_all=new JButton(”查詢所有信息”);find_delete=new JButton(”刪除所選信息”);text_fi nd=new JTextField();jsp_fi nd=new JScrollPa ne();table_fi nd=new JTable(); model_fi nd=new DefaultTableModel();model_fi nd = new DefaultTableMod

21、el( new Object , new String "商品編號(hào)","商品名稱","商品產(chǎn)地”,"進(jìn)價(jià)","售價(jià)","庫存量","進(jìn)貨量","出貨量");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.addActi on Liste ner(th

22、is);fin d_all.addAct ion Liste ner(this);fin d_delete.addActi on Liste ner(this);jp1.add(text_fi nd);jp2.add(fi ndd);jp2.add(fi nd_n ame);jp2.add(fi nd_all);jp2.add(fi nd_delete);jp3.add("North",jp1);jp3.add("Ce nter",jp2);jp2_mai n=new JPan el( new BorderLayout(10,10); jp2_ma in

23、. 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 (new GridL

24、ayout(3,2,0,0);jp3_ma in. setLayout (new BorderLayout();tfr= new TextField("255");tfg=new TextField("255");tfb=new TextField("255");tfr.setEditable(false);tfg.setEditable(false);tfb.setEditable(false);sbr= new Scrollbar(Scrollbar.HORIZONTAL,255,0,0,255); sbg=new Scrollb

25、ar(Scrollbar.HORIZONTAL,255,0,0,255); sbb=new Scrollbar(Scrollbar.HORIZONTAL,255,0,0,255);sbr.setName("SBR"); sbg.setName("SBG"); sbb.setName("SBB");sbr.setBackgro un d(Color.red); sbg.setBackgro un d(Color.gree n);sbb.setBackgro un d(Color.blue);sbr.addAdjustme ntListe

26、 ner(this);sbg.addAdjustme 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(" 藍(lán)色");pw.add(tfb);Panel pc= new Pan el();pc.setLayout (new GridLayout(3, 1, 0, 0);pc.add(sbr);pc.add(

27、sbg);pc.add(sbb);pcolor.add(pw,BorderLayout.WEST);pcolor.add(pc,BorderLayout.CENTER);jp3_mai n.add(display,BorderLayout.CENTER);jp3_ma in. add(pcolor,BorderLayout.SOUTH);/查看幫助文檔,調(diào)用本地的程序,查看幫助文檔public void useCMDComma nd() throws IOExceptio n"/c",Run time.getR un time().exec( newStrin g"

28、;cmd.exe",保定商場商品管理系統(tǒng)項(xiàng)目幫助.doc");/主函數(shù)public static void main( Stri ng args) / TODO Auto-ge nerated method stubjava.awt.Eve ntQueue.i nvokeLater( new Runn able() public void run() new Mai n( ).setVisible(true););/監(jiān)聽方法public void action Performed(Acti onEvent e) /得到事件源String btStri ng=e.getAct

29、 ion Comma nd();/錄入功能if (btString.equals(”錄入商品")/追加到最后一行if(!text_id.getText().equals("") && !text_name.getText().equals("")&& !text_address.getText().equals("")&& !text_in_price.getText().equals("")&& !text_out_price.getTex

30、t().equals("")&& !text_jinhuo.getText().equals("")&& !text_chuhuo.getText().equals("") && !text_kucu n.getText().equals("") /獲取文本框信息int idStri ng=l nteger.parsel nt(text_id.getText();Stri ng ids=text_id.getText();Stri ng n ameStri ng=te

31、xt_ name.getText();String addresStri ng=text_address.getText();doublein_priceStri ng=Double.parseDouble(text_in_price.getText();doubleout_priceStri ng=Double.parseDouble(text_out_price.getText();int jin huoStri ng=ln teger.parse In t(text_j in huo.getText();int chuhuoStri ng=ln teger.parse In t(text

32、_chuhuo.getText();int kuc un=ln teger.parse In t(text_kuc un. getText();if (in _priceStri ng<=0) JOptio nPan e.showMessageDialog(this,"親,進(jìn)價(jià)要大于零哦!”);else if (in _priceStri ng>=out_priceStri ng) JOptio nPa ne.showMessageDialog(this,"親,要有盈利的,銷售價(jià)格要大于進(jìn)價(jià)!");else (”錄入商品”);if(idStri ng!

33、=O&&!n ameStri ng.equals("")&& !addresString.equals("")&& in_priceString!=O && out_priceString!=O &&jin huoStri ng!=0 && chuhuoStri ng!=0 && kucu n!=0) /對數(shù)據(jù)庫的操作String sql="i nsert into result values('"+ids +&qu

34、ot;','" +n ameStri ng+"','"+addresStri ng+"',"+in_priceStri ng+","+out_priceStri ng+","+jin huoStri ng+","+chuhuoStri ng+","+kucun+")"Userdate userdate=new Userdate();boolea n flag=userdate.add_goods(sql);

35、if (flag) /對表格的操作model.i nsertRow(model.getRowCou nt(),newObjectids,n ameStri ng,addresStri ng,i n_priceStri ng,out_priceStri ng,ji nhuoStri ng,chuhuoStri n g,kuc un );else JOptio nPan e.showMessageDialog(this,"商品編號(hào)重復(fù)! ”);else JOptio nPa ne.showMessageDialog(this," 請輸入商品詳細(xì) 信息! ”);else JOpt

36、io nPa ne.showMessageDialog(this,"請輸入商品的詳細(xì)信息!”);/刪除功能else if(btString.equals("刪除所選商品")/獲取要?jiǎng)h除的行,沒有選擇是-1int row=table.getSelectedRow();System.out.print(" 刪除商品操作”);System.out.pri nt(row);if (row=-1) JOptio nPa ne.showMessageDialog(this,"請選擇要?jiǎng)h除商品的商品名!");else /System.out.pri

37、 nt(row);/數(shù)據(jù)庫刪除商品操作intsha ngpin _id=In teger.parse In t(Stri ng)model.getValueAt(row, 0);String sha ngpin _id=(Stri ng) model.getValueAt(row, 0);System.out.pri nt(row);Stri ng sql="delete from result where id='"+shangpin_id+""'Userdate userdate=new Userdate();boolea n fla

38、g=userdate.add_goods(sql);if (flag) model.removeRow(row);/重置功能else if(btString.equals("重置信息")text_id.setText("");text_ name.setText("");text_address.setText("");text_in_price.setText("");text_out_price.setText("");text_ji nhuo.setText("

39、;");text_chuhuo.setText("");text_kucu n.setText("");else if(btString.equals("修改密碼")UpData data=new UpData();data.setVisible(true);else if(btString.equals("計(jì)算器")Calculator calculator = new Calculator();calculator.setSize(250,350);calculator.setLocati on Re

40、lativeTo (nu II);calculator.setVisible(true);calculator.setResizable(false);else if(btString.equals("退出系統(tǒng)")System.exit(0);記事本")else if (btStri ng.equals(”NotePad notePad=n ew NotePad(); no tePad.setVisible(true);else if(btString.equals(”查看幫助")/System.out.pri ntl n("help_pss&

41、quot;); try useCMDComma nd();System.out.pri ntl n("help_pss"); catch (IOException e1) / TODO Auto-ge nerated catch block e1.pri ntStackTrace();else if(btString.equals("關(guān)于")About about =new About(); about.setVisible(true);else if(btString.equals("重新登錄")(”重新登錄");Land

42、ing landing = new Landin g();landin g.setVisible(true);this.dispose();else if(btString.equals("查找")c.show(card,"2");else if(btString.equals("錄入")c.show(card,"1");else if(btString.equals("刪除")c.show(card,"2");JOptio nPan e.showMessageDialog(

43、this,"請先查找所要?jiǎng)h除的商品信息!");else if(btString.equals("背景設(shè)置")c.show(card,"3");/查找功能else if(btStri ng.equals("根據(jù)商品編號(hào)查詢")if (text_fi nd.getText().equals("") JOptio nPan e.showMessageDialog(this,"查詢信息為空!”);else int id =ln teger.parseI nt(text_fi nd.getTex

44、t().trim();Stri ng id =text_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=In teger.toStri ng(goods.getld();String idStri ng=goods.getld();String n ameStri ng=goods.ge

45、tName();String addresStri ng=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();/判斷用戶所輸入的商品編號(hào)數(shù)據(jù)庫中是否有if (idStri ng=null) JOptionPane.showMe

46、ssageDialog(this,"對不起,小編沒有從數(shù)據(jù)庫中找到商品編號(hào)為:"+id+"的信息!");else /對表格的操作model_fi nd.i nsertRow(model_fi nd.getRowCo un t(), new ObjectidStri ng,n ameStri ng,addresStri ng,i n_priceStri ng,out_priceStri ng,ji nhuoStri ng,chuhuoStri ng,kuc un );else if(btStri ng.equals(”根據(jù)商品名稱查詢")Stri

47、 ng n ame =text_fi nd.getText().trim();Good_data data=new Good_data();Stri ng sql="select * from result where nam like '%"+name+"%":List<Goods> datalist=data.fi ndGoods(sql);/獲取文本框信息if (n ame.equals("") JOptio nPan e.showMessageDialog(this,"查詢信息為空!”);else

48、 if (datalist.size()<=0) JOptionPane.showMessageDialog(this,"對不起,小編沒有從數(shù)據(jù)庫中找到商品名為:"+n ame+"的信息! ”);for(Goods d:datalist)遍歷數(shù)據(jù),將查詢所得到的數(shù)據(jù)逐一賦值到表中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

49、ng=d.getl n_price();double out_priceStri ng=d.getOut_price();int 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 ng,i n_priceStri ng,out_priceStri ng,ji nhuoStri ng,chuhuoStri n g,kuc un );else if(btString.equals(”刪除所選信息")/獲取要?jiǎng)h除的行,沒有選擇是-1int row=table_fi nd.getSelectedRow();System.out.print("刪除商品操作”);System.out.pri nt(row);if (row=-1) JOptio nPa ne.showMessageDialog(this,"請選擇要?jiǎng)h除商品!”);else

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論