Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Filling in a triangle made of GLines

 
Mitch Tran
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?
 
Campbell Ritchie
Sheriff
Pie
Posts: 49748
69
  • 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