Win a copy of Python Continuous Integration and Delivery this week in the Python 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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Filling in a triangle made of GLines  RSS feed

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?
Posts: 63373
  • 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!