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

triangles and text

Theresa Marlin
Ranch Hand

Joined: Sep 23, 2009
Posts: 49
I have to create an applet, and I was wondering if there is any way to create a triangle and fill it in with a different color than background color. I know you would use drawLine for the three lines in the triangle, but is there some way to fill it in, different from the rest of the background?

Also, is there any way to insert text into an applet?



Thanks for your help!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41809
    
  62
You can use the Graphics.drawString method to draw text.

As to drawing and filling triangles, you'd do that by creating a java.awt.Polygon object with the triangle's coordinates, and then using the Graphics.drawPolygon and Graphics.fillPolygon methods.

(Moving the question to the AWT/Swing/GUI forum, since there's nothing applet-specific about it.)


Ping & DNS - my free Android networking tools app
Theresa Marlin
Ranch Hand

Joined: Sep 23, 2009
Posts: 49
Thank you! Sorry about the mispost!
eric aro
Greenhorn

Joined: Dec 04, 2009
Posts: 15
Theresa Marlin wrote:I have to create an applet, and I was wondering if there is any way to create a triangle and fill it in with a different color than background color. I know you would use drawLine for the three lines in the triangle, but is there some way to fill it in, different from the rest of the background?

Also, is there any way to insert text into an applet?



Thanks for your help!


The best way to do is to use polygon, graphics2D. The Graphics you usually get in the paint() method is a graphics2D just cast it as graphics2D and enjoy the full list of methods, and Shape in particular.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: triangles and text