hi, i have a lab monday which requires me to generate random sized squares random poinst. im not to familiar with the random class and the syntax and all that but im guessin i need to use a for loop.
if someone can just point me in the right direction on what to do before the loop that would be nice. i will try and figure more out on my own while i wait for responses

so far i have this. but when i run it it only does one square. i want it to do many squares at once.

import javax.swing.*;
import java.awt.*;
import java.util.*;

public class randomSquares{
  public static void main(String[] args) {
    randomSquares d = new randomSquares();
  }

  public randomSquares(){
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(new MyComponent());
    frame.setSize(500,500);
    frame.setVisible(true);  
  }

  public class MyComponent extends JComponent{
    public void paint(Graphics g){
      int height = 500;
      int width = 500;
	

	Random r = new Random();
	int number = r.nextInt();
	
	int random_number = number % 500; {
	if (random_number < 1) random_number = random_number + 500;
	System.out.println(random_number);
	
	for (int i = 0; i < 500; i++);{
		g.drawRect(random_number, random_number, random_number, random_number);
	}
	
	
	}
	
	}
	
  }
}

i understand now that it is actually generating 500 shapes, there just in the same spot every time. How do i randomize that which is already random?

How do i randomize the
g.drawRect(random args here?);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.