⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 salemanger.java

📁 一个超市收银系统,用eclipse开发,使用了数据库
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        About.add(AboutSystem);        AboutSystem.addActionListener(new ActionListener() {	        public void actionPerformed(ActionEvent e) {	        	Bangzhu_gui AboutS=new Bangzhu_gui();				AboutS.bangzhu_gui(frame);          	 	        }	    });        bar.add(About);                 	// Add all the components to the main panel.        fieldPane3 = new JPanel(false);        fieldPane3.setLayout(new GridLayout(1, 3));        PIdLabel = new JLabel("商品编码: ", JLabel.RIGHT);        TIdField=new JTextField("23",5);        TIdField.setDocument(new MaxLenDocument(13));               // TIdField        PNameLabel = new JLabel("商品名称: ", JLabel.RIGHT);        TNameField=new JTextField("");        TNameField.setEditable(false);        PPriceLabel = new JLabel("单    价: ", JLabel.RIGHT);        TPriceField=new JMoneyField("0",15,2);        TPriceField.setEditable(false);       // TPriceField.setDocument(new MoneyForMatDocument(20));        PQualityLabel = new JLabel("数    量: ", JLabel.RIGHT);        TQualityField=new JMoneyField("1",15,2);        TQualityField.setText("1");      //  TQualityField.setDocument(new MoneyForMatDocument(20));        PTotalCostLabel = new JLabel("总    价: ", JLabel.LEFT);        TTotalCostField=new JMoneyField("0",15,1);        TTotalCostField.setEditable(false);                PCostLabel = new JLabel("应    付: ", JLabel.LEFT);        TCostField=new JMoneyField("0",15,1);       // TCostField.setDocument(new MoneyForMatDocument(20));        TCostField.setEditable(false);        PPayLabel = new JLabel("支    付: ", JLabel.LEFT);        TPayField=new JMoneyField("0",15,1);        TPayField.setDocument(new GetMoneyDocument(15,1));       // TPayField.setDocument(new MoneyForMatDocument(20));        PChangeLabel = new JLabel("找    零: ", JLabel.LEFT);        TChangeField=new JMoneyField("0",15,1);      //  TChangeField.setDocument(new MoneyForMatDocument(20));        TChangeField.setEditable(false);                PayButton= new JButton("结算");        PayButton.addActionListener(new ActionListener() {	        public void actionPerformed(ActionEvent e) {	        	if(TTotalCostField.getText().trim().equals(""))	        		return;	        	if(TChangeField.getText().trim().equals("")){	        		JOptionPane.showMessageDialog(tableAggregate,"客户所付的钱不够,无法完成结算","提示",JOptionPane.ERROR_MESSAGE,	    					new ImageIcon("image/caidanx.gif"));		        		return;	        	}	        		        	PayFunction();	        }	    }        );                   PayButton.setIcon(payIcon);                        TChangeMethodLable=new JLabel("找零组合: ", JLabel.LEFT);                                       // TIdField.setEditable(false);        JPanel namePane11 = new JPanel(false);        namePane11.setLayout(new GridLayout(1, 2));        namePane11.add(PIdLabel);        namePane11.add(TIdField);        JPanel namePane12 = new JPanel(false);        namePane12.setLayout(new GridLayout(1, 2));        namePane12.add(PNameLabel);        namePane12.add(TNameField);        JPanel namePane13 = new JPanel(false);        namePane13.setLayout(new GridLayout(1, 2));        namePane13.add(PPriceLabel);        namePane13.add(TPriceField);      //  TPriceField        JPanel namePane14 = new JPanel(false);        namePane14.setLayout(new GridLayout(1, 2));        namePane14.add(PQualityLabel);        namePane14.add(TQualityField);     /*   JPanel namePane15 = new JPanel(false);        namePane15.setLayout(new GridLayout(1, 2));*/      ///  namePane15.add(PCostLabel);      //  namePane15.add(TCostField);                JPanel namePane16 = new JPanel(false);        namePane16.setLayout(new GridLayout(5,1));        namePane16.add(namePane11);        namePane16.add(namePane12);        namePane16.add(namePane13);        namePane16.add(namePane14);      //  namePane16.add(namePane15);        JPanel namePane17 = new JPanel(false);        namePane17.setLayout(new GridLayout(2, 1));                fieldPane3.add(namePane16);     //   fieldPane3.add(namePane17);        fieldPane3.setAutoscrolls(false);                        RightPanel1=new JPanel(false);        RightPanel1.setLayout(new GridLayout(9,1));        RightPanel1.add(PTotalCostLabel);        RightPanel1.add(TTotalCostField);        RightPanel1.add(PCostLabel);        RightPanel1.add(TCostField);        RightPanel1.add(PPayLabel);        RightPanel1.add(TPayField);        RightPanel1.add(PChangeLabel);        RightPanel1.add(TChangeField);        RightPanel1.add(PayButton);       /* fieldPane3.add(PIdLabel);        fieldPane3.add(TIdField);        fieldPane3.add(PNameLabel);        fieldPane3.add(TNameField);        fieldPane3.add(PPriceLabel);        fieldPane3.add(TPriceField);        fieldPane3.add(PQualityLabel);                fieldPane3.add(TQualityField);        fieldPane3.add(PCostLabel);        fieldPane3.add(TCostField);*/                        BottomPanel1=new JPanel(false);        BottomPanel1.setLayout(new GridLayout(1,5));                DelButton = new JButton("取消");        DelButton.addActionListener(new ActionListener() {	        public void actionPerformed(ActionEvent e) {	        	DelProduct();            	 	        }	    }        	);        DelButton.setIcon(DelIcon);        BottomPanel1.add(DelButton);                        BottomPanel2=new JPanel(false);        BottomPanel2.setLayout(new GridLayout(1,5));        BottomPanel2.add(TChangeMethodLable);                mainPanel.add(fieldPane3);             //   namePane17.add(ManagerButton);     //   namePane17.add(BuyButton);                mainPanel.add(BuyButton);        mainPanel.add(ManagerButton);               //mainPanel.add(queryAggregate);        mainPanel.add(tableAggregate);        mainPanel.add(BottomPanel1);        mainPanel.add(RightPanel1);        mainPanel.add(BottomPanel2);                mainPanel.setLayout(this);        // Create a Frame and put the main panel in it.        frame = new JFrame("销售系统");        frame.setJMenuBar(bar);        frame.addWindowListener(new WindowAdapter() {            public void windowClosing(WindowEvent e) {System.exit(0);}});        frame.setBackground(Color.lightGray);        frame.getContentPane().add(mainPanel);        frame.pack();        frame.getRootPane().setDefaultButton(BuyButton);     //   frame.setVisible(false);        frame.setBounds(200, 200, 640, 480);        /*[窗口屏幕中间显示]*/        Dimension   screenSize   =   Toolkit.getDefaultToolkit().getScreenSize();           Dimension   frameSize   =   frame.getSize();           if   (frameSize.height   >   screenSize.height)   {               frameSize.height   =   screenSize.height;           }           if   (frameSize.width   >   screenSize.width)   {               frameSize.width   =   screenSize.width;           }           frame.setLocation((screenSize.width   -   frameSize.width)   /   2,   (screenSize.height   -   frameSize.height)   /   2);          	while(activateConnectionDialog());	    if(SystemUser.getUserType()==0){	    	ManagerButton.setVisible(false);	    }	    frame.setTitle("销售系统(欢迎"+SystemUser.getUserName()+")");	        }    /**     * 创建table     * */    public JScrollPane createTable() {       // sorter = new TableSorter();        //connect();        //fetch();    	Object data[][]={{"","","","",""}};    	Object name[]={"商品编号","商品名称","单价","数量","总价"};        model   =   new DefaultTableModel(data,name){               public   boolean   isCellEditable(int   row,   int   column)   {             	if(column!=3)                return   false;            	else            		return true;            }           };            // Create the table        table = new JTable(model);         model.removeRow(0);        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);           table.getColumn("商品编号").setPreferredWidth(120);         table.getColumn("商品名称").setPreferredWidth(200);           table.getColumn("单价").setPreferredWidth(60);          table.getColumn("数量").setPreferredWidth(60);          table.getColumn("总价").setPreferredWidth(80);          table.getSelectionModel().addListSelectionListener(                new ListSelectionListener() {                    public void valueChanged(ListSelectionEvent event) {                        int viewRow = table.getSelectedRow();                        if (viewRow < 0) {                            //Selection got filtered away.                         //   ClearAll();                        } else {                            /* TIdField.setText(table.getValueAt(viewRow, 0).toString());                             TNameField.setText(table.getValueAt(viewRow, 1).toString());                             TPriceField.setText(table.getValueAt(viewRow, 2).toString());                             TQualityField.setText(table.getValueAt(viewRow, 3).toString());                             TCostField.setText(table.getValueAt(viewRow, 4).toString());*/                        }                    }                }        );                table.getModel().addTableModelListener(new TableModelListener(){         	public void tableRowsInserted(TableModelEvent e){          	/*     double money=0;            	 for(int i=0;i<table.getRowCount();i++){       		     money=StrtoDouble(table.getValueAt(i, 4).toString());           	 }           	 String str=""+money;       	     TCostField.setText(str);*/           }            public void tableChanged(TableModelEvent e){             	 int viewRow = e.getFirstRow();                 if (viewRow < 0) {                     //Selection got filtered away.                    // ClearAll();                 } else {                	 int Column=e.getColumn();                	 if(Column==3){                		double money=0;                	    DecimalFormat df1=new DecimalFormat("0.00");                		money=StrtoDouble(table.getValueAt(viewRow, 3).toString())*                		StrtoDouble(table.getValueAt(viewRow, 2).toString());                        String str=df1.format(money);                     	table.setValueAt(str, viewRow, 4);                     	money=0;                     	for(int i=0;i<table.getRowCount();i++)                     		money=money+StrtoDouble(table.getValueAt(i, 4).toString());                        str=df1.format(money);                        TTotalCostField.setText(str);                        df1=new DecimalFormat("0.0");                        TCostField.setText(df1.format(money));                        GetChangeResult();                	 }                	// else                	//	 return;                	// TCostField.setText(table.getValueAt(viewRow, 3).toString());                 }            }             public void tableRowsDeleted(TableModelEvent e){            	            }                                 });                         	  					        		table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);         // Install a mouse listener in the TableHeader as the sorter UI.       // sorter.addMouseListenerToHeaderInTable(table);        JScrollPane scrollpane = new JScrollPane(table);        return scrollpane;    }    /**     * 初始化输入文本框     * */    private void ClearAll()    {    	TIdField.setText("");    	TNameField.setText("");    	TPriceField.setText("");    	TQualityField.setText("1");    	//TCostField.setText("");    }    /**     * 程序入口函数main     * */    public static void main(String s[]) {        new SaleManger();    }    public Dimension preferredLayoutSize(Container c){return origin;}    public Dimension minimumLayoutSize(Container c){return origin;}    public void addLayoutComponent(String s, Component c) {}    public void removeLayoutComponent(Component c) {}    /**     * 主窗口 组件位置初始化     * */    public void layoutContainer(Container c) {        Rectangle b = c.getBounds();        int topHeight = 90;        int inset = 4;        ManagerButton.setBounds(b.width-2*inset-120, inset, 120, 25);        BuyButton.setBounds(b.width-2*inset-120, 60, 120, 25);       // fieldPane3.setBounds(inset, inset, b.width-2*inset - 150, 80);        fieldPane3.setBounds(inset, inset, b.width-2*inset - 150, 100);     //   queryAggregate.setBounds(inset, inset, b.width-2*inset, 80);        tableAggregate.setBounds(new Rectangle(inset,                                               inset + topHeight+20,                                               b.width-2*inset-100,                                               b.height-2*inset - topHeight-60));        BottomPanel1.setBounds(new Rectangle(inset,        		b.height-inset - topHeight-60+inset + topHeight+20,                100,                30));        BottomPanel2.setBounds(inset+120,        		b.height-inset - topHeight-60+inset + topHeight+20,        		b.width-2*inset-100,                30);        RightPanel1.setBounds(b.width-inset-100,inset + topHeight+20,100,b.height-2*inset - topHeight-100);    }   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -