Jump to content
  private String char_list = "Woodcutting";

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        getLength = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        showPass = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Enter Length");

        jButton1.setText("Generate");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addComponent(jLabel1)
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(getLength, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(showPass, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(71, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(51, 51, 51)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(getLength, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(showPass, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(48, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        
        
        int string_length = Integer.parseInt(getLength.getText());
        StringBuilder str = new StringBuilder();
        for(int i=0;i<string_length;i++){
            int num = getRandomNum();
            char ch = char_list.charAt(num);
            str.append(ch);
        }
        showPass.setText(str.toString());
        
        
        
    }                                        

    private int getRandomNum(){
        int randomInt = 0;
        Random randomGenerator = new Random();
        randomInt = randomGenerator.nextInt(char_list.length());
        if(randomInt -1 == -1){
            return randomInt;
        }
        else
            return randomInt-1;
        
    }

So i was supposed to do Word generator with words like Woodcutting,Agility,Fishing. etc but  this just generates random characters ? does anyone have any clue how i can generate words. Thanks in advance, for any questions i try answer fast as possible

Link to comment
https://linustechtips.com/topic/864856-java-word-generator/
Share on other sites

Link to post
Share on other sites

I'm guess this homework? You've posted a lot regarding Java. Maybe you nee to learn yourself. Sorry for being blunt. You need to work on your own. 

CPU: AMD Ryzen 5 5600X | CPU Cooler: Stock AMD Cooler | Motherboard: Asus ROG STRIX B550-F GAMING (WI-FI) | RAM: Corsair Vengeance LPX 32 GB (4x 8 GB) DDR4-3000 CL16 | GPU: Nvidia GTX 1060 6GB Zotac Mini | Case: K280 Case | PSU: Cooler Master B600 Power supply | SSD: 1TB  | HDDs: 1x 250GB & 1x 1TB WD Blue | Monitor: 24" Acer S240HLBID | OS: Win 11 Pro.

 

Home Lab:  Lenovo ThinkCenter M82 Hyper-V Server 2022 | Dell OptiPlex 9020 Hyper-V Server 2022 | TP-LINK TL-SG108E | Cisco Catalyst C2960CG 8 Port Switch | HP MicroServer G8 SCCM Server | 2x Dell PowerEdge R630 Hyper-V Server 2022

 

 

Link to comment
https://linustechtips.com/topic/864856-java-word-generator/#findComment-10744179
Share on other sites

Link to post
Share on other sites

Just now, Abdul201588 said:

I'm guess this homework? You've posted a lot regarding Java. Maybe you nee to learn yourself. Sorry for being blunt. You need to work on your own. 

This isnt homework just my own project so i could learn java bit better by making java things that are interesting

Link to comment
https://linustechtips.com/topic/864856-java-word-generator/#findComment-10744182
Share on other sites

Link to post
Share on other sites

4 hours ago, bomberblyat said:

for(int i=0;i<string_length;i++){ int num = getRandomNum(); char ch = char_list.charAt(num); str.append(ch); }

this literally just loops in till the length of string_length adding a random chat for char_list. 

 

How did you expect it to do anything else? 

4 hours ago, bomberblyat said:

This isnt homework just my own project so i could learn java bit better by making java things that are interesting

even still as @Abdul201588 said maybe its time to actually learn some java because its pretty clear what that loop does.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
https://linustechtips.com/topic/864856-java-word-generator/#findComment-10744848
Share on other sites

Link to post
Share on other sites

2 hours ago, vorticalbox said:

this literally just loops in till the length of string_length adding a random chat for char_list. 

 

How did you expect it to do anything else? 

even still as @Abdul201588 said maybe its time to actually learn some java because its pretty clear what that loop does.

i dont know im noob 

Link to comment
https://linustechtips.com/topic/864856-java-word-generator/#findComment-10745387
Share on other sites

Link to post
Share on other sites

15 hours ago, bomberblyat said:

i dont know im noob 

being a "noob" is fine, everyone is a noob at some point. I suggest doing an online java course so you can get the basic logic down. input, output, loops, ifs and so on. 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
https://linustechtips.com/topic/864856-java-word-generator/#findComment-10748056
Share on other sites

Link to post
Share on other sites

4 hours ago, vorticalbox said:

...so you can get the basic logic...

Indeed, if you are struggling with even basic flow control such as loops then you really need to concentrate on walking before trying to run.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
https://linustechtips.com/topic/864856-java-word-generator/#findComment-10748627
Share on other sites

Link to post
Share on other sites

1 minute ago, fpo said:

Codecademy.com teaches this for free. 

 

This may very well be the ONE TIME people will agree.... 

On that we can indeed agree, it seems good for learning syntax and flow control xD You may well find what you need there. After mastering some of the basics if you are looking for more real world based problem solving then I'd suggest having a look at Codewars.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
https://linustechtips.com/topic/864856-java-word-generator/#findComment-10748756
Share on other sites

Link to post
Share on other sites

7 hours ago, vorticalbox said:

being a "noob" is fine, everyone is a noob at some point. I suggest doing an online java course so you can get the basic logic down. input, output, loops, ifs and so on. 

Alright, thanks for advises, i know how to do basic java pretty well but im quite new on GUI java things, ill definetly do researching, as this is my project to make me better on java.

 

Link to comment
https://linustechtips.com/topic/864856-java-word-generator/#findComment-10749182
Share on other sites

Link to post
Share on other sites

44 minutes ago, bomberblyat said:

Alright, thanks for advises, i know how to do basic java pretty well but im quite new on GUI java things, ill definetly do researching, as this is my project to make me better on java.

 

Well  GUI just maps functions to a graphical representation for the user to see.

 

should as pressing a button to do an action or getting input from the user. Instead of that input being in the command line you have a text box. 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
https://linustechtips.com/topic/864856-java-word-generator/#findComment-10749362
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×