Results 1 to 2 of 2
  1. #1
    VanHelsing is offline Member
    Join Date
    Sep 2014
    Posts
    1
    Rep Power
    0

    Default JTextFields and adding data to ArrayList when enter button is pressed on the GUI

    Hello all,

    this is a very easy question to answer, it is just very hard for me to wrap my head around. I have a small program that has become a huge monster. I have three text fields to input last name, first name, and email. When I press the enter button I get the print out in the console but not in the text field I want the data to appear. For right now I need to figure out once the data is entered, how do I get that data and add it to my Array list. Listed below is the mess I have right now. If anyone can help it would be a huge benefit. Thank you all for your help.

    Java Code:
    private void enterButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // TODO add your handling code here:
            enterButton.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e) {
                    String lastName = lastNameTextField.getText();
                    String firstName = firstNameTextField.getText();
                    String email = emailTextField.getText();
                   
                    String text = lastName + ": " + firstName  + " : " + email + "\n";
                    
                    System.out.println(text);       
                   
                   
                    lastNameTextField.setText("");
                    firstNameTextField.setText("");  
                    emailTextField.setText("");
                }
                
            });

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: JTextFields and adding data to ArrayList when enter button is pressed on the GUI

    First off, don't add an ActionListener in an event handler.
    Second, learn some more basics before using IDE-generated code.

    Here: How to Use Buttons, Check Boxes, and Radio Buttons (The Javaâ„¢ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 1
    Last Post: 01-23-2013, 09:51 AM
  2. How to set button to be pressed more than once
    By ajs1351 in forum New To Java
    Replies: 20
    Last Post: 12-04-2011, 06:53 AM
  3. Replies: 0
    Last Post: 11-03-2011, 07:33 AM
  4. Checking if enter has been pressed on a text field
    By BoomPony in forum New To Java
    Replies: 1
    Last Post: 01-28-2011, 03:18 PM
  5. Detect the ENTER key being pressed
    By aaronfsimons in forum New To Java
    Replies: 12
    Last Post: 05-16-2009, 08:48 PM

Posting Permissions

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