i've been trying to get this triangle to show up with the additon of the random x, y and random r, b, g.
I do know how to get it to show up without the random numbers but with them it isn't working.
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
//for (int i = 0; i < 500; i++) {
rand = new Random();
red = rand.nextFloat();
rand = new Random();
green = rand.nextFloat();
rand = new Random();
blue = rand.nextFloat();
c = new Color(red, green, blue);
g.setColor(c);
rand = new Random();
x1 = 1+rand.nextFloat();
rand = new Random();
x2 = 1+rand.nextFloat();
rand = new Random();
x3 = 1+rand.nextFloat();
rand = new Random();
y1 = 1+rand.nextInt(500);
rand = new Random();
y2 = 1+rand.nextInt(500);
rand = new Random();
y3 = 1+rand.nextInt(500);
int[] xPoints = {(int) x1,(int) x2,(int) x3};
int[] yPoints = {(int) y1,(int) y2,(int) y3};
g.fillPolygon(xPoints, yPoints, nPoints);
//}
}
public static void main(String[] args) {
JFrame frame = new JFrame("Paint");
frame.setSize(500,500);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
Draw draw = new Draw();
frame.add(draw);
frame.setVisible(true);
}
}
Aucun commentaire:
Enregistrer un commentaire