?? ioform.java
字號:
package good;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class Ioform extends JFrame {
private static final Component InPrice = null;
private Inventory inventory = new Inventory(100);
private Invoice invoice = new Invoice(inventory);
final JTextArea textArea_1 = new JTextArea(); //顯示存貨單的信息
final JTextArea textArea_2 = new JTextArea(); //顯示提貨單的信息
Imanufacturer supply=new Imanufacturer();
Employee employee =new Employee();
Client client=new Client();
Goods goods=new Goods();
Goods price_1=new Goods();
Goods price_2=new Goods();
//boolean inventoryFlag=false;
boolean invoiceFlag=false;
public Ioform() {
super();
setTitle("商品庫存管理系統");
final JTabbedPane tabbedPane = new JTabbedPane();
final JPanel panel_1 = new JPanel();
final JPanel panel_2 = new JPanel();
final JScrollPane scrollPane_1 = new JScrollPane(textArea_1);
final JScrollPane scrollPane_2 = new JScrollPane(textArea_2);
final JComboBox id_1 = new JComboBox(goods.GetAllGoodId()); //存貨單某項的ID
final JComboBox supplyName = new JComboBox(supply.GetAllSupplyName());
final JComboBox employeeId = new JComboBox(employee.GetAllemployeeId());
final JTextField number_1 = new JTextField(4); //欲修改的存貨單某項的數量
//final JTextField price_1=new JTextField("",10);
final JTextField indate=new JTextField(" ",10);
//final JTextField id_2 = new JTextField(4); //提貨單某項的ID
final JComboBox id_2 = new JComboBox(goods.GetAllGoodId());
final JTextField number_2 = new JTextField(4); //欲修改的提貨單某項的數量
final JComboBox clientName = new JComboBox(client.GetAllclientName());
final JComboBox employeeId_2 = new JComboBox(employee.GetAllemployeeId());
final JTextField outdate=new JTextField("",10);
final JTextField outprice=new JTextField("",10);
final JPanel panelButton_1 = new JPanel();
final JPanel panelButton_2 = new JPanel();
final JPanel panelInput_1 = new JPanel();
final JPanel panelInput_2 = new JPanel();
final JButton inventoryAddButton = new JButton();
final JButton inventoryRemoveButton = new JButton();
final JButton invoiceAddButton = new JButton();
final JButton invoiceDeleteButton = new JButton();
getContentPane().add(tabbedPane, BorderLayout.CENTER);
tabbedPane.add("存貨單", panel_1);
tabbedPane.add("提貨單", panel_2);
panel_1.setLayout(new BorderLayout());
panel_1.add(scrollPane_1, BorderLayout.CENTER);
panel_1.add(panelButton_1, BorderLayout.SOUTH);
panel_1.add(panelInput_1, BorderLayout.NORTH);
panelInput_1.setLayout(new GridLayout(1,6));
panelInput_1.add(new JLabel(" 存貨單ID:"));
panelInput_1.add(id_1);
panelInput_1.add(new JLabel(" 商品數量:"));
panelInput_1.add(number_1);
panelInput_1.add(new JLabel(" 供應商名稱:"));
panelInput_1.add(supplyName);
panelInput_1.add(new JLabel(" 雇員ID:"));
panelInput_1.add(employeeId);
//panelInput_1.add(new JLabel(" 價格"));
//panelInput_1.add(price_1);
panelInput_1.add(new JLabel(" 進貨日期"));
panelInput_1.add(indate);
//panelButton_1.setLayout(new GridLayout(1,6));
panelButton_1.add(inventoryAddButton);
inventoryAddButton.setText("增加商品數量");
//panelButton_1.add(inventoryRemoveButton);
inventoryRemoveButton.setText("減少商品數量");
textArea_1.setEditable(false);
scrollPane_1.setViewportView(textArea_1);
panel_2.setLayout(new BorderLayout());
panel_2.add(scrollPane_2, BorderLayout.CENTER);
panel_2.add(panelButton_2, BorderLayout.SOUTH);
panel_2.add(panelInput_2, BorderLayout.NORTH);
panelInput_2.add(new JLabel("提貨單某項的ID:"));
panelInput_2.add(id_2);
panelInput_2.add(new JLabel("商品數量:"));
panelInput_2.add(number_2);
panelInput_2.add(new JLabel(" 客戶名稱:"));
panelInput_2.add(clientName);
panelInput_2.add(new JLabel("雇員ID:"));
panelInput_2.add(employeeId_2);
panelInput_2.add(new JLabel("出貨價格:"));
panelInput_2.add(outprice);
panelInput_2.add(new JLabel("出貨日期:"));
panelInput_2.add(outdate);
panelButton_2.add(invoiceAddButton);
invoiceAddButton.setText("增加提貨單");
panelButton_2.add(invoiceDeleteButton);
invoiceDeleteButton.setText("刪除提貨單");
this.setBounds(100, 100, 800,600);
this.setVisible(true);
textArea_2.setEditable(false);
scrollPane_2.setViewportView(textArea_2);
refreshInventory();
refreshInvoice();
inventoryAddButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
inventory.addUnits(id_1.getSelectedItem().toString(), Integer
.parseInt(number_1.getText()));
inventory.setEmployeeId(employeeId.getSelectedItem().toString());
inventory.setGoodId(id_1.getSelectedItem().toString());
inventory.setNumber(Integer.parseInt(number_1.getText()));
inventory.setSupplyName(supplyName.getSelectedItem().toString());
inventory.setInPrice(Double.parseDouble(number_1.getText()));
inventory.setDate(indate.getText());
inventory.InventoryAdd();
//invoiceFlag=true;
} catch (NumberFormatException e1) {
JOptionPane.showMessageDialog(null, "輸入的商品數量錯誤!", "警告",
JOptionPane.ERROR_MESSAGE);
}
refreshInventory();
}
});
inventoryRemoveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
inventory.removeUnits(id_1.getSelectedItem().toString(),
Integer.parseInt(number_1.getText()));
} catch (NumberFormatException e1) {
JOptionPane.showMessageDialog(null, "輸入的商品數量錯誤!", "警告",
JOptionPane.ERROR_MESSAGE);
}
refreshInventory();
}
});
invoiceAddButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
boolean flag;
try {
flag=invoice.addItem(id_2.getSelectedItem().toString(), Integer.parseInt(number_2
.getText()),Double.parseDouble(outprice.getText()));
if (flag)
{
invoice.setEmployeeId(employeeId.getSelectedItem().toString());
invoice.setGoodId(id_2.getSelectedItem().toString());
invoice.setOutnumber(Integer.parseInt(number_2.getText()));
invoice.setClientname(clientName.getSelectedItem().toString());
invoice.setOutPrice(Double.parseDouble(outprice.getText()));
invoice.setOutdate(outdate.getText());
invoice.Invoicedele();
invoiceFlag=true;
}
} catch (NumberFormatException e1) {
JOptionPane.showMessageDialog(null, "輸入的商品數量錯誤!", "警告",
JOptionPane.ERROR_MESSAGE);
}
refreshInvoice();
//refreshInventory();
}
});
invoiceDeleteButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
invoice.delItem(id_2.getSelectedItem().toString());
refreshInvoice();
}
});
}
//刷新存貨單的顯示結果
public void refreshInventory() {
String str = null;
String title="商品ID\t 數量 * 價格\t\t 商品名稱 ";
for (int i = 0; i < inventory.list.length; i++) {
str = inventory.toString() + "\n";
}
textArea_1.setText(title+"\n"+str);
/*if (invoiceFlag)
{
refreshInvoice();
invoiceFlag=false;
}*/
}
//刷新提貨單的顯示結果
public void refreshInvoice() {
String str = null;
String title="商品ID\t 數量 * 價格\t\t 商品名稱 ";
for (int i = 0; i < invoice.list.length; i++) {
str = invoice.toString() + "\n";
}
textArea_2.setText(title+"\n"+str);
if (invoiceFlag)
{
refreshInventory();
invoiceFlag=false;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -