how to use ArrayList

hello.

this is james mcfadden. i am totally new to ArrayList. how do i modify the following two pieces of code so that i can use ArrayList?

thanks for the help.

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.sql.*;

import java.util.*;

publicclass ProductFormextends JFrame{

JPanel pnlTitle,pnlBody,pnlFooter;

JButton btnDBAdd=new JButton("Add");

JButton btnDBEdit=new JButton("Edit");

JButton btnDBDelete=new JButton("Delete");

JLabel[] lblForm=new JLabel[14];

JLabel lblTitle=new JLabel("Product Form");

JTextField[] txtFlds=new JTextField[60];

String[] listFormNames={"Product Number","Name","Rental Price","Age Category","Type","Year"};

Container contentpane;

int productNumber;

String name;

float rentalPrice;

String ageCategory;

String type;

int year;

DBController dbc=new DBController();

Product p=new Product();

public ProductForm(){

super("Product");

contentpane=getContentPane();

contentpane.setLayout(new BorderLayout());

pnlTitle=new JPanel();

pnlBody=new JPanel();

pnlFooter=new JPanel();

pnlBody.setLayout(new GridLayout(listFormNames.length,2,20,20));

for(int i=0;i<listFormNames.length;i++){

lblForm[i]=new JLabel(listFormNames[i]);

pnlBody.add(lblForm[i]);

txtFlds[i]=new JTextField(25);

pnlBody.add(txtFlds[i]);

}

lblTitle.setForeground(Color.RED);

pnlTitle.add(lblTitle);

pnlFooter.add(btnDBAdd);

pnlFooter.add(btnDBEdit);

pnlFooter.add(btnDBDelete);

contentpane.add(pnlTitle,BorderLayout.NORTH);

contentpane.add(pnlBody,BorderLayout.CENTER);

contentpane.add(pnlFooter,BorderLayout.SOUTH);

pack();

setVisible(true);

btnDBAdd.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent e){

//get the product number

String s=txtFlds[0].getText();

p.setProductNumber(Integer.parseInt(s));

//get the product name

p.setName(txtFlds[1].getText());

//get the rental price

String s2=txtFlds[2].getText();

float f=Float.parseFloat(s2);

p.setRentalPrice(f);

//get the age category

p.setAgeCategory(txtFlds[3].getText());

p.setType(txtFlds[4].getText());

String s3=txtFlds[5].getText();

p.setYear(Integer.parseInt(s3));

dbc.makeConnection();

dbc.setHostURL();

dbc.insertProduct(p);

dbc.closeDB();

}

});

btnDBEdit.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent e){

//get the product number

String s=txtFlds[0].getText();

p.setProductNumber(Integer.parseInt(s));

//get the product name

p.setName(txtFlds[1].getText());

dbc.makeConnection();

dbc.setHostURL();

dbc.editProduct(p);

dbc.closeDB();

}

});

btnDBDelete.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent e){

dbc.makeConnection();

dbc.setHostURL();

dbc.deleteProduct(p);

dbc.closeDB();

}

});

}

publicvoid getInput(){

Scanner sc =new Scanner(System.in);

int i = sc.nextInt();

}

}

publicclass Product{

int productNumber;

String name;

float rentalPrice;

String ageCategory;

String type;

int year;

//setters

publicvoid setProductNumber(int a){

this.productNumber = a;

}

publicvoid setName(String b){

this.name = b;

}

publicvoid setRentalPrice(float c){

this.rentalPrice = c;

}

publicvoid setAgeCategory(String d){

this.ageCategory = d;

}

publicvoid setType(String e){

this.type = e;

}

publicvoid setYear(int f){

this.year = f;

}

//getters

publicint getProductNumber(){

return this.productNumber;

}

public String getName(){

return this.name;

}

publicfloat getRentalPrice(){

return this.rentalPrice;

}

public String getAgeCategory(){

return this.ageCategory;

}

public String getType(){

return this.type;

}

publicint getYear(){

return this.year;

}

}

>

[8838 byte] By [james-mcfaddena] at [2007-11-27 8:52:06]
# 1
Don't crosspost.Stick to your original thread. http://forum.java.sun.com/thread.jspa?threadID=5188725
jverda at 2007-7-12 21:06:55 > top of Java-index,Java Essentials,New To Java...