Mình tạo một giao diện có 2 Button , 1 cái để khi kích vào nó hiện ra một giao diện Nhập Bill , cái kia kích vào nó hiện thị là giao diện những sản phẩm.Mình muốn tất cả hiện thị trên một frame thôi
Mình tính removeAll giao diện cũ rồi mình add trong mỗi button một giao diện mới , nhưng removeAll nó xóa hết rồi những vẫn hiển thị hình ảnh trên giao diện.
package bill;
import java.awt.Component;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
public class SalesManageGUI extends JFrame implements ActionListener
{
private JLabel lbSB1,lbSB2, lbCus, lbDate, lbPay1,lbPay2,lbNote1,lbNote2,lbItem,lbNumber,lbTitle,lbTb1,lbTb2;
private JTextField txtSB1,txtSB2,txtCus,txtDate,txtPay1,txtPay2,txtItem,txtNumber;
private TextArea txtNote1,txtNote2;
private JButton btnAdd,btnRemove, btnSort,btnSave,btnEdit,btnReset,btnFind,btnItem,btnBill;
private JPanel pAll;
JTable tMain1,tMain2;
private JLabel lbTitle1,lbID,lbName,lbDis,lbNOI,lbNOP,lbPrice;
private JTextField txtID,txtName,txtDis,txtNOI,txtNOP,txtPrice;
private JPanel p1,p2,p3,p4,p5;
private JTable tMain ;
private JButton btnAdd2,btnEdit2,btnDelete2,btnInsert2,btnSave2 ;
private String[] column = {"ID Item","Name Item","Distributor","Price","Number Of Inventory","Note"} ;
private Object[][] data = new Object[50][50];
private Item[] item = new Item[100] ;
private Vector vTittle = new Vector() ;
private Vector vMain = new Vector();
private Vector vAdd ;
private DefaultTableModel dtm = new DefaultTableModel() ;
private int numberOfOrder ;
int t = 0 ;
public SalesManageGUI() {
super("Sale Manage") ;
super.setSize(1400,800);
super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
super.setVisible(true);
super.setLayout( null);
btnItem = new JButton("Status Item") ;
btnItem.setBounds(200,50,150,50);
btnBill = new JButton("Bill Manage") ;
btnBill.setBounds(50,50,150,50);
super.add(btnItem) ;
super.add(btnBill) ;
btnBill.addActionListener( new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
// superClear();
setFrame();
Font fontLb=new Font("Time new Roman",Font.PLAIN,16);
Font fontTb=new Font("Time new Roman",Font.BOLD, 22);
lbTb1=new JLabel("Bill Table");
lbTb1.setFont(fontTb);
lbTb1.setBounds(870,150,300,30);
lbTb2=new JLabel("Detail Bill Table");
lbTb2.setFont(fontTb);
lbTb2.setBounds(840,450,300,30);
lbTitle=new JLabel("Sale Manage");
Font font=new Font("Time new Roman",Font.BOLD,30);
lbTitle.setFont(font);
lbTitle.setBounds(650,20,400,35);
lbSB1=new JLabel("Bill Serial");
lbSB1.setFont(fontLb);
lbSB1.setBounds(50,200,100,20);
txtSB1=new JTextField();
txtSB1.setBounds(150,200,150,25);
lbCus=new JLabel("Customer");
lbCus.setFont(fontLb);
lbCus.setBounds(50,240,100,20);
txtCus=new JTextField();
txtCus.setBounds(150,240,150,25);
lbDate=new JLabel("Date");
lbDate.setFont(fontLb);
lbDate.setBounds(50,280,50,20);
txtDate=new JTextField();
txtDate.setBounds(150,280,150,25);
lbPay1=new JLabel("Payment");
lbPay1.setFont(fontLb);
lbPay1.setBounds(50,320,100,20);
txtPay1=new JTextField();
txtPay1.setBounds(150,320,150,25);
lbNote1=new JLabel("Note");
lbNote1.setFont(fontLb);
lbNote1.setBounds(385,200,50,20);
txtNote1=new TextArea();
txtNote1.setBounds(320,240,170,105);
String[] column1 = {"Ordinal Numbers","Bill ID","Customer","Date","Payment","Note"} ;
Object[][] data1 = {
} ;
tMain1 = new JTable(data1,column1) ;
JScrollPane table1 = new JScrollPane(tMain1) ;
table1.setBounds(500,200,800,200);
//txtPay,txtIdI,txtItem,txtNumber
lbSB2=new JLabel("Item Serial");
lbSB2.setFont(fontLb);
lbSB2.setBounds(50,500,100,20);
txtSB2=new JTextField();
txtSB2.setBounds(150,500,150,25);
lbItem=new JLabel("Item Name");
lbItem.setFont(fontLb);
lbItem.setBounds(50,540,100,20);
txtItem=new JTextField();
txtItem.setBounds(150,540, 150, 25);
lbNumber=new JLabel("Number");
lbNumber.setFont(fontLb);
lbNumber.setBounds(50,580,100,20);
txtNumber=new JTextField();
txtNumber.setBounds(150,580,150,25);
lbPay2=new JLabel("Payment");
lbPay2.setFont(fontLb);
lbPay2.setBounds(50,620,100,20);
txtPay2=new JTextField();
txtPay2.setBounds(150,620,150,25);
lbNote2=new JLabel("Note");
lbNote2.setFont(fontLb);
lbNote2.setBounds(385,500,50,20);
txtNote2=new TextArea();
txtNote2.setBounds(320,540,170,105);
//button
btnAdd = new JButton("Add") ;
btnAdd.setBounds(50,360,100,20);
String[] column2 = {"Ordinal Numbers","Bill ID","Item","Number","Payment","Note"} ;
Object[][] data2 = {
} ;
tMain2 = new JTable(data2,column2) ;
JScrollPane table2 = new JScrollPane(tMain2) ;
table2.setBounds(500,500,800,200);
superAdd(btnItem);
superAdd(btnAdd) ;
superAdd(lbTitle);
superAdd(lbSB1);
superAdd(txtSB1);
superAdd(lbCus);
superAdd(txtCus);
superAdd(lbDate);
superAdd(txtDate);
superAdd(lbPay1);
superAdd(txtPay1);
superAdd(lbNote1);
superAdd(txtNote1);
superAdd(lbSB2);
superAdd(txtSB2);
superAdd(lbItem);
superAdd(txtItem);
superAdd(lbNumber);
superAdd(txtNumber);
superAdd(lbPay2);
superAdd(txtPay2);
superAdd(lbNote2);
superAdd(txtNote2);
superAdd(lbTb1);
superAdd(lbTb2);
superAdd(table1);
superAdd(table2);
// t++ ;
}
});
btnItem.addActionListener( new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
// superClear();
setFrame();
Font f=new Font("Times New Roman",Font.BOLD,30);
lbTitle=new JLabel("ITEM");
lbTitle.setBounds(650,10,100,30);//x,y,chieu rong,chieu cao
lbTitle.setFont(f);
lbID=new JLabel("ID Item ");
lbID.setBounds(120,500,80,30);
txtID = new JTextField(5);
txtID.setBounds(200,500,150,30);
lbName = new JLabel("Name Item ") ;
lbName.setBounds(120,550,80,30);
txtName = new JTextField(5);
txtName.setBounds(200,550,150,30);
lbPrice = new JLabel("Price ") ;
lbPrice.setBounds(120,600,80,30);
txtPrice = new JTextField(5);
txtPrice.setBounds(200,600,150,30);
lbDis = new JLabel("Distributor") ;
lbDis.setBounds(400,500,80,30);
txtDis = new JTextField(5);
txtDis.setBounds(530,500,150,30);
lbNOI = new JLabel("Number of inventory") ;
lbNOI.setBounds(400,550,120,30);
txtNOI = new JTextField(5);
txtNOI.setBounds(530,550,150,30);
//set Button
btnAdd2 = new JButton("Add") ;
btnAdd2.setBounds(120,700,100,40);
btnEdit2 = new JButton("Edit");
btnEdit2.setBounds(270,700,100,40);
btnDelete2 = new JButton("Delete");
btnDelete2.setBounds(420,700,100,40);
btnInsert2 = new JButton("Insert");
btnInsert2.setBounds(570,700,100,40);
btnSave2 = new JButton("Save") ;
btnSave2.setBounds(720,700,100,40);
//setText for Table
tMain = new JTable(data,column) ;
JScrollPane table = new JScrollPane(tMain) ;
table.setBounds(100,60,1200,400);
//b3:them cac components vao Jframe
superAdd(table);
superAdd(lbTitle);
superAdd(lbName);
superAdd(txtName);
superAdd(lbID);
superAdd(txtID);
superAdd(lbPrice);
superAdd(txtPrice);
superAdd(lbDis);
superAdd(txtDis);
superAdd(lbNOI);
superAdd(txtNOI);
superAdd(btnAdd2);
superAdd(btnSave2) ;
superAdd(btnEdit2);
superAdd(btnDelete2);
superAdd(btnInsert2);
title() ;
btnAdd.addActionListener( new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
item[numberOfOrder] = new Item(txtID.getText(),txtName.getText(),txtDis.getText(),Integer.parseInt(txtPrice.getText()),Integer.parseInt(txtNOI.getText()),0) ;
addItem(item[numberOfOrder]);
dtm.setDataVector(vMain,vTittle);
tMain.setModel(dtm);
}
}) ;
// t++ ;
}
});
t++ ;
super.validate();
}
public void addItem(Item i) {
numberOfOrder++ ;
vAdd = new Vector() ;
vAdd.add(i.getId()) ;
vAdd.add(i.getNameOfItem()) ;
vAdd.add(i.getPrice()) ;
vAdd.add(i.getDistribor()) ;
vAdd.add(i.getNumberOfInventory()) ;
vMain.add(vAdd) ;
}
public void superAdd(Component comp) {
super.add(comp) ;
}
public void superClear() {
super.removeAll();
super.hide();
}
public void setFrame() {
super.removeAll();
super.hide();
super.setTitle("Sales Manage");
super.setSize(1400,800);
super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
super.setVisible(true);
super.setLayout( null);
btnItem = new JButton("Status Item") ;
btnItem.setBounds(200,50,150,50);
btnBill = new JButton("Bill Manage") ;
btnBill.setBounds(50,50,150,50);
super.add(btnItem) ;
super.add(btnBill) ;
super.validate();
}
public void title() {
vTittle.add("Serial Item") ;
vTittle.add("Name Item") ;
vTittle.add("Price Item") ;
vTittle.add("Price") ;
vTittle.add("Serial Item") ;
vTittle.add("Serial Item") ;
}
public static void main(String[] args) {
SalesManageGUI s= new SalesManageGUI();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
package bill;
import java.util.Scanner;
public class Item {
protected String nameOfItem,Id,distribor ;
protected int price ;
protected int numberOfPurchase,numberOfInventory ;
public Item() {
}
public Item(String id,String name,String distributor,int price,int purchase,int inventory) {
setId(id);
setNameOfItem(name);
setDistribor(distributor);
setPrice(price);
setNumberOfInventory(inventory);
setNumberOfPurchase(purchase);
}
public String getNameOfItem() {
return nameOfItem;
}
public void setNameOfItem(String nameOfItem) {
this.nameOfItem = nameOfItem;
}
public String getId() {
return Id;
}
public void setId(String id) {
Id = id;
}
public String getDistribor() {
return distribor;
}
public void setDistribor(String distribor) {
this.distribor = distribor;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getNumberOfPurchase() {
return numberOfPurchase;
}
public void setNumberOfPurchase(int numberOfPurchase) {
this.numberOfPurchase = numberOfPurchase;
}
public int getNumberOfInventory() {
return numberOfInventory;
}
public void setNumberOfInventory(int numberOfInventory) {
this.numberOfInventory = numberOfInventory;
}
public void input() {
Scanner kb = new Scanner(System.in) ;
System.out.print("Enter Id : ");
this.setId(kb.next());
System.out.print("Enter name of item : ");
this.setNameOfItem(kb.nextLine());
kb.nextLine() ;
System.out.print("Enter Distributor : ");
this.setDistribor(kb.nextLine());
System.out.println("Enter Price : ");
this.setPrice(kb.nextInt());
System.out.print("Enter number of inventory : ");
this.setNumberOfInventory(kb.nextInt());
System.out.print("Enter number of purchase : ");
this.setNumberOfPurchase(kb.nextInt());
}
public void output() {
System.out.println("ID : "+ this.Id);
System.out.println("Name of Item : "+this.nameOfItem);
System.out.println("Distributor : "+this.distribor);
System.out.println("Number Of Inventory : "+this.numberOfInventory);
System.out.println("Number Of Purchase : "+this.numberOfPurchase);
}
public double total() {
return this.price*this.numberOfPurchase ;
}
}