lundi 23 septembre 2019

How can I show a random number between 1 to 10 with graphics2D?

I'm thinking about how to create it, I can make it with System.out.println on a thread, it works well, but, I'm inquirring about how to show the random data each second, with the methodGraphics2D, anyone could help?

here's what I did:

String[] numbers= {"1","2", "3", "4", "5", "6", "7", "8", "9", "10"};
int random = (int) (Math.random()*numbers.length);

//here's the part I struggle
public void paint (Graphics g) {
    g2.setColor(Color.black);
    g2.drawString("The number is below", 50, 70);

    //won't run
    g2.draw(numbers, 50, 90);
}



Aucun commentaire:

Enregistrer un commentaire