help plz ... Building GUI
can you help me please?
My code Purpose witch allows me to store keys and objects In the hashtable
A dealer maintains a list (hash table) of cars for sale. The first column in the table will contain VRN numbers and the second column Car4Sale objects
here is the code:
import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.util.*;
publicclass BuyCarextends JFrameimplements ActionListener
{
JPanel panel;
JTextField jt_IName,jt_ICode,jt_Price,jt_color,jt_Sprice;//TEXT BOXES
JButton btn_Add,btn_Cancel;//BUTTONS
JLabel lbl_IName,lbl_ICode,lbl_Price,lbl_color,lbl_Sprice;// LABELS
public BuyCar()
{
super("Buy-New Car");// WINDOW TITLE
panel=new JPanel();
panel.setLayout(null);
//LABELS DEFINITIONS
lbl_IName=new JLabel("VRN No :");
lbl_ICode=new JLabel("Manufacturer :");
lbl_Price=new JLabel("Engine Size :");
lbl_color=new JLabel("Color :");
lbl_Sprice=new JLabel("Price :");
//TEXTBOXES DEFINITION
jt_IName=new JTextField();
jt_ICode=new JTextField();
jt_Price=new JTextField();
jt_color=new JTextField();
jt_Sprice=new JTextField();
//BUTTONS DEFINITION
btn_Add=new JButton("ADD");
btn_Add.addActionListener(this);
btn_Cancel=new JButton("CANCEL");
btn_Cancel.addActionListener(this);
//SET THE SIZE & LOCATION
lbl_IName.setBounds(15,20,180,20);
jt_IName.setBounds(100,20,150,20);
lbl_ICode.setBounds(15,45,180,20);
jt_ICode.setBounds(100,45,150,20);
lbl_Price.setBounds(15,70,180,20);
jt_Price.setBounds(100,70,150,20);
lbl_color.setBounds(15,95,180,20);
jt_color.setBounds(100,95,150,20);
lbl_Sprice.setBounds(15,120,180,20);
jt_Sprice.setBounds(100,120,150,20);
btn_Add.setBounds(80,180,60,20);
btn_Cancel.setBounds(150,180,80,20);
//ADD ALL FIELDS TO PANEL
panel.add(lbl_IName);
panel.add(jt_IName);
panel.add(lbl_ICode);
panel.add(jt_ICode);
panel.add(lbl_Price);
panel.add(jt_Price);
panel.add(lbl_color);
panel.add(jt_color);
panel.add(lbl_Sprice);
panel.add(jt_Sprice);
panel.add(btn_Add);
panel.add(btn_Cancel);
//SET PANEL PROPERTIES
panel.setBackground(new Color(169,202,223));
panel.setBorder(new BevelBorder(BevelBorder.RAISED));
//SET WINDOW PROPERTIES
getContentPane().add(panel,BorderLayout.CENTER);
setLocation(200,200);
setSize(400,300);
setVisible(true);
setResizable(false);
}
publicvoid actionPerformed(ActionEvent e)
{
Object comm=e.getSource();
// CLICK ADD BUTTON
if(comm==btn_Add)
{
String str_SName,str_SCode,str_SPrice;
//ASSIGN THE VALUES TO VARIABLES
str_SName=jt_IName.getText();
str_SCode=jt_ICode.getText();
str_SPrice=jt_Price.getText();
//CHECK WHETHER THE VALUE IS NULL OR NOT
if(str_SName.equals(""))
{
JOptionPane.showMessageDialog(null,"Enter Var Number","ERROR",JOptionPane.ERROR_MESSAGE);
jt_IName.requestFocus();
}
elseif(str_SCode.equals(""))
{
JOptionPane.showMessageDialog(null,"Enter Manuacrer Name","ERROR",JOptionPane.ERROR_MESSAGE);
jt_ICode.requestFocus();
}
elseif(str_SPrice.equals(""))
{
JOptionPane.showMessageDialog(null,"Enter Engine Size","ERROR",JOptionPane.ERROR_MESSAGE);
jt_Price.requestFocus();
}
else
{
try
{}
catch(Exception se)
{
//System.out.print(se.toString());
}
}
}
elseif(comm==btn_Cancel)
{
dispose();// CLOSE THE WINDOW
}
}
publicstaticvoid main (String [] args){
new BuyCar();
}
}
when I click the Add "button", the Var No and Car object shoud be added to the hashtable which consist a list of cars and thier Var No...
the Var No will be the Key.
I should add another button "View". When I click this button the car list (hashtable) should
be displayed on the screen
How can I do the hashtable in the GUI...
How can I Add and delete from hashtable.
thanks

