my task is to create a gui for a list of cars, bus,bicycle etc. and the program should be able to add and remove to the car in store. so i wrote this code below using netbeans IDE.
package vehicleregister;
import java.awt.*;
import java.awt.event.*;
public class VehicleRegister extends Frame implements WindowListener,ActionListener {
private Label label1;
private Label label2;
private Label label3;
private Label label4;
private Label label5;
private Label label6;
private Label label7;
private Button btnAddBuss;
private Button btnRemoveBuss;
private Button btnAddCar;
private Button btnRemoveCar;
private Button btnAddVan;
private Button btnRemoveVan;
private Button btnAddBicycle;
private Button btnRemoveBicycle;
private Button btnAddOthers;
private Button btnRemoveOthers;
private List stock;
private int carCount=50;
private int bussCount=40;
private int vanCount=60;
private int bicycleCount=55;
private int otherCount;
private TextField tf;
public VehicleRegister(String title){
super(title);
setBackground(SystemColor.YELLOW);
addWindowListener(this);
setLayout(null);
label1=new Label("CLICK THE CORRESPONDING ADD OR REMOVE BUTTON FOR THE TYPE");
label1.setBounds(55,50,450,30);
add(label1);
label2=new Label("OF VEHICLE YOU WANT TO ADD TO, OR REMOVE FROM THOSE IN STOCK");
label2.setBounds(55,70,450,30);
this.add(label2);
btnAddBuss=new Button("ADD");
btnAddBuss.setBounds(150,120,50,30);
btnAddBuss.addActionListener(this);
add(btnAddBuss);
btnRemoveBuss=new Button("REMOVE");
btnRemoveBuss.setBounds(250,120,60,30);
btnRemoveBuss.addActionListener(this);
add(btnRemoveBuss);
btnAddCar=new Button("ADD");
btnAddCar.setBounds(150,160,50,30);
btnAddCar.addActionListener(this);
add(btnAddCar);
btnRemoveCar=new Button("REMOVE");
btnRemoveCar.setBounds(250,160,60,30);
btnRemoveCar.addActionListener(this);
add(btnRemoveCar);
btnAddVan=new Button("ADD");
btnAddVan.setBounds(150,200,50,30);
btnAddVan.addActionListener(this);
add(btnAddVan);
btnRemoveVan=new Button("REMOVE");
btnRemoveVan.setBounds(250,200,60,30);
btnRemoveVan.addActionListener(this);
add(btnRemoveVan);
btnAddBicycle=new Button("ADD");
btnAddBicycle.setBounds(150,240,50,30);
btnAddBicycle.addActionListener(this);
add(btnAddBicycle);
btnRemoveBicycle=new Button("REMOVE");
btnRemoveBicycle.setBounds(250,240,60,30);
btnRemoveBicycle.addActionListener(this);
add(btnRemoveBicycle);
btnAddOthers=new Button("ADD");
btnAddOthers.setBounds(150,280,50,30);
btnAddOthers.addActionListener(this);
add(btnAddOthers);
btnRemoveOthers=new Button("REMOVE");
btnRemoveOthers.setBounds(250,280,60,30);
btnRemoveOthers.addActionListener(this);
add(btnRemoveOthers);
label3=new Label("BUSS");
label3.setBounds(55,120,60,30);
add(label3);
label4=new Label("CAR");
label4.setBounds(55,160,60,30);
add(label4);
label5=new Label("VAN");
label5.setBounds(55,200,60,30);
add(label5);
label6=new Label("BICYCLE");
label6.setBounds(55,240,60,30);
add(label6);
label7=new Label("OTHER");
label7.setBounds(55,280,60,30);
add(label7);
stock=new List();
stock.setBounds(25,320,500,50);
add(stock);
tf= new TextField();
add(tf);
tf.setBounds(350,120,150,60);
}
public static void main(String[] args) {
VehicleRegister frame = new VehicleRegister("VEHICLE REGISTER APPLICATION");
frame.setSize(550,400);
frame.setLocation(450,250);
frame.setVisible(true);
}
public void windowActivated(WindowEvent e) {
}
public void windowClosed(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
public void windowDeactivated(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowOpened(WindowEvent e) {
}
public void actionPerformed(ActionEvent e) {
int input;
if (e.getSource()==btnAddBuss)
{
input=Integer.parseInt(tf.getText());
bussCount=input + bussCount;
stock.removeAll();
stock.add("VEHICLES NOW IN STOCK");
stock.add("BUS "+bussCount);stock.add("CAR "+ carCount);stock.add("VAN "+ vanCount);
stock.add("BICYCLE "+ bicycleCount);stock.add("OTHER VEHICLE TYPE "+ otherCount);
}
else if (e.getSource()==btnRemoveBuss)
{
input=Integer.parseInt(tf.getText());
bussCount=bussCount - input;
stock.removeAll();
stock.add("VEHICLES NOW IN STOCK");
stock.add("BUS "+ bussCount);stock.add("CAR "+ carCount);stock.add("VAN "+ vanCount);
stock.add("BICYCLE "+ bicycleCount);stock.add("OTHER VEHICLE TYPE "+ otherCount);
}
else if (e.getSource()==btnAddCar)
{
input=Integer.parseInt(tf.getText());
carCount=input + carCount;
stock.removeAll();
stock.add("VEHICLES NOW IN STOCK");
stock.add("BUS "+ bussCount);stock.add("CAR "+ ++carCount);stock.add("VAN "+ vanCount);
stock.add("BICYCLE "+ bicycleCount);stock.add("OTHER VEHICLE TYPE "+ otherCount);
}
else if (e.getSource()==btnRemoveCar)
{
input=Integer.parseInt(tf.getText());
carCount=carCount - input;
stock.removeAll();
stock.add("VEHICLES NOW IN STOCK");
stock.add("BUS "+ bussCount);stock.add("CAR "+ carCount);stock.add("VAN "+ vanCount);
stock.add("BICYCLE "+ bicycleCount);stock.add("OTHER VEHICLE TYPE "+ otherCount);
}
else if (e.getSource()==btnAddVan)
{
input=Integer.parseInt(tf.getText());
vanCount=input + vanCount;
stock.removeAll();
stock.add("VEHICLES NOW IN STOCK");
stock.add("BUS "+ bussCount);stock.add("CAR "+ carCount);stock.add("VAN "+vanCount);
stock.add("BICYCLE "+ bicycleCount);stock.add("OTHER VEHICLE TYPE "+ otherCount);
}
else if (e.getSource()==btnRemoveVan)
{
input=Integer.parseInt(tf.getText());
vanCount=vanCount - input;
stock.removeAll();
stock.add("VEHICLES NOW IN STOCK");
stock.add("BUS "+ bussCount);stock.add("CAR "+ carCount);stock.add("VAN "+vanCount);
stock.add("BICYCLE "+ bicycleCount);stock.add("OTHER VEHICLE TYPE "+ otherCount);
}
else if (e.getSource()==btnAddBicycle)
{
input=Integer.parseInt(tf.getText());
bicycleCount=input + bicycleCount;
stock.removeAll();
stock.add("VEHICLES NOW IN STOCK");
stock.add("BUS "+ bussCount);stock.add("CAR "+ carCount);stock.add("VAN "+ vanCount);
stock.add("BICYCLE "+bicycleCount);stock.add("OTHER VEHICLE TYPE "+ otherCount);
}
else if (e.getSource()==btnRemoveBicycle)
{
input=Integer.parseInt(tf.getText());
bicycleCount=bicycleCount - input;
stock.removeAll();
stock.add("VEHICLES NOW IN STOCK");
stock.add("BUS "+ bussCount);stock.add("CAR "+ carCount);stock.add("VAN "+ vanCount);
stock.add("BICYCLE "+bicycleCount);stock.add("OTHER VEHICLE TYPE "+ otherCount);
}
else if (e.getSource()==btnAddOthers)
{
input=Integer.parseInt(tf.getText());
otherCount=input + otherCount;
stock.removeAll();
stock.add("VEHICLES NOW IN STOCK");
stock.add("BUS "+ bussCount);stock.add("CAR "+ carCount);stock.add("VAN "+ vanCount);
stock.add("BICYCLE "+ bicycleCount);stock.add("OTHER VEHICLE TYPE "+ otherCount);
}
else if (e.getSource()==btnRemoveOthers)
{
input=Integer.parseInt(tf.getText());
otherCount=otherCount - input;
stock.removeAll();
stock.add("VEHICLES NOW IN STOCK");
stock.add("BUS "+ bussCount);stock.add("CAR "+ carCount);stock.add("VAN "+ vanCount);
stock.add("BICYCLE "+ bicycleCount);stock.add("OTHER VEHICLE TYPE "+ otherCount);
}
}
}
But my task is to Use android environment but I dont know how to go about it. can anyone help me out?