|
-
Oct 23rd, 2008, 11:59 PM
#3
Thread Starter
New Member
Re: ask for help!
Finally, I solved it by myself....
solution:
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class RandomTriangle extends JFrame
{
public RandomTriangle()
{
super();
setSize(350,350);
setVisible(true);
}
public void paint(Graphics g)
{
super.paint( g );
int x,y,z;
Graphics2D g2d = (Graphics2D) g;
GeneralPath RandomTriangle = new GeneralPath();
{
x = (int)(Math.random()*256);
y = (int)(Math.random()*256);
z = (int)(Math.random()*256);
RandomTriangle.moveTo(x,y);
RandomTriangle.lineTo((int)(Math.random()*350),(int)(Math.random()*350));
RandomTriangle.lineTo((int)(Math.random()*350),(int)(Math.random()*350));
RandomTriangle.closePath();
g2d.setColor( new Color(x,y,z));
g2d.fill( RandomTriangle );
}
}
public static void main( String args[] )
{
RandomTriangle r1 = new RandomTriangle();
}
}
the number 350 can become any number,but 350 is easier to see.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|