A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

How to draw a triangle in java?

Best Answers

I have trouble drawing a triangle with the draw(Graphics g) method in Java. I can draw a rectangle like so: public void draw(Graphics g) { g.setColor(colorFill); g.fillRect(p.x, p.y, width, height); g.setColor(colorBorder); g.drawRect(p.x, p.y, width, height); drawHandles(g); Where p represents "the top left corner of the shapes". read more

import java.awt.Graphics; import java.awt.Point; import java.awt.Polygon; import javax.swing.JFrame; import javax.swing.JPanel; Step Create your triangle class and extend the JPanel class so that the triangle can be displayed to a screen. read more

Related Types

Image Answers

Programming via Java: More on objects
Source: toves.org