What collection to use?

From my GUI press "Used Phone Acquisition" when enter is pressed the data will be saved and return to "select option".

Am i going to use queue or vector? and how to add

tf1.setText("");to EventHandler Cancel and Cancel2 to terminate data entry.

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.util.*;

publicclass HPhoneInvextends JFrame{

privateint currentCard = 1;

private JPanel cardPanel;

private CardLayout cl;

JPanel card1 =null;

JPanel card2 =null;

JPanel card3 =null;

public HPhoneInv(){

setTitle("Handphone Inventory System");

setSize(500, 160);

cardPanel =new JPanel(new CardLayout());

JPanel jp1 =new JPanel();

jp1.setLayout(new GridLayout(1,1) );

JLabel jl1 =new JLabel("Select Option:");

jl1.setForeground(Color.RED);

jp1.add(jl1);

JPanel buttonPanel =new JPanel();

buttonPanel.setLayout(new GridLayout(1,2) );

JButton AcqBtn=new JButton("Used Phone Acquisition");

JButton TranBtn=new JButton("Sale Transaction");

buttonPanel.add(AcqBtn);

buttonPanel.add(TranBtn);

card1 =new JPanel(new BorderLayout());

card1.add(jp1, BorderLayout.NORTH);

card1.add(buttonPanel, BorderLayout.SOUTH);

card2 =new JPanel(new BorderLayout());

JPanel jp2 =new JPanel();

jp2.setLayout(new GridLayout(5,2) );

JLabel lbl1 =new JLabel("Cust IC No:");

JLabel lbl2=new JLabel("Brand:");

JLabel lbl3 =new JLabel("Model:");

JLabel lbl4=new JLabel("Serial No:");

JLabel lbl5=new JLabel("Cost:");

JTextField tf1=new JTextField("");

JTextField tf2=new JTextField("");

JTextField tf3=new JTextField("");

JTextField tf4=new JTextField("");

JTextField tf5=new JTextField("");

jp2.add(lbl1);

jp2.add(tf1);

jp2.add(lbl2);

jp2.add(tf2);

jp2.add(lbl3);

jp2.add(tf3);

jp2.add(lbl4);

jp2.add(tf4);

jp2.add(lbl5);

jp2.add(tf5);

JPanel buttonPanel2 =new JPanel();

buttonPanel2.setLayout(new GridLayout(1,2) );

JButton EnterBtn=new JButton("Enter");

JButton CancelBtn=new JButton("Cancel");

buttonPanel2.add(EnterBtn);

buttonPanel2.add(CancelBtn);

card2.add(jp2, BorderLayout.NORTH);

card2.add(buttonPanel2, BorderLayout.SOUTH);

//card 3

card3 =new JPanel(new BorderLayout());

JPanel jp3 =new JPanel();

jp3.setLayout(new GridLayout(4,2) );

JLabel l1 =new JLabel("Serial No:");

JLabel l2 =new JLabel("Model:");

JLabel l3 =new JLabel("Price:");

JTextField t1=new JTextField("");

JTextField t2=new JTextField("");

JTextField t3=new JTextField("");

JTextField t4=new JTextField("");

JButton b =new JButton("Search for Phone Record");

jp3.add(l1);

jp3.add(t1);

jp3.add(b);

jp3.add(t2);

jp3.add(l2);

jp3.add(t3);

jp3.add(l3);

jp3.add(t4);

JPanel buttonPanel3 =new JPanel();

buttonPanel3.setLayout(new GridLayout(1,2) );

JButton Enter2Btn=new JButton("Enter");

JButton Cancel2Btn=new JButton("Cancel");

buttonPanel3.add(Enter2Btn);

buttonPanel3.add(Cancel2Btn);

card3.add(jp3, BorderLayout.NORTH);

card3.add(buttonPanel3, BorderLayout.SOUTH);

cardPanel.add(card1,"one");

cardPanel.add(card2,"two");

cardPanel.add(card3,"three");

this.getContentPane().add(cardPanel);

AcqBtn.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent arg0){

CardLayout cardLayout = (CardLayout)(cardPanel.getLayout());

cardLayout.show(cardPanel,"two");

}

});

TranBtn.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent arg0){

CardLayout cardLayout = (CardLayout)(cardPanel.getLayout());

cardLayout.show(cardPanel,"three");

}

});

EnterBtn.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent arg0){

CardLayout cardLayout = (CardLayout)(cardPanel.getLayout());

cardLayout.show(cardPanel,"one");

}

});

CancelBtn.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent arg0){

CardLayout cardLayout = (CardLayout)(cardPanel.getLayout());

cardLayout.show(cardPanel,"one");

}

});

Enter2Btn.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent arg0){

CardLayout cardLayout = (CardLayout)(cardPanel.getLayout());

cardLayout.show(cardPanel,"one");

}

});

Cancel2Btn.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent arg0){

CardLayout cardLayout = (CardLayout)(cardPanel.getLayout());

cardLayout.show(cardPanel,"one");

}

});

}

publicstaticvoid main(String[] args){

HPhoneInv cl =new HPhoneInv();

cl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

cl.pack();

cl.setVisible(true);

}

}

Message was edited by:

RockmanEXE

Message was edited by:

RockmanEXE

[9706 byte] By [RockmanEXEa] at [2007-11-27 10:43:43]
# 1

1. ArrayList is better than Vector because, among other things, it grows by 50% when it needs more space rather than 100%, so it is quite a bit more efficient and takes up less space.

2. If you are going to be looking at one item at a time from the first item they enter to the last item they enter, use a linked queue. When you remove an element from the front of an ArrayList, the remaining array list has to be shifted up; the same is not true with a linked queue.

jGardnera at 2007-7-28 20:02:03 > top of Java-index,Core,Core APIs...
# 2

jGardner is right. Also keep in mind that Vector is basically a synchronized version of ArrayList, for the most part. On top of ArrayList requiring more memory, it will also be faster because no synchronization routines are going on in the background. So unless you need synchronization, use ArrayList.

kmangolda at 2007-7-28 20:02:03 > top of Java-index,Core,Core APIs...
# 3

> On top of ArrayList requiring more memory

less memory

But if you want a queue, use something derived from java.util.Queue.

ejpa at 2007-7-28 20:02:03 > top of Java-index,Core,Core APIs...
# 4

At a later stage i will need algorithms in "Sale Transaction" to seach for model and seial num keyed in "used Phone Acquisiton" ,i still gonna use arraylist or vector or queue.

i have card layout in my listener,can show me how to add another action inside ,like in CancelHandler to clear entry.

e.g

tf1.setText("");

RockmanEXEa at 2007-7-28 20:02:03 > top of Java-index,Core,Core APIs...
# 5

> > On top of ArrayList requiring more memory

>

> less memory

Yes, a typo, sorry.

kmangolda at 2007-7-28 20:02:03 > top of Java-index,Core,Core APIs...