title: How to use Random() to draw images on random place in JPanel?
body: <p>I'm working on a game where you need to click a mouse/rat, after clicking it you get 1 point and the mouse/rat will disappear </p>
  
  <p>How to make the mouse image appear on different places?</p>
  
  <p>My gamescreen looks like this:
  <img src="https://i.stack.imgur.com/eDa5A.png" alt="mouse catch game"></p>
  
  <p>And my code for this page looks like:</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Cursor;
  import java.awt.Dimension;
  import java.awt.Font;
  import java.awt.Graphics;
  import java.awt.Image;
  import java.awt.Point;
  import java.awt.Toolkit;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  import javax.swing.ImageIcon;
  import javax.swing.JButton;
  import javax.swing.JPanel;
  import javax.swing.JTextField;
  
  public class Gamescreen extends JPanel implements Runnable {
          public String Gamestatus = "active";
          private Thread thread;
          //public Main game;
  
      public void paintComponent(Graphics g) {
          super.paintComponent(g);
          g.drawImage(background, 0, 0, this.getWidth(), this.getHeight(), null);
          g.drawImage(mouse, 10, 10, null);
      }
  
      private static final long serialVersionUID = 1L;
  
          Image background, muisje;
          JTextField input;
          JButton guess;
          JButton menu;
  
          Gamescreen() {
          setLayout(null);
  
          ImageIcon icon = new ImageIcon(this.getClass().getResource("assets/achtergrondspel.png"));
          background = icon.getImage();       
  
          ImageIcon icon2 = new ImageIcon(this.getClass().getResource("assets/muisje.png"));
          mouse = icon2.getImage();    
  
          //Get the default toolkit  
          Toolkit toolkit = Toolkit.getDefaultToolkit();  
  
          //Load an image for the cursor  
          Image image = toolkit.getImage("src/assets/hand.png");  
  
          //Create the hotspot for the cursor  
          Point hotSpot = new Point(0,0);
  
          //Create the custom cursor  
          Cursor cursor = toolkit.createCustomCursor(image, hotSpot, "Hand");
  
          //Use the custom cursor  
          setCursor(cursor);
  
          // setLayout( null );
  
          // Input field
          input = new JTextField(10);
          input.setLayout(null);
          input.setBounds(150, 474, 290, 60); // change position at bottom of screen is int 1
  
          // Button for guess
          guess = new JButton("Raden");
          guess.setLayout(null);
          guess.setBounds(10, 474, 130, 60);
          guess.setFont(new Font("Dialog", 1, 20));
          guess.setForeground(Color.white);
          guess.setBackground(new Color(46, 204, 113));
          guess.setPreferredSize(new Dimension(130, 60));
  
          // Menu button
          menu = new JButton("Menu");
          menu.setLayout(null);
          menu.setBounds(450, 474, 130, 60);
          menu.setFont(new Font("Dialog", 1, 20));
          menu.setForeground(Color.white);
          menu.setBackground(new Color(46, 204, 113));
          menu.setPreferredSize(new Dimension(130, 60));
  
          // add to screen
          add(input);
          //add(guess);
          add(menu);
  
          menu.addActionListener(new ActionListener() {
  
  public void actionPerformed(ActionEvent e) {
          String i = invoer.getText();
          System.out.println("Er is gedrukt! " + i);
                  }
              });
          }
  
          public void start(){
              thread = new Thread(this,"gameloop");
              thread.start();
          }
  
          public void run() {
              // TODO Auto-generated method stub
              while(Gamestatus=="active"){
                  System.out.println("Gameloop works");
              }
          }
  }
  </code></pre>