Quote
I have an existing array with 4 elements. I am creating an add button and using the ArrayList to copy the array and what ever else I add. Then I want to return it to the original array. I am unable to modify any of my classes. I am working inside the gui area.
I think the problem is my setup or a casting issue. Can someone help? I have example and add button code.
I think the problem is my setup or a casting issue. Can someone help? I have example and add button code.
Example:
import java.util.*;
public class Sample
{
public static void main(String[] args)
{
String[] x = new String[] {"Asia", "Europe", "Africa"};
System.out.println("Length of x ="+x.length);
ArrayList xv = new ArrayList();
for (int i = 0; i < x.length; i++)
xv.add(x[i]);
xv.add("Australia");
System.out.println("Length of xv ="+xv.size());
x = new String[xv.size()];
xv.toArray(x);
System.out.println("Length of x ="+x.length);
}
}
MyCode:
//ADD Button
class AddButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
// updateAButton( inventory);
ArrayList<NameRestock> xv = new ArrayList<NameRestock>();
for (i = 0; i < inventory.length;i++)
{
xv.add(inventory[i]);
System.out.println("Length" + xv.size());
}
int iItem = Integer.parseInt(JOptionPane.showInputDialog("Enter Item Number: "));
String Mtrl = JOptionPane.showInputDialog(null, "Enter Material Name :");
int Amnt = Integer.parseInt(JOptionPane.showInputDialog("Enter count of product: "));
double cost = Double.parseDouble(JOptionPane.showInputDialog("Enter cost: $ "));
String store = JOptionPane.showInputDialog("Enter Purchase Store :");
// xv.add(new NameRestock(5,"Glue",2,5.00,"GlueShop"));
xv.add(new NameRestock(iItem, Mtrl, Amnt, cost, store));
System.out.println("Length Now " + xv.size());
System.out.println("Length of inventory = " + inventory.length);
}
} //end ADD Button

New Topic/Question
Reply




MultiQuote






|