Hi im making a Gui programme using a null layout and a setBounds() method for lay out . In the programme I want 25 strings printed out on the screen in random locations . I know that i could do this with a for loop however i have been trying this to no avail.
public void paint(Graphics g){
super.paint(g);
for(i=0;i<25;i++){
g.drawString("string name",Math.random()*250,Math.random()*250);
g.setColor(Color.RED);
}
}
I have been trying this and it has not been working so my question is is there some better way to do this or am i making some sort of obvious mistake.
You are not using the Math.random() part correctly try this instead:
This will help to get all the strings drawn within the region of the panel, although strings with varying length might go offscreen, just add some extra code to check the length of the string and set its co-ords appropriately