Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-19-2012, 04:05 PM   PM User | #1
GreenHand
New to the CF scene

 
Join Date: Apr 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
GreenHand is an unknown quantity at this point
Exclamation Creating an Arraylist from JtextFields

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);
add(p2,BorderLayout.CENTER);
add(p3,BorderLayout.EAST);
add(p4,BorderLayout.SOUTH);


ListenerClass listener = new ListenerClass();
Create.addActionListener(listener);
Delete.addActionListener(listener);
MainMenu.addActionListener(listener);


}


public static void main(String[] args)
{
newres frame = new newres();
frame.setTitle("Hotel Babylon");
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.pack();
}
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)
{
setVisible(false);

}


}
}
}
GreenHand is offline   Reply With Quote
Old 04-19-2012, 05:10 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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>>)?

Edit:
Also, in the future please wrap code with [code][/code] or [php][/php] tags. It retains the formatting so its easier to read.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:04 PM.


Advertisement
Log in to turn off these ads.