View Full Version : Creating an Arraylist from JtextFields

04-19-2012, 04:05 PM
Hi im trying to Create an Arraylist From 6 jtextfields and 2 combo boxs so when i click the add button it will add the details to an array and not sure how to start This Wat I Have

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.ImageIcon;
import javax.swing.border.*;

public class newres extends JFrame

JComboBox combo;
JComboBox rooms;

JPanel p1 = new JPanel();
private JLabel newres ;
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
JPanel p4 = new JPanel();
private JButton Create,MainMenu,Delete, Quit;
private JTextField BookNum,CName,Dday,DMonth,DYear,nights;

public newres()

// setLayout(new GridLayout(1, 5, 5, 5));
p1.setLayout(new GridLayout(2,1));
p1.add(newres = new JLabel("Reservations Menu",JLabel.CENTER));
p1.setFont(new Font("Times-Roman", Font.BOLD, 40));

p2.setLayout(new GridLayout(6,0));
p2.add( new JLabel("BookingNumber\n"));
p2.add(BookNum = new JTextField(5));
p2.add(new JLabel("Name"));
p2.add(CName = new JTextField(20));
p2.add(new JLabel("Day"));
p2.add(Dday = new JTextField(20));
p2.add(new JLabel("Month"));
p2.add(DMonth = new JTextField(20));
p2.add(new JLabel("Year"));
p2.add(DYear = new JTextField(20));
p2.add(new JLabel("Nights"));
p2.add(nights = new JTextField(20));

p3.setLayout(new GridLayout(2,10));
String locations[] = {"Galway", "Sligo", "Dublin", "Letterkenny"};
p3.add(combo = new JComboBox(locations));
String type[] = {"Single", "Double", "Triple"};
p3.add(rooms = new JComboBox(type));

p4.add(Create = new JButton("Create"));
p4.add(Delete = new JButton("Delete"));
p4.add(MainMenu = new JButton("Main Menu"));

add(p1, BorderLayout.NORTH);

ListenerClass listener = new ListenerClass();


public static void main(String[] args)
newres frame = new newres();
frame.setTitle("Hotel Babylon");
frame.setSize(700, 500);
class ListenerClass implements ActionListener
public void actionPerformed(ActionEvent e)
if(e.getSource() == Create)

System.out.println("Test Create listener");

else if(e.getSource() == Delete)
System.out.println("Test Delete listener");
else if(e.getSource() == MainMenu)



04-19-2012, 05:10 PM
Are you looking to take each of these fields and add them as an object within the arraylist, or are you looking to take all these fields and submit the entire record as an object in the arraylist (ie: ArrayList<ArrayList<String>>)?

Also, in the future please wrap code with
tags. It retains the formatting so its easier to read.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum