This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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: 61756
193
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!