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

下載本文檔

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

文檔簡(jiǎn)介

1、/代表各的主頁(yè)面package com.gui;import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.io.*;import java.nio.channels.ClosedSelectorException;import java.sql.*;import javax.swing.JFileChooser;import javax.swing.plaf.ScrollBarUI;import javax.swing.table.DefaultTableColumnModel;import javax

2、.swing.table.DefaultTableModel;import com.DateSystem.Good_data;import com.DateSystem.Goods;import com.DateSystem.Userdate;import java.util.List;public class Main extends JFrame implements ActionListener,AdjustmentListener/* * param args */主窗體組件MenuBar menuBar; Menu menu_xitong,menu_guanli,menu_gongj

3、u,menu_Help;MenuItem item_up_password, item_reLanding, item_exit;MenuItem item_input, item_find, item_delete;MenuItem item_jisuanqi, item_jishiben, item_beijing;MenuItem item_LookHelp, item_About;/錄入界面要用的組件JPanel jp_btn,jp_main,jp_table,jp_text;JLabel lbl_id, lbl_name, lbl_address, lbl_in_price, lbl

4、_out_price, lbl_kucun, lbl_jinhuo, lbl_chuhuo;TextField text_id,text_name,text_address,text_in_price,text_out_price,text_kucun,text_jinhuo,text_chuhuo;JButton submit,reset,delete;JScrollPane jsp;JTable table;DefaultTableModel model;CardLayout c=new CardLayout();JPanel card;/查找頁(yè)面要用的組件JPanel jp1,jp2,j

5、p3;JPanel jp2_main;JButton find_id,find_name,find_delete,find_all;JTextField text_find;JScrollPane jsp_find;JTable table_find;DefaultTableModel model_find;/背景更改要用的組件int r =255,g=255,b=255;TextField tfr,tfg,tfb;Scrollbar sbr,sbg,sbb;Panel display;JPanel jp3_main;public Main()super("主窗口");me

6、nuBar=new MenuBar();menu_gongju=new Menu("工具");menu_guanli=new Menu("管理");menu_Help=new Menu("幫助");menu_xitong=new Menu("系統(tǒng)");item_About=new MenuItem("關(guān)于");item_beijing=new MenuItem("背景設(shè)置");item_LookHelp=new MenuItem("查看幫助");item_

7、up_password=new MenuItem("修改密碼");item_reLanding=new MenuItem("重新登錄");item_exit=new MenuItem("退出系統(tǒng)");item_jishiben=new MenuItem("記事本");item_jisuanqi=new MenuItem("計(jì)算器");item_find=new MenuItem("查找");item_input=new MenuItem("錄入");ite

8、m_delete=new MenuItem("刪除");/注冊(cè)監(jiān)聽(tīng)item_About.addActionListener(this);item_beijing.addActionListener(this);item_LookHelp.addActionListener(this);item_up_password.addActionListener(this);item_reLanding.addActionListener(this);item_exit.addActionListener(this);item_jishiben.addActionListener(t

9、his);item_jisuanqi.addActionListener(this);item_find.addActionListener(this);item_input.addActionListener(this);item_delete.addActionListener(this);menu_xitong.add(item_up_password);menu_xitong.add(item_reLanding);menu_xitong.add(item_exit);menu_guanli.add(item_input);menu_guanli.add(item_find);/men

10、u_guanli.add(item_delete);menu_gongju.add(item_jisuanqi);menu_gongju.add(item_jishiben);menu_gongju.add(item_beijing);menu_Help.add(item_About);menu_Help.add(item_LookHelp);menuBar.add(menu_xitong);menuBar.add(menu_guanli);menuBar.add(menu_gongju);menuBar.add(menu_Help);setMenuBar(menuBar);setResiza

11、ble(false);initComponents();/調(diào)用方法初始化界面Find();change_color();/查找功能的布局以及組建/this.setLayout(new CardLayout();card=new JPanel();card.setLayout(c);card.add("1", jp_main);card.add("2", jp2_main);card.add("3", jp3_main);/this.getContentPane().add("Center", jp_main);th

12、is.add(card);this.setSize(1000, 500);this.setLocationRelativeTo(null);this.setVisible(true);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);/錄入界面初始化private void initComponents() /構(gòu)造面板System.out.println("pass");lbl_id=new JLabel("商品編號(hào)",JLabel.CENTER);lbl_name=new JLabel("

13、商品名稱",JLabel.CENTER);lbl_address=new JLabel("商品產(chǎn)地",JLabel.CENTER);lbl_in_price=new JLabel("進(jìn)價(jià)",JLabel.CENTER);lbl_out_price=new JLabel("售價(jià)",JLabel.CENTER);lbl_jinhuo=new JLabel("進(jìn)貨量",JLabel.CENTER);lbl_chuhuo=new JLabel("銷(xiāo)售量",JLabel.CENTER);lbl_

14、kucun=new JLabel("庫(kù)存量",JLabel.CENTER);text_id=new TextField();text_name = new TextField();text_address=new TextField();text_in_price=new TextField();text_out_price=new TextField();text_jinhuo=new TextField();text_chuhuo=new TextField();text_kucun=new TextField();jp_table=new JPanel(new Bor

15、derLayout();jp_text =new JPanel(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(lbl_jinhuo);jp_text.add(lbl_chuhuo);jp_text.add(lbl_kucun);jp_text.add(text_id);jp_text.add(text_name);jp_text.add(t

16、ext_address);jp_text.add(text_in_price);jp_text.add(text_out_price);jp_text.add(text_jinhuo);jp_text.add(text_chuhuo);jp_text.add(text_kucun);model = new DefaultTableModel(new Object , new String "商品編號(hào)", "商品名稱", "商品產(chǎn)地" ,"進(jìn)價(jià)","售價(jià)","庫(kù)存量",&quo

17、t;進(jìn)貨量","出貨量" );table =new JTable(model);jsp=new JScrollPane(table);submit=new JButton("錄入商品");reset=new JButton("重置信息");delete=new JButton("刪除所選商品");submit.addActionListener(this);reset.addActionListener(this);delete.addActionListener(this);jp_btn=new JPa

18、nel(new GridLayout(1,3);jp_btn.add(submit);jp_btn.add(delete);jp_btn.add(reset);jp_table.add("Center",jp_text);jp_table.add("South",jp_btn);jp_main=new JPanel(new BorderLayout(10,10);jp_main.add("Center",jsp);jp_main.add("North",jp_table);System.out.println(&q

19、uot;pass");/查找面板初始化面板private void Find() jp1=new JPanel(new GridLayout(1,1);jp2=new JPanel(new GridLayout(1,4);jp3=new JPanel(new BorderLayout();find_id =new JButton("根據(jù)商品編號(hào)查詢");find_name=new JButton("根據(jù)商品名稱查詢");find_all=new JButton("查詢所有信息");find_delete=new JButto

20、n("刪除所選信息");text_find=new JTextField();jsp_find=new JScrollPane();table_find=new JTable();model_find=new DefaultTableModel();model_find = new DefaultTableModel(new Object , new String "商品編號(hào)", "商品名稱", "商品產(chǎn)地" ,"進(jìn)價(jià)","售價(jià)","庫(kù)存量","

21、進(jìn)貨量","出貨量" );table_find =new JTable(model_find);jsp_find=new JScrollPane(table_find);find_id.addActionListener(this);find_name.addActionListener(this);find_all.addActionListener(this);find_delete.addActionListener(this);jp1.add(text_find);jp2.add(find_id);jp2.add(find_name);jp2.add(fi

22、nd_all);jp2.add(find_delete);jp3.add("North",jp1);jp3.add("Center",jp2);jp2_main=new JPanel(new BorderLayout(10,10);jp2_main.add("Center",jsp_find);jp2_main.add("North",jp3);/背景更改private void change_color() jp3_main=new JPanel();display =new Panel();display.se

23、tBackground(Color.WHITE);Panel pcolor =new Panel();pcolor.setLayout(new BorderLayout();Panel pw=new Panel();pw.setLayout(new GridLayout(3,2,0,0);jp3_main.setLayout(new BorderLayout();tfr= new TextField("255");tfg=new TextField("255");tfb=new TextField("255");tfr.setEdit

24、able(false);tfg.setEditable(false);tfb.setEditable(false);sbr=new Scrollbar(Scrollbar.HORIZONTAL,255,0,0,255);sbg=new Scrollbar(Scrollbar.HORIZONTAL,255,0,0,255);sbb=new Scrollbar(Scrollbar.HORIZONTAL,255,0,0,255);sbr.setName("SBR");sbg.setName("SBG");sbb.setName("SBB")

25、;sbr.setBackground(Color.red);sbg.setBackground(Color.green);sbb.setBackground(Color.blue);sbr.addAdjustmentListener(this);sbg.addAdjustmentListener(this);sbb.addAdjustmentListener(this);pw.add(new Label("紅色");pw.add(tfr);pw.add(new Label("綠色");pw.add(tfg);pw.add(new Label("

26、藍(lán)色");pw.add(tfb);Panel pc= new Panel();pc.setLayout(new GridLayout(3, 1, 0, 0);pc.add(sbr);pc.add(sbg);pc.add(sbb);pcolor.add(pw,BorderLayout.WEST);pcolor.add(pc,BorderLayout.CENTER);jp3_main.add(display,BorderLayout.CENTER);jp3_main.add(pcolor,BorderLayout.SOUTH);/查看幫助文檔,調(diào)用本地的程序,查看幫助文檔public v

27、oid useCMDCommand() throws IOException Runtime.getRuntime().exec(new String"cmd.exe", "/c", ".BaoDing_Shoop保定商場(chǎng)商品管理系統(tǒng)項(xiàng)目幫助.doc"); /主函數(shù)public static void main(String args) / TODO Auto-generated method stubjava.awt.EventQueue.invokeLater(new Runnable() public void run() ne

28、w Main().setVisible(true); );/監(jiān)聽(tīng)方法public void actionPerformed(ActionEvent e) /得到事件源String btString=e.getActionCommand();/錄入功能if (btString.equals("錄入商品") /追加到最后一行if(!text_id.getText().equals("") && !text_name.getText().equals("") && !text_address.getText(

29、).equals("") && !text_in_price.getText().equals("") && !text_out_price.getText().equals("") && !text_jinhuo.getText().equals("") && !text_chuhuo.getText().equals("") && !text_kucun.getText().equals(""

30、) /獲取文本框信息int idString=Integer.parseInt(text_id.getText();String ids=text_id.getText();String nameString=text_name.getText();String addresString=text_address.getText();double in_priceString=Double.parseDouble(text_in_price.getText();double out_priceString=Double.parseDouble(text_out_price.getText();

31、int jinhuoString=Integer.parseInt(text_jinhuo.getText();int chuhuoString=Integer.parseInt(text_chuhuo.getText();int kucun=Integer.parseInt(text_kucun.getText();if (in_priceString<=0) JOptionPane.showMessageDialog(this, "親,進(jìn)價(jià)要大于零哦!");else if (in_priceString>=out_priceString) JOptionPa

32、ne.showMessageDialog(this, "親,要有盈利的,銷(xiāo)售價(jià)格要大于進(jìn)價(jià)!");else System.out.print("錄入商品");if (idString!=0 && !nameString.equals("") && !addresString.equals("") && in_priceString!=0 && out_priceString!=0 && jinhuoString!=0 &&

33、; chuhuoString!=0 && kucun!=0) /對(duì)數(shù)據(jù)庫(kù)的操作 String sql="insert into result values('"+ ids +"','" + nameString+"','"+ addresString+"',"+ in_priceString+","+ out_priceString+","+ jinhuoString+","+ chuhuoS

34、tring+","+ kucun+ ")"Userdate userdate=new Userdate();boolean flag=userdate.add_goods(sql);if (flag) /對(duì)表格的操作model.insertRow(model.getRowCount(), new Object ids, nameString,addresString,in_priceString,out_priceString,jinhuoString,chuhuoString,kucun );else JOptionPane.showMessageDi

35、alog(this, "商品編號(hào)重復(fù)!"); else JOptionPane.showMessageDialog(this, "請(qǐng)輸入商品詳細(xì)信息!");else JOptionPane.showMessageDialog(this, "請(qǐng)輸入商品的詳細(xì)信息!");/刪除功能else if(btString.equals("刪除所選商品")/獲取要?jiǎng)h除的行,沒(méi)有選擇是-1int row=table.getSelectedRow();System.out.print("刪除商品操作");Syst

36、em.out.print(row);if (row=-1) JOptionPane.showMessageDialog(this,"請(qǐng)選擇要?jiǎng)h除商品的商品名!");else /System.out.print(row);/數(shù)據(jù)庫(kù)刪除商品操作/int shangpin_id= Integer.parseInt(String) model.getValueAt(row, 0) ;String shangpin_id=(String) model.getValueAt(row, 0) ;System.out.print(row);String sql="delete f

37、rom result where id='"+shangpin_id+"'"Userdate userdate=new Userdate();boolean flag=userdate.add_goods(sql);if (flag) model.removeRow(row);/重置功能else if(btString.equals("重置信息")text_id.setText("");text_name.setText("");text_address.setText("&qu

38、ot;);text_in_price.setText("");text_out_price.setText("");text_jinhuo.setText("");text_chuhuo.setText("");text_kucun.setText("");else if(btString.equals("修改密碼")UpData data=new UpData();data.setVisible(true);else if(btString.equals("計(jì)算器

39、")Calculator calculator = new Calculator();calculator.setSize(250,350);calculator.setLocationRelativeTo(null);calculator.setVisible(true);calculator.setResizable(false);else if(btString.equals("退出系統(tǒng)")System.exit(0);else if (btString.equals("記事本") NotePad notePad=new NotePad(

40、);notePad.setVisible(true);else if(btString.equals("查看幫助")/System.out.println("help_pss");try useCMDCommand();System.out.println("help_pss"); catch (IOException e1) / TODO Auto-generated catch blocke1.printStackTrace();else if(btString.equals("關(guān)于")About about

41、=new About();about.setVisible(true);else if(btString.equals("重新登錄")System.out.print("重新登錄");Landing landing = new Landing();landing.setVisible(true);this.dispose();else if(btString.equals("查找")c.show(card,"2");else if(btString.equals("錄入")c.show(card

42、,"1");else if(btString.equals("刪除")c.show(card,"2");JOptionPane.showMessageDialog(this, "請(qǐng)先查找所要?jiǎng)h除的商品信息!");else if(btString.equals("背景設(shè)置")c.show(card,"3");/查找功能else if(btString.equals("根據(jù)商品編號(hào)查詢")if (text_find.getText().equals("

43、;") JOptionPane.showMessageDialog(this, "查詢信息為空!");else /int id =Integer.parseInt(text_find.getText().trim();String id =text_find.getText().trim();Good_data data=new Good_data();Goods goods =data.findStudentById(id);/String id_s=Integer.toString(id);/獲取文本框信息/int idString=goods.getId()

44、;/String ids=Integer.toString(goods.getId();String idString=goods.getId();String nameString=goods.getName();String addresString=goods.getAddress();double in_priceString=goods.getIn_price();double out_priceString=goods.getOut_price();int jinhuoString=goods.getJinhuo();int chuhuoString=goods.getChuhuo

45、();int kucun=goods.getKucun();/判斷用戶所輸入的商品編號(hào)數(shù)據(jù)庫(kù)中是否有if (idString=null) JOptionPane.showMessageDialog(this,"對(duì)不起,小編沒(méi)有從數(shù)據(jù)庫(kù)中找到商品編號(hào)為:"+id+"的信息!");else /對(duì)表格的操作model_find.insertRow(model_find.getRowCount(), new Object idString, nameString,addresString,in_priceString,out_priceString,jinhuo

46、String,chuhuoString,kucun );else if(btString.equals("根據(jù)商品名稱查詢")String name =text_find.getText().trim();Good_data data=new Good_data();String sql="select * from result where nam like '%"+name+"%'" List<Goods> datalist=data.findGoods(sql);/獲取文本框信息 if (name.e

47、quals("") JOptionPane.showMessageDialog(this, "查詢信息為空!");else if (datalist.size()<=0) JOptionPane.showMessageDialog(this,"對(duì)不起,小編沒(méi)有從數(shù)據(jù)庫(kù)中找到商品名為:"+name+"的信息!"); for(Goods d:datalist)/遍歷數(shù)據(jù),將查詢所得到的數(shù)據(jù)逐一賦值到表中/int idString=d.getId();String idString=d.getId();String

48、 nameString=d.getName();String addresString=d.getAddress();double in_priceString=d.getIn_price();double out_priceString=d.getOut_price();int jinhuoString=d.getJinhuo();int chuhuoString=d.getChuhuo();int kucun=d.getKucun();/對(duì)表格的操作model_find.insertRow(model_find.getRowCount(), new Object idString, nameString,addresString,in_priceString,out_priceString,jinhuoString,chuhuoString,kucun ); else if(btString.equals("刪除所選信息")/獲取要?jiǎng)h除的行,沒(méi)有選擇是-1int row=table_find.getSelectedRow();System.out.print("刪除商品操作");System.out.print(row);if (row=-1) JOptionPane.showMessageDia

溫馨提示

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

最新文檔

評(píng)論

0/150

提交評(píng)論