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 9253999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:21:29+00:00 2026-06-18T11:21:29+00:00

The question is, I try to make second textfield (textFieldGen) to print out the

  • 0

The question is, I try to make second textfield (textFieldGen) to print out the exact result likes console. Currently, second textfield shows one string only.

This is my first coding on java GUI.
(extra info, I built it using Eclipse with WindowBuilder + GEF )

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.awt.TextField;
import java.awt.Label;
import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

public class PassGenerator {
private JFrame frmPasswordGenerator;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                PassGenerator window = new PassGenerator();
                window.frmPasswordGenerator.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the application.
 */
public PassGenerator() {
    initialize();
}

/**
 * Initialize the contents of the frame.
 */
private void initialize() {
    frmPasswordGenerator = new JFrame();
    frmPasswordGenerator.setTitle("Password Generator");
    frmPasswordGenerator.setBounds(100, 100, 419, 229);
    frmPasswordGenerator.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frmPasswordGenerator.getContentPane().setLayout(null);

    final TextField textFieldGen = new TextField();
    final TextField textFieldPass = new TextField();

    textFieldPass.setBounds(74, 60, 149, 19);
    frmPasswordGenerator.getContentPane().add(textFieldPass);

    Label labelPass = new Label("Password Length:");
    labelPass.setBounds(74, 33, 177, 21);
    frmPasswordGenerator.getContentPane().add(labelPass);

    Button genButton = new Button("Generate");
    genButton.setBounds(262, 60, 86, 23);
    frmPasswordGenerator.getContentPane().add(genButton);
    // Add action listener to button
    genButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
        // Execute when button is pressed
        //System.out.println("You clicked the button");
            String getTxt = textFieldPass.getText();
            boolean y = true;

            do{
                try{
                    int c = Integer.parseInt(getTxt);
                    Random r = new Random();
                    String[] alphabet = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","w","x","y","z"};
                    int nc = 0-c;
                    int c2 = c/2;
                    int nc2 = 0-c2;
                    int ncm = (nc+1)/2;

                    if (c%2 == 0){
                        for(int x = nc2; x<0;x++){
                            int alphaNum = r.nextInt(26);
                            System.out.print(alphabet[alphaNum]);
                            String alpha = alphabet[alphaNum];
                            textFieldGen.setText(alpha.toString());
                            int numNum = r.nextInt(10);
                            System.out.print(numNum);
                            textFieldGen.setText(Integer.toString(numNum));
                        }
                    }
                    else {
                        for(int x = ncm; x<0;x++){
                            int alphaNum = r.nextInt(26);
                            System.out.print(alphabet[alphaNum]);
                            String alpha = alphabet[alphaNum];
                            textFieldGen.setText(alpha.toString());
                            int numNum = r.nextInt(10);
                            System.out.print(numNum);
                            textFieldGen.setText(Integer.toString(numNum));
                        }
                        int numNum = r.nextInt(10);
                        System.out.print(numNum);
                        textFieldGen.setText(Integer.toString(numNum));
                    }
                    y = false;
                }
                catch (NumberFormatException e1 ){
                    int messageType = JOptionPane.PLAIN_MESSAGE;
                    JOptionPane.showMessageDialog(null, "Please Enter Integer only", "Error!!", messageType);
                    y = false;
                }
            }while (y);
        }
    });          

    Label labelGen = new Label("Generated Password:");
    labelGen.setBounds(74, 109, 149, 21);
    frmPasswordGenerator.getContentPane().add(labelGen);


    textFieldGen.setBounds(74, 136, 149, 19);
    frmPasswordGenerator.getContentPane().add(textFieldGen);

    Button copyButton = new Button("Copy");
    copyButton.setBounds(262, 136, 86, 23);
    frmPasswordGenerator.getContentPane().add(copyButton);  
}

}
  • 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-06-18T11:21:30+00:00Added an answer on June 18, 2026 at 11:21 am

    Use textFieldGen.setText (textFieldGen.getText () + "\n" + Integer.toString(numNum))

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am starting this question to try and make a central point developers can
This is my first question here so try to make my best so you
I don't want to create a vague question so I will try to make
Dumb question time: In the following request spec, I try to make sure that
Ok, so I'll try to make that question a little more simple. The core
Ok, I'm going to try to make this more clear because my last question
I am trying to make a simple quiz with just one question, I have
I will try to make my question sound as unconfusing as possible. I appologize
Two random question as I try to integerate Paypal IPN into my Codeigniter based
sorry for asking this dumb question i will try to explain as good as

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.