Results 1 to 7 of 7
Thread: How to fill color on triangle
- 03-24-2009, 02:23 AM #1
Member
- Join Date
- Mar 2009
- Posts
- 38
- Rep Power
- 0
How to fill color on triangle
Hi everyone...
I draw a triangle using Lines.
I want to fill color to the triangle. But I am not successful. So far I can only color the line but not fill it.
Java Code:public void paintComponent(Graphics g){ super.paintComponents(g); int k=0; for (j=0 ; j < numOfLines; j++){ // the values of numOfLines retrieved from other method. g.setColor(Color.green); g.drawLine(x[k], x[k+1], x[k+2], x[k+3]); k = k+4; //index files }
-
I'd look into using the Graphics method fillPolygon(...). Either that or perhaps create a Path2D.Float object and render it with a Graphics2D object.
- 03-24-2009, 03:08 AM #3
Member
- Join Date
- Mar 2009
- Posts
- 38
- Rep Power
- 0
Thanks a lot.
- 04-14-2011, 04:00 PM #4
Member
- Join Date
- Apr 2011
- Posts
- 5
- Rep Power
- 0
almost you solved this problem by using the knowledge related to ARRAY.
who can help me to write code to fill yellow on a triangle on a panel?
- 04-14-2011, 04:17 PM #5
Member
- Join Date
- Jan 2011
- Location
- Beirut, Lebanon
- Posts
- 90
- Rep Power
- 0
Nes_java I can understand that you want to draw a triangle on a DrawingPanel ? if that is the case you must use:
1) new Polygon()
2) by addPoint(x,y) determine the three points of the polygon
3) change or setColor to draw with
4) fillPolygon(poly) to fill it with the color you want
and don't forget to getGraphincs() from the DrawingPanel class or it wont work
Hope I helped youClick on REP and add to member reputation, if you find their advices/solutions effective.
-
- 04-15-2011, 12:25 AM #7
Member
- Join Date
- Apr 2011
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
Triangle
By jkswebsite in forum New To JavaReplies: 8Last Post: 01-10-2009, 02:08 PM -
Is it a right triangle? (Code help)
By TheApostle in forum New To JavaReplies: 8Last Post: 10-07-2008, 08:39 PM -
How to Fill Arc in Java
By Java Tip in forum java.awtReplies: 0Last Post: 06-23-2008, 11:14 PM -
Pascal Triangle help
By Magic101 in forum New To JavaReplies: 4Last Post: 05-01-2008, 07:51 PM -
Making triangle
By banie in forum New To JavaReplies: 4Last Post: 02-02-2008, 11:23 AM


LinkBack URL
About LinkBacks


Bookmarks