• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

need help with program

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HELP ME, PLEASE!!!
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
My, my, aren't you a big fella. Here, have a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic