1

Im a newcomer :) However, my program has a table and a RandomGen should get the highest random int by getRowCount -> checkvar1.

Now, the main class gets checkvar1 and sends it to setVariable(), then I want to exchange this checkvar1 with randomGen to limit the maximum generated integer.

So this of course doesn't work because the parameters in randomGen() aren't set and I cannot set them, because then the exchange to the onActionPerformed() method in my main class doesn't work anymore.

public final class RandomGen
{
    // EXCHANGE OF CHECKVAR1 FOR RANDOM GEN
    public static void setVariable(int checkvar1)
    {
        System.out.print(checkvar1);
    }

    // RANDOM GENERATOR
    public static int randomGen()
    {
        Random rand = new Random();
        int var1 = rand.nextInt(checkvar1) + 1;
        return var1;
    }
}

Here my main class:

public void onActionPerformed(java.awt.event.ActionEvent evt) {                                             


        //NUMBER OF LAST ROW
        int checkvar1 = (Integer)jTable1.getRowCount();

        //->EXCHANGE WITH setVariable()

        RandomGen.setVariable(checkvar1);

        if (checkvar1 >= 3) {
            int recogvar1 = checkvar1 - 1;            
            Object checkobj1 = jTable1.getModel().getValueAt(recogvar1, 0);

            if (checkobj1 == null){
                //...
            }               
            else {

            int var1 = RandomGen.variable();

            String result = var1 + "";
            jTextField1.setText(result);
            //System.out.print(result);
            }

        }
        else {
            String rule2 = "At least " + 3 + " rows should be filled";
            jTextField1.setText(rule2);            
        }
KatharsisHerbie
  • 115
  • 1
  • 10

1 Answers1

0

You are doing nothing with your setVariable in your class RandomGen. So You only need to change this.

// RANDOM GENERATOR
public static int randomGen(int checkvar1)
{
    Random rand = new Random();
    int var1 = rand.nextInt(checkvar1) + 1;
    return var1;
}

And in your main Method try this.

    //NUMBER OF LAST ROW
    int checkvar1 = (Integer)jTable1.getRowCount();

    //->EXCHANGE WITH randomGenerator
     checkvar1 = RandomGen.randomGen(checkvar1);
Gatusko
  • 2,503
  • 1
  • 17
  • 25
  • tanks - yes. But I get this error caused by the parameters in randomGen(int checkvar1) in main class at "int var1 = RandomGen.variable();" -> method variable in class RandomGen can not be applied to given types... – KatharsisHerbie Jan 17 '17 at 19:10
  • `RandomGen.variable();` I don't see a method variable() in your class RandomGen? What do you want to do with this method? call checkvar1? Because we Already defined the Random value in `checkvar1 = RandomGen.randomGen(checkvar1);` So you have already have the random Variable. Just use this one or I'm missing something else? – Gatusko Jan 17 '17 at 19:19
  • yah sorry... variable() = randomGen() unfortunately renamed it -.- – KatharsisHerbie Jan 17 '17 at 19:27
  • Hope my answer help you in something. – Gatusko Jan 17 '17 at 19:29