Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

need help with program

 
Stephen Norris
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I must write a program that displays 10 randomly generated traingles in different random colors. Each triangle should be filled with a different color. Use class GeneralPath and method fill of class Graphics2D to draw the triangles. This is what I have so far, but not too sure what I have to do to create the triangles. Please, anyone help me if you can.

[ February 06, 2004: Message edited by: Stephen Norris ]
 
Stephen Norris
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HELP ME, PLEASE!!!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I've never used GeneralPath, but it looks like one reasonable procedure would be to construct one with the default constructor, then use moveTo() to set one corner of the triangle, then use lineTo() to trace out the lines. Then, as GeneralPath implements Shape, you can just pass the GeneralPath to the Graphics2D.fill() method to draw it.
Two tips: don't override paint() in a Swing component. Override "paintComponent()" instead, and always call super.paintComponent() inside your implementation. Finally, don't try to draw right on a JFrame; draw on a JPanel, and add the JPanel to your JFrame.
I'm going to move this to the Swing forum.
[ February 06, 2004: Message edited by: Ernest Friedman-Hill ]
 
Stephen Norris
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to create random triangles? I am a beginner and don't have any familiarity with this. I need help and lots of it.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I deleted a few messages that were off-topic in this thread.
As far as random triangles: for each triangle, all you need are three random points, right? And for each random point, you need two random numbers from 1...d, where d is the appropriate imension of the window.
The class java.util.Random is a source of random numbers.
OK, now you write some code, come back, post it, and we'll go from there.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!