Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7561177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:05:55+00:00 2026-05-30T13:05:55+00:00

I am trying to create a program that allows you to create your own

  • 0

I am trying to create a program that allows you to create your own customized form. In one JFrame I have my code where it allows the user to enter the questions that will be on the form. In the other JFrame I want there to be a print out of what the actual form looks like.

I can’t get the Layout Managers to work correctly when I have my code like this:

public class WinMaker implements ActionListener, ItemListener {

// Define variables
public JLabel title;
public JButton submit;
public JButton create;
public JTextField question1;
public String q1;
public JTextField question2;
public JTextField question3;
public JTextField question4;
public JTextField question5;
public JTextField answer1;
public JTextField answer2;
public JTextField answer3;
public JTextField answer4;
public JTextField answer5;
public JLabel response1;
public JComboBox questions;
String[] question = { "1", "2", "3", "4", "5" };
JFrame j = new JFrame();
JFrame f = new JFrame();

public WinMaker() {

    title = new JLabel(
            "Select the # of questions in the form and write your questions in the space below:");

    questions = new JComboBox(question);
    questions.setSelectedIndex(4);
    questions.addItemListener(this);

    question1 = new JTextField(30);
    question2 = new JTextField(30);
    question3 = new JTextField(30);
    question4 = new JTextField(30);
    question5 = new JTextField(30);

    answer1 = new JTextField(15);
    answer2 = new JTextField(15);
    answer3 = new JTextField(15);
    answer4 = new JTextField(15);
    answer5 = new JTextField(15);

    create = new JButton("Create");
    create.setFont(new Font("Tahoma", Font.BOLD, 18));
    create.setBackground(Color.red);
    create.addActionListener(this);

    submit = new JButton("Submit"); // create JButton
    submit.addActionListener(this); // add actionlistener to JButton
            // Create layout
    j.setLayout(new GridLayout(8, 1));
    j.getContentPane();
    j.add(title);
    j.add(questions); //JComboBox

    j.add(question1); 

    q1 = question1.getText(); //I'm trying to get the text in the textfield and             
                                 store it in a string so I can print it out on the   
                                 next JFrame
    response1 = new JLabel(q1); 

    j.add(question2); //textfield
    j.add(question3);
    j.add(question4);
    j.add(question5);
    j.add(create); //create button

    j.setSize(300, 300); // dimensions of JFrame
    j.setTitle("WinMaker"); // title of JFrame
    j.setLocationRelativeTo(null);
    j.setResizable(true);
    j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    j.setVisible(true);


    f.setLayout(new FlowLayout());
    f.getContentPane();

    f.add(response1);  //text from string won't display
    f.add(answer1);

    f.add(question2); 
    f.add(answer2);

    f.add(question3); 
    f.add(answer3);

    f.add(question4); 
    f.add(answer4);

    f.add(question5); 
    f.add(answer5);

    f.setSize(300, 300); // dimensions of JFrame f.setTitle("WinMaker");
    f.setTitle("WinMaker Form"); // title of JFrame
    f.setLocationRelativeTo(null); 
    f.setResizable(true);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(false);
   }

   public static void main(String[] args) {
    new WinMaker();
   }
 }

Once I press a JButton I want another JFrame to launch that displays that questions the user has entered in the first JFrame. Any advice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:05:56+00:00Added an answer on May 30, 2026 at 1:05 pm

    One problem I see is that you’re trying to get the text from a JTextField in the GUI class’s constructor. This is before a user has had any time to enter the text so shouldn’t work (unless you pre-fill it which I don’t see you’re doing). You’ll want to add ActionListeners to your JTextField or a JButton and get the text from the JTextField after the user has entered it and pressed the JButton or pressed <Enter> in the JTextField triggering listener, not in the constructor. The Oracle Java Swing tutorials will show you how to do this.

    Edit
    Regarding your comment:

    In the first JFrame I have textfields where the users writes the questions that should be in the survey. Then on when a JButton is pressed it launches another JFrame that prints out those questions as well JTextfields for the person taking to survey to answer.

    This begs the question “better in what way?”.

    Things to consider include…

    • Creating a non-GUI Question class to encapsulate just what is a Question and what information does it hold.
    • I’d create a GUI with the goal of creating Question objects, perhaps putting them in an ArrayList.
    • I’d create a class for writing Questions to a file and also reading Questions out of a file.
    • Then I’d consider creating code for displaying Questions. I’d gear this code towards creating a JPanel not a JFrame. This way I can display it in a JDialog, or a JFrame or JApplet as desired.
    • Since the Questions are stored separate from your code, you have the option of displaying them any way you see fit, including use of reporting software.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a basic program that allows a user to create a
I'm trying to create a program that takes a text file of c++ code
I have been trying to create a Ruby program that will be running online
I'm trying to create a C++ program that allows me to read from a
I am trying to create a button on my access form that allows for
I am trying to run a test program that allows a user to click
I'm trying to create a scorecard program which allows the user to select cells
I'm new to graphics programming. I'm trying to create a program that allows you
I'm trying to create a feature in my program that allows users to download
I'm trying to understand threading better. If I create a program that allows people

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.