mardi 27 octobre 2015

How to write true color random (java)

Soo this is cod:

  import java.awt.*;
  import java.util.Random; 
  import javax.swing.*;
  public class GraphsPaneTest {
public static void main(String[] args) {
    myFrame window = new myFrame();
}
  }
  class myFrame extends JFrame
  {
public myFrame()
{
    myPanel panel = new myPanel();
    Container cont = getContentPane();
    cont.add(panel);
    setBounds(100,100,500,500);
    setVisible(true);
}
  }

  class myPanel extends JPanel
  {
public void paintComponent(Graphics gr)
{
    super.paintComponent(gr); 
    Random ab = new Random(); 
    colors={Color.BLUE, Color.RED, Color.ORANGE, Color.PINK}; //Here an error
    int colorsThis = ab.nextInt(colors[colorThis]); //Here an error
    gr.setColor(Color.RED); //I try it, but it does't work //And here an error
    int a=1;
    while (a<10)
    {
        Random b = new Random(); 
        gr.fillRect(b.nextInt(900+1),b.nextInt(900+1), b.nextInt(50+1), b.nextInt(50+1)); 
        a++; 
    }
}

  }

I tried to create a cod which has square which has a random color and random corrdinat and random bounds. Soo i have an error. Please help. I know my English is very bad.




Aucun commentaire:

Enregistrer un commentaire