aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Filling in a triangle made of GLines Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Filling in a triangle made of GLines" Watch "Filling in a triangle made of GLines" New topic
Author

Filling in a triangle made of GLines

Mitch Tran
Greenhorn

Joined: Oct 08, 2012
Posts: 1
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

Joined: Oct 13, 2005
Posts: 39436
    
  28
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Filling in a triangle made of GLines