jeudi 25 avril 2019

How can I use arrays to produce an equation in a Jlabel

I've made a java class with 3 fixed size arrays (array[15], array[30], array[50]) also I got 2 JFrame forms, the first with 3 JRadioButtons (15, 30, 50) and the second JFrame with a Jlabel which should generate an equation and a JTextField which should validate user input and also a button which should continue to the next question. If the user selects JRadioButton 15 I want the Jlabel on the second JFrame to generate 15 equations etc.

I've tried to put the code from the java class in the source code of the JFrame form, though I have to put it in a separate java class for my assignment. Also, I've searched on google and can't find anything relevant.

import java.util.Random;

public class SomGenerator {

public static int randomFill() {
    Random rdm = new Random();
    int randomNum = rdm.nextInt(50)+1;
    return randomNum;
}

public static int[] lijst1() {
    int[] array1 = new int[15];
    for(int i = 0; i < array1.length; i++) {
        array1[i] = randomFill();
    }
    return array1;
}

public static int[] lijst2() {
    int[] array2 = new int[30];
    for(int i = 0; i < array2.length; i++) {
        array2[i] = randomFill();
    }
    return array2;
}

public static int[] lijst3() {
    int[] array3 = new int[15];
    for(int i = 0; i < array3.length; i++) {
        array3[i] = randomFill();
    }
    return array3;
}

}


public class SommenFrame extends javax.swing.JFrame {

public SommenFrame() {
    initComponents();
}

public class SetSommen extends SomGenerator {
    public SetSommen() {
        //somLbl needs to generate the equation
        somLbl.setText(lijst1 + "+" + lijst1);
    }
}

I would really appreciate some help since I've looked at posts where people use the setText() property to set an array to the Label whereas I get an error, I used extends to link to the java class so I don't get why it doesn't get the array assigned to it.




Aucun commentaire:

Enregistrer un commentaire