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

📄 inventorygui.java

📁 it is an inventory system which is used to maintain all the accounts of stores
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
// Code Written By Kevin Dela Rosa			June 14, 2004// Created using JCreator and NetBeans IDE/***********************************************************************************//**                                                                               **//**                      Inventory Deluxe v 1.03                                  **/ /**                      InventoryGui Class                                       **/ /**                                                                               **//***********************************************************************************/import  java.io.*;import  java.util.*;import  java.text.*;import  java.awt.*;import  java.awt.event.*;import  javax.swing.*;import  javax.swing.filechooser.*; public class InventoryGui extends  JFrame implements ActionListener{    private Company companyObject;		// Company Object    private String  toolTips[][];	    // Matrix that contains the tool tips for the Inventory Table    private boolean boolSortName;       // Determines if the Inventory Table should be sorted by name or by item number        public InventoryGui() throws IOException    // Default Constructor that initializes the components        {        initComponents();    }        public void refreshFinancialInformation()    // Refreshes the data that is displayed in financial information    {    	DecimalFormat dollar = new DecimalFormat("$0.00");    	String funds = dollar.format(companyObject.getFunds());    	jLabelFinancialStatement.setText("The company currently holds " + funds + " in cash.");    }        public void refreshTable()    // Refreshes the Data that is displayed in the inventory Table    {    	DecimalFormat dollar = new DecimalFormat("$0.00");    	if(boolSortName)    		companyObject.sortByName();    	else    		companyObject.sortById();    	ArrayList temp = companyObject.getItems();    	int numRows = temp.size();    	int newWidth = 650;    	int newHeight = 0;    	    	    	String[] columnNames = new String [] {"Name", "Item Number", "Quantity", "Sales Price",                                 "Order Price", "Descrpition"};    	    	Object[][] tableData = new Object[numRows][columnNames.length];    	    	toolTips = new String[numRows][columnNames.length];    	for(int x = 0; x < numRows; x++)    	{    		Item i = (Item) temp.get(x);    		    		String salesPrice = dollar.format(i.getSalesPrice());    		String orderPrice = dollar.format(i.getOrderPrice());    		    		tableData[x][0] = i.getName();    		tableData[x][1] = i.getId();    		tableData[x][2] = new Integer(i.getAmount());    		tableData[x][3] = salesPrice;    		tableData[x][4] = orderPrice;    		tableData[x][5] = i.getDescription();    		    		toolTips[x][0] = i.getName();    		toolTips[x][1] = i.getId();    		toolTips[x][2] = Integer.toString(i.getAmount());    		toolTips[x][3] = salesPrice;    		toolTips[x][4] = orderPrice;    		toolTips[x][5] = i.getDescription();    		    	}    	 	        jTableInventory.setModel(new  javax.swing.table.DefaultTableModel(tableData,columnNames)         {            Class[] types = new Class [] {            	java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class            };            boolean[] canEdit = new boolean [] {                false, false, false, false, false, false            };                public Class getColumnClass(int columnIndex) {                return types [columnIndex];            }            public boolean isCellEditable(int rowIndex, int columnIndex) {                return canEdit [columnIndex];            }        });            	    	newHeight = numRows * 16;    	if(newHeight < 350)    		newHeight = 350;    		    		    	jTableInventory.setPreferredSize(new  Dimension(newWidth, newHeight));    	refreshFinancialInformation();    } 	public void actionPerformed(ActionEvent evt)	// Handles the action events from the menus and buttons found on the graphical user interface	{			String cmd = evt.getActionCommand();				if(cmd.equals("Sales"))		{			String itemNumber = jTextFieldSalesItemNumber.getText();						try			{				jTextFieldSalesItemNumber.setText(null);								int quantity = Integer.parseInt(jTextFieldSalesQuantity.getText());								if(quantity <= 0)				{					JOptionPane.showMessageDialog(this, "Please only enter positive numbers.", "Input Error", JOptionPane.ERROR_MESSAGE);										}				else if(!companyObject.newSales(itemNumber, quantity))				{					JOptionPane.showMessageDialog(this, "Please enter a valid Item Number, or\nEnter a valid value for the quantity of items sold.","Input Error", JOptionPane.ERROR_MESSAGE);				}				else				{					JOptionPane.showMessageDialog(this, "Sale Complete!", "Sales", JOptionPane.INFORMATION_MESSAGE);				}			}			catch(Exception E)			{				JOptionPane.showMessageDialog(this, "Please enter valid values.", "Input Error",JOptionPane.ERROR_MESSAGE);							} 			jTextFieldSalesQuantity.setText(null);			refreshTable();					}					if(cmd.equals("Order"))		{						String itemNumber = jTextFieldOrderItemNumber.getText();			jTextFieldOrderItemNumber.setText(null);						try			{				int quantity = Integer.parseInt(jTextFieldOrderQuantity.getText());								if(quantity <= 0)				{					JOptionPane.showMessageDialog(this, "Please only enter positive numbers.", "Input Error", JOptionPane.ERROR_MESSAGE);				}				else if(!companyObject.newOrders(itemNumber, quantity))				{					JOptionPane.showMessageDialog(this, "Please enter a valid Item Number, or\nEnter a valid value for the quantity of items ordered.", "Input Error", JOptionPane.ERROR_MESSAGE);				}				else				{					JOptionPane.showMessageDialog(this, "Order Complete!", "Orders", JOptionPane.INFORMATION_MESSAGE);				}			}			catch(Exception E)			{				JOptionPane.showMessageDialog(this, "Please enter valid values.", "Input Error", JOptionPane.ERROR_MESSAGE);					} 				jTextFieldOrderQuantity.setText(null);			refreshTable();				}					if(cmd.equals("Liquidate"))		{			String itemNumber = jTextFieldlLiquidateItemNumber.getText();			jTextFieldlLiquidateItemNumber.setText(null);							if(!companyObject.liquidateItem(itemNumber))			{								JOptionPane.showMessageDialog(this, "Please enter a valid Item Number", "Input Error", JOptionPane.ERROR_MESSAGE);			}			else			{				JOptionPane.showMessageDialog(this, "Item Liquidated!", "Liquidation", JOptionPane.INFORMATION_MESSAGE);			}			refreshTable();		}							if(cmd.equals("New"))		{			String itemNumber = jTextFieldNewItemNumber.getText();			jTextFieldNewItemNumber.setText(null);						String name = jTextFieldNewItemName.getText();			jTextFieldNewItemName.setText(null);						String description = jTextFieldNewItemDescrpition.getText();			jTextFieldNewItemDescrpition.setText(null);							try			{				int itemNumbertest = Integer.parseInt(itemNumber);				double salesPrice = Double.parseDouble(jTextFieldNewItemSalesPrice.getText());				double orderPrice = Double.parseDouble(jTextFieldNewItemOrderPrice.getText());				int initialAmount = Integer.parseInt(jTextFieldNewItemInitialAmount.getText());								if(salesPrice <= 0.0 || orderPrice <= 0.0 || initialAmount <= 0 || itemNumbertest <= 0)				{					JOptionPane.showMessageDialog(this, "Please only enter positive numbers.", "Input Error", JOptionPane.ERROR_MESSAGE);				}				else if(!companyObject.makeItem(name, description, itemNumber, salesPrice, orderPrice, initialAmount))				{					JOptionPane.showMessageDialog(this, ("Item number \"" + itemNumber + "\" already exists.\n or \n Order less of item."), "Input Error",JOptionPane.ERROR_MESSAGE);				}				else				{					JOptionPane.showMessageDialog(this, "New Item Created!", "New Item", JOptionPane.INFORMATION_MESSAGE);				}			}			catch(Exception e)			{				JOptionPane.showMessageDialog(this, "Please enter valid types.", "Input Error", JOptionPane.ERROR_MESSAGE);			}			jTextFieldNewItemSalesPrice.setText(null);			jTextFieldNewItemOrderPrice.setText(null);			jTextFieldNewItemInitialAmount.setText(null);			refreshTable();		}					if(cmd.equals("Update"))		{						String itemNumber = jTextFieldUpdateItemNumber.getText();			jTextFieldUpdateItemNumber.setText(null);						boolean orderPriceUpdate = false;			boolean salesPriceUpdate = false;						if(jTextFieldUpdateOrderPrice.getText() != null )			{				try				{					double orderPrice = Double.parseDouble(jTextFieldUpdateOrderPrice.getText());						if(orderPrice < 0.0)					{						JOptionPane.showMessageDialog(this, "Please enter a positive numbers for Order Price", "Input Error", JOptionPane.ERROR_MESSAGE);					}					else if(companyObject.changeOrderPrice(itemNumber, orderPrice))					{						orderPriceUpdate = true;					}					else					{						JOptionPane.showMessageDialog(this, "Please enter a valid Item Number", "Input Error", JOptionPane.ERROR_MESSAGE);					}										}				catch(Exception e)				{				}			}						jTextFieldUpdateOrderPrice.setText(null);						if(jTextFieldUpdateSalesPrice.getText() != null)			{				try				{									double salesPrice = Double.parseDouble(jTextFieldUpdateSalesPrice.getText());												if(salesPrice < 0.0)					{						JOptionPane.showMessageDialog(this, "Please enter a positive number for Sales Price.", "Input Error", JOptionPane.ERROR_MESSAGE);					}					else if(companyObject.changeSalesPrice(itemNumber, salesPrice))					{						salesPriceUpdate = true;					}					else					{						if(jTextFieldUpdateOrderPrice.getText() == null )						{							JOptionPane.showMessageDialog(this, "Please enter a valid Item Number", "Input Error",JOptionPane.ERROR_MESSAGE);						}					}				}				catch(Exception e)				{				}			}							jTextFieldUpdateSalesPrice.setText(null);							if(orderPriceUpdate)			{				if(salesPriceUpdate)				{					JOptionPane.showMessageDialog(this, "Both Order Price and Sales Price will be updated!", "Update", JOptionPane.INFORMATION_MESSAGE);				}				else				{					JOptionPane.showMessageDialog(this, "Only Order Price will be updated!", "Update", JOptionPane.INFORMATION_MESSAGE);				}			}			else if(salesPriceUpdate)			{				JOptionPane.showMessageDialog(this, "Only Sales Price will be updated!", "Update", JOptionPane.INFORMATION_MESSAGE);			}			else			{				JOptionPane.showMessageDialog(this, "Neither Order Price nor Sales Price will be updated!", "Update", JOptionPane.INFORMATION_MESSAGE);				}									refreshTable();						}					if(cmd.equals("Save"))		{			try    		{    			companyObject.endProgram();    			JOptionPane.showMessageDialog(this, "Saved!", "", JOptionPane.INFORMATION_MESSAGE);    		}    		catch(Exception e)    		{					JOptionPane.showMessageDialog(null, "Saving Error", "File Error", JOptionPane.ERROR_MESSAGE);    		}		}			if(cmd.equals("Sales Data"))		{			jTabbedPaneLayout.setSelectedComponent(jPanelSales);		}						if(cmd.equals("New Orders"))		{			jTabbedPaneLayout.setSelectedComponent(jPanelOrders);		}					if(cmd.equals("Liquidation"))		{			jTabbedPaneLayout.setSelectedComponent(jPanelLiquidate);		}				if(cmd.equals("New Item"))		{			jTabbedPaneLayout.setSelectedComponent(jPanelNewItem);		}		

⌨️ 快捷键说明

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