




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、/代表各的主页面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;/查找页面要用的组件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("系统");item_About=new MenuItem("关于");item_beijing=new MenuItem("背景设置");item_LookHelp=new MenuItem("查看帮助");item_
7、up_password=new MenuItem("修改密码");item_reLanding=new MenuItem("重新登录");item_exit=new MenuItem("退出系统");item_jishiben=new MenuItem("记事本");item_jisuanqi=new MenuItem("计算器");item_find=new MenuItem("查找");item_input=new MenuItem("录入");ite
8、m_delete=new MenuItem("删除");/注册监听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();/调用方法初始化界面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() /构造面板System.out.println("pass");lbl_id=new JLabel("商品编号",JLabel.CENTER);lbl_name=new JLabel("
13、商品名称",JLabel.CENTER);lbl_address=new JLabel("商品产地",JLabel.CENTER);lbl_in_price=new JLabel("进价",JLabel.CENTER);lbl_out_price=new JLabel("售价",JLabel.CENTER);lbl_jinhuo=new JLabel("进货量",JLabel.CENTER);lbl_chuhuo=new JLabel("销售量",JLabel.CENTER);lbl_
14、kucun=new JLabel("库存量",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 "商品编号", "商品名称", "商品产地" ,"进价","售价","库存量",&quo
17、t;进货量","出货量" );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("根据商品编号查询");find_name=new JButton("根据商品名称查询");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 "商品编号", "商品名称", "商品产地" ,"进价","售价","库存量","
21、进货量","出货量" );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、蓝色");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);/查看帮助文档,调用本地的程序,查看帮助文档public v
27、oid useCMDCommand() throws IOException Runtime.getRuntime().exec(new String"cmd.exe", "/c", ".BaoDing_Shoop保定商场商品管理系统项目帮助.doc"); /主函数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); );/监听方法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, "亲,进价要大于零哦!");else if (in_priceString>=out_priceString) JOptionPa
32、ne.showMessageDialog(this, "亲,要有盈利的,销售价格要大于进价!");else System.out.print("录入商品");if (idString!=0 && !nameString.equals("") && !addresString.equals("") && in_priceString!=0 && out_priceString!=0 && jinhuoString!=0 &&
33、; chuhuoString!=0 && kucun!=0) /对数据库的操作 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) /对表格的操作model.insertRow(model.getRowCount(), new Object ids, nameString,addresString,in_priceString,out_priceString,jinhuoString,chuhuoString,kucun );else JOptionPane.showMessageDi
35、alog(this, "商品编号重复!"); else JOptionPane.showMessageDialog(this, "请输入商品详细信息!");else JOptionPane.showMessageDialog(this, "请输入商品的详细信息!");/删除功能else if(btString.equals("删除所选商品")/获取要删除的行,没有选择是-1int row=table.getSelectedRow();System.out.print("删除商品操作");Syst
36、em.out.print(row);if (row=-1) JOptionPane.showMessageDialog(this,"请选择要删除商品的商品名!");else /System.out.print(row);/数据库删除商品操作/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("计算器
39、")Calculator calculator = new Calculator();calculator.setSize(250,350);calculator.setLocationRelativeTo(null);calculator.setVisible(true);calculator.setResizable(false);else if(btString.equals("退出系统")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("关于")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, "请先查找所要删除的商品信息!");else if(btString.equals("背景设置")c.show(card,"3");/查找功能else if(btString.equals("根据商品编号查询")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();/判断用户所输入的商品编号数据库中是否有if (idString=null) JOptionPane.showMessageDialog(this,"对不起,小编没有从数据库中找到商品编号为:"+id+"的信息!");else /对表格的操作model_find.insertRow(model_find.getRowCount(), new Object idString, nameString,addresString,in_priceString,out_priceString,jinhuo
46、String,chuhuoString,kucun );else if(btString.equals("根据商品名称查询")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,"对不起,小编没有从数据库中找到商品名为:"+name+"的信息!"); for(Goods d:datalist)/遍历数据,将查询所得到的数据逐一赋值到表中/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();/对表格的操作model_find.insertRow(model_find.getRowCount(), new Object idString, nameString,addresString,in_priceString,out_priceString,jinhuoString,chuhuoString,kucun ); else if(btString.equals("删除所选信息")/获取要删除的行,没有选择是-1int row=table_find.getSelectedRow();System.out.print("删除商品操作");System.out.print(row);if (row=-1) JOptionPane.showMessageDia
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 银行行长面试题及答案
- 银行信贷试题判断及答案
- 吉林铁路专业试题及答案
- 美容专业试题及答案
- 检验专业的面试题及答案
- 管理学专业面试题及答案
- 变配电专业试题及答案
- 卫生专业试题及答案
- 福建省山海联盟教学协作体2024-2025学年高二上学期期中地理试卷(含答案)
- 哪有不收费的施工方案
- 2025年教师职称-浙江-浙江教师职称(基础知识、综合素质、初中信息技术)历年参考题库典型考点含答案解析
- 北京高校标准化食堂标准(2026版)讲解
- 专题1.4数学归纳法(高效培优讲义)
- 泸州北方化学工业有限公司锅炉烟气脱硫脱硝除尘技改项目环评报告
- 可靠性基础知识培训课件
- 耗材产品售后方案(3篇)
- 2025年全国保密教育线上培训考试试题库(含答案)
- DGTJ08-2004B-2020 建筑太阳能光伏发电应用技术标准
- 产伤性阴道血肿护理课件
- 校园周边安全管理办法
- 腕部损伤的护理课件
评论
0/150
提交评论