Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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);

    }


    }
    }
    }

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •