title: Programming a JButton to create an object when clicked
body: <p>EDIT: I want this window to be able to create multiple user profiles, so it needs to create more variables than just u1. The idea of the program is to mimic a social network. I don't know how to do this, however. Thanks!</p>
  
  <p>I'm new to java GUI. So far, I have created a window with four text fields inside: first name, last name, gender, and hometown. I want to now create a button that takes the strings entered in those 4 text fields, and creates an object from them using this constructor:</p>
  
  <pre><code>//object constructor
  public UserProfile(String fn, String ln, String g, String h) {
      firstName = fn;
      lastName = ln;
      fullName = fn + ' ' + ln;
      gender = g;
      homeTown = h;
  }
  </code></pre>
  
  <p>Here is my CreateProfile class so far. The relevant code for the button is at the bottom, and I'm pretty sure it's wrong / inefficient.</p>
  
  <pre><code>import java.awt.FlowLayout;
  import java.awt.event.ActionListener;
  import java.awt.event.ActionEvent;
  import javax.swing.*;
  
  /* Window for creating a UserProfile */
  public class CreateProfile extends JFrame {
  
      private JLabel jl1;
      public JTextField tf1;
  
      private JLabel jl2;
      public JTextField tf2;
  
      private JLabel jl3;
      public JTextField tf3;
  
      private JLabel jl4;
      public JTextField tf4;
  
      public JButton jb;
  
      public CreateProfile() {   // constructor for the window
          super("Create Your FaceSpace Profile");
          setLayout(new FlowLayout());
  
          jl1 = new JLabel("First name: ");
          tf1 = new JTextField(null, 10);
          add(jl1);add(tf1);
  
          jl2 = new JLabel("Last name: ");
          tf2 = new JTextField(null, 10);
          add(jl2);add(tf2);
  
          jl3 = new JLabel("Gender (M/F): "); // make drop down
          tf3 = new JTextField(null, 10);
          add(jl3);add(tf3);
  
          jl4 = new JLabel("Hometown: ");
          tf4 = new JTextField(null, 10);
          add(jl4);add(tf4);
  
          /* Button that creates a UserProfile object given the four text fields */
          jb = new JButton("Create Profile!");
          add(jb);
          jb.addActionListener(this);
  
      }
  
      private class buttonEvent implements ActionListener {
  
          public void action(ActionEvent e) {
              String command = e.getActionCommand();
              if(command.equals("jb")) {
                  // Code in question
                  String fn = tf1.getText().trim();
                  String ln = tf2.getText().trim();
                  String g = tf3.getText().trim();
                  String ht = tf4.getText().trim();
                  UserProfile u1 = new UserProfile(fn,ln,g,ht);
              }
          }
  
      }
  
  }
  </code></pre>