


版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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(” 系统");item_About= new Menultem(” 关于"); item_beijing=new Menulte
7、m(”背景设置");item_LookHelp=new Menultem(” 查看帮助"); item_up_password=new Menultem(” 修改密码"); item_reLanding=new Menultem(”重新登录");item_exit= new Menultem(”退出系统");item_jishiben=new Menultem(”记事本");item_jisuanqi=new Menultem(”计算器");item_find=new Menultem(”查找");item_ in
8、 put=new Men ultem(”录入");item_delete=new Men ultem(”删除");/注册监听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();/调用方法初始化界面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);构造面板
13、号 ”,JLabel.CENTER);商品名称 ”,JLabel.CENTER);商品产地 ”,JLabel.CENTER)进价 ”,JLabel.CENTER);售价 ”,JLabel.CENTER);进货量 ”,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 "商品编号","商品名称","商品产地”,”进价","售价","库存量","进货量","出货量” );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(”根据商品编号查询 ”);find_n ame=new JButt on (”根据商品名称查询”);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 "商品编号","商品名称","商品产地”,"进价","售价","库存量","进货量","出货量");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(" 蓝色");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);/查看帮助文档,调用本地的程序,查看帮助文档public void useCMDComma nd() throws IOExceptio n"/c",Run time.getR un time().exec( newStrin g"
28、;cmd.exe",保定商场商品管理系统项目帮助.doc");/主函数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););/监听方法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,"亲,进价要大于零哦!”);else if (in _priceStri ng>=out_priceStri ng) JOptio nPa ne.showMessageDialog(this,"亲,要有盈利的,销售价格要大于进价!");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) /对数据库的操作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,"商品编号重复! ”);else JOptio nPa ne.showMessageDialog(this," 请输入商品详细 信息! ”);else JOpt
36、io nPa ne.showMessageDialog(this,"请输入商品的详细信息!”);/删除功能else if(btString.equals("删除所选商品")/获取要删除的行,没有选择是-1int row=table.getSelectedRow();System.out.print(" 删除商品操作”);System.out.pri nt(row);if (row=-1) JOptio nPa ne.showMessageDialog(this,"请选择要删除商品的商品名!");else /System.out.pri
37、 nt(row);/数据库删除商品操作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("计算器")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("退出系统")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("关于")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,"请先查找所要删除的商品信息!");else if(btString.equals("背景设置")c.show(card,"3");/查找功能else if(btStri ng.equals("根据商品编号查询")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();/判断用户所输入的商品编号数据库中是否有if (idStri ng=null) JOptionPane.showMe
46、ssageDialog(this,"对不起,小编没有从数据库中找到商品编号为:"+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(”根据商品名称查询")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,"对不起,小编没有从数据库中找到商品名为:"+n ame+"的信息! ”);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
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(”删除所选信息")/获取要删除的行,没有选择是-1int row=table_fi nd.getSelectedRow();System.out.print("删除商品操作”);System.out.pri nt(row);if (row=-1) JOptio nPa ne.showMessageDialog(this,"请选择要删除商品!”);else
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年监理工程师《合同管理》考点:合同风险管理与控制
- 2025年水稻新品种、新组合项目合作计划书
- 2025二级建造师建设工程施工管理知识点:成本加酬金合同解析
- 面包钓鱼测试题及答案
- 《美发店服务礼仪》课件
- 2025标准商务合同应当涵盖的关键要素
- 2025年钢结构用H型钢项目建议书
- 2025年头孢类抗菌药物合作协议书
- 贸易执行面试题及答案
- 2025年木聚糖酶合作协议书
- 伤残鉴定 委托书
- 城乡农产品批发市场四股桥智慧农贸市场建设项目可行性研究报告写作模板-申批备案
- 物流专业人才需求状况调研报告
- 《儿童生长发育规律》课件
- 广西教师副高职称评定条件
- 2025陕西省烟草专卖局招聘51人易考易错模拟试题(共500题)试卷后附参考答案
- 23年第三届概论二等奖教案:吴宁 毛泽东思想及其历史地位
- 《万科的产品战略》课件
- 题型04 化学工艺流程题-【好题汇编】备战2024-2025学年高一化学上学期期末真题分类汇编(江苏专用)
- 2025年中国烟草总公司招聘笔试参考题库含答案解析
- DB3702T 0008-2021 养老保险待遇领取资格大数据认证服务规范
评论
0/150
提交评论