This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Filling in a triangle made of GLines  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone, I'm new here, and I had a question on a project I'm working on currently in my computer science class. We have to make a triangle roof for a house made of lines using the graphics program extension, but I don't know how to fill in the triangle I made



When I run this, it just shows the red outline of the triangle. The only graphics objects we have covered so far are GLine, GRect, GOval, and GLabel. Can someone please help me find a way to color in this triangle?
 
Marshal
Posts: 59783
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I shall move this discussion to the GUIs forum, where it will fit better. I have added code tags to your post, which you should always use; you can see how much better it looks.
I can’t remember offhand how to draw triangles. Doesn’t Graphics2D have a drawPolygon method, or drawMultipleLines? There is a class called GeneralPath, too. You might be able to use that. You might need to use methods which fill the area to be draw, rather than drawing it. You end up with methods like thisWhere t is a Triangle object and its paint method uses one of those methods of the graphics classes.
When you look up the documentation, don’t get scared when you read about abstract classes. That bit doesn’t cause any problems in real life.
Also have a look in the Java Tutorials, which have sections about drawing in.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!