
java - How to create Graphics object for drawing Polygon
Aug 5, 2013 · I need to draw a Polygon - by connecting consecutive points and then connecting the last point to the first. With this goal I tried to use drawPolygon(xPoints, yPoints, nPoints). To my mind it's ...
How to Implement Polygon2D in Java 2D Graphics?
Discover how to effectively implement Polygon2D in Java 2D graphics with step-by-step guidance and clear code examples.
swing - about drawing a Polygon in java - Stack Overflow
Mar 3, 2013 · JFrame does not have a paintComponent(Graphics g) method. Add the @Override annotation and you will get a compile time error. 1) Use JPanel and override paintComponent (you would than add JPanel to the JFrame viad JFrame#add(..))
Java 2D graphics: Drawing shapes, text, and images
Apr 18, 2023 · Learn the basics of Java 2D graphics, including drawing shapes, text, and images using the Graphics2D class. Create visually appealing applications and games in Java.
Draw a Polygon : Shape « 2D Graphics GUI - Java
public void paintComponent(Graphics g) { super.paintComponent(g); Polygon p = new Polygon(); for (int i = 0; i < 5; i++) p.addPoint((int) (100 + 50 * Math.cos(i * 2 * Math.PI / 5)), (int) (100 + 50 * Math.sin(i * 2 * Math.PI / 5))); g.drawPolygon(p); Polygon s = new Polygon(); for (int i = 0; i < 360; i++) { double t = i / 360.0;
Lesson: Working with Geometry (The Java™ Tutorials > 2D Graphics)
This lesson shows you how to use the Graphics2D class to draw graphic primitives as well as arbitrary shapes, and how to display graphics with fancy outline and fill styles. These topics are discussed in the following sections.
java.awt.Graphics2D#drawPolygon - ProgramCreek.com
The following examples show how to use java.awt.Graphics2D #drawPolygon () . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source …
Drawing polygons. - Java 2D Graphics
// draw polygon with Polygon object int [] xValues = {20, 40, 50, 30, 20, 15}; int [] yValues = {50, 50, 60, 80, 80, 60}; Polygon polygon1 = new Polygon (xValues, yValues, 6); g.drawPolygon(polygon1); // draw polylines with two arrays int [] xValues2 = {70, 90, 100, 80, 70, 65, 60}; int [] yValues2 = {100, 100, 110, 110, 130, 110, 90};
Drawing Arbitrary Shapes (The Java™ Tutorials > 2D Graphics > …
Java Tutorials lesson shows how to use the Graphics2D class to draw graphic primitives, arbitrary shapes, and to display graphics with outline and fill styles
graphics - How to fill a polygon in java? - Stack Overflow
Feb 12, 2016 · Just like the Graphics2D#draw(Shape) method, there is a Graphics2D#fill(shape) method. g2.setColor(Color.BLUE); g2.fill(map.area); g2.setColor(Color.RED); g2.draw(map.area); You might like to have a look at 2D Graphics for more details
- Some results have been removed