aspose file tools
The moose likes Swing / AWT / SWT and the fly likes How to draw triangle in paintcomponent Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "How to draw triangle in paintcomponent" Watch "How to draw triangle in paintcomponent" New topic
Author

How to draw triangle in paintcomponent

Raghu ram
Ranch Hand

Joined: Oct 19, 2007
Posts: 34
Anybody help me out.

For the Rectangle thr is a method called

g.drawRect(x,y,width,height);
But for the triangle there is no method.
Somebody told that we can draw using the method
g.drawLine(x,y,x1,y1);

Plss reply as soon as possible
Kerry Shetline
Greenhorn

Joined: Feb 09, 2006
Posts: 14
What you probably want is java.awt.Polygon.

To avoid nasty looking "jaggies", you might want to look into Graphics2D.setRenderingHint(...) to handle antialiasing. Here are a couple of utility methods I wrote for getting the current antialiasing state (in case you want to save and restore it) and for setting the state on and off:

Raghu ram
Ranch Hand

Joined: Oct 19, 2007
Posts: 34
I didnt get your code. I want the code for drawing triangle
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35253
    
    7
Hello "raghu1ram"-

On your way in you may have missed that we have a policy on screen names here at JavaRanch. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.

As to your question, a triangle is a polygon with 3 line segments. So after defining the polygon, a call to drawPolygon will draw it.

Alternatively, you can draw it using 3 drawLine calls.

What do you have so far?


Android appsImageJ pluginsJava web charts
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216


Now that's not that hard, is it?

Of course you can also use ints instead of Points if you already have those.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Raghu ram
Ranch Hand

Joined: Oct 19, 2007
Posts: 34
Rob Prime Thanks for giving the solution.......
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to draw triangle in paintcomponent
 
Similar Threads
draw pixel at position that is float
Hey Yall, does this look right?
Angles
i want to draw an equilateral sierpinski triangle.
Using Nested For Loops To Make Triangle