File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

triangles and text

 
Theresa Marlin
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
Theresa Marlin
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you! Sorry about the mispost!
 
eric aro
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic