How To Draw The Letter M On Java Applet
Draw a Polygon in Coffee Applet
Polygon is a airtight effigy with finite fix of line segments joining ane vertex to the other. The polygon comprises of set of (x, y) coordinate pairs where each pair is the vertex of the polygon. The side of the polygon is the line drawn between two successive coordinate pairs and a line segment is drawn from the first pair to the last pair.
Nosotros can draw Polygon in java applet by iii ways :
- drawPolygon(int[] x, int[] y, int numberofpoints) : draws a polygon with the given prepare of x and y points.
importjava.awt.*;importjavax.swing.*;publicclasspolyextendsJApplet {publicvoidinit(){setSize(200,200);evidence();}publicvoidstart(){}publicvoidcease(){}publicvoidpaint(Graphics g){intx[] = {ten,30,40,fifty,110,140};inty[] = {140,110,50,40,30,10};intnumberofpoints =vi;g.setColor(Color.blue);yard.drawPolygon(ten, y, numberofpoints);}}Output :
- drawPolygon(Polygon p) : draws a polygon with the given object of Polygon class.
importjava.awt.*;importjavax.swing.*;publiccoursepolyextendsJApplet {publicvoidinit(){setSize(200,200);testify();}publicvoidstart(){}publicvoidstop(){}publicvoidpaint(Graphics m){intx[] = {10,thirty,twoscore,50,110,140};inty[] = {140,110,50,40,30,x};intnumberofpoints =6;Polygon p =newPolygon(ten, y, numberofpoints);g.setColor(Color.blue);g.drawPolygon(p);}}Output :
- drawLine(int x, int y, int x1, int y1) : In this method nosotros would connect adjacent vertices with a line segment and also connect the outset and last vertex.
importjava.awt.*;importjavax.swing.*;publiccoursepolyextendsJApplet {publicvoidinit(){setSize(200,200);show();}publicvoidoffset(){}publicvoidcease(){}publicvoidpaint(Graphics thou){int10[] = {ten,thirty,forty,l,110,140};inty[] = {140,110,l,40,thirty,x};intnumberofpoints =6;k.setColor(Colour.blue);for(inti =0; i < numberofpoints -i; i++)g.drawLine(x[i], y[i], 10[i +1], y[i +1]);g.drawLine(ten[0], y[0], x[numberofpoints -1], y[numberofpoints -1]);}}Output :
Note: The above function are a role of java.awt bundle and belongs to java.awt.Graphics class. Also, these codes might not run in an online compiler please use an offline compiler. The 10 and y coordinates can be changed past the developer according to their demand
Source: https://www.geeksforgeeks.org/draw-polygon-java-applet/
Posted by: gonzalezwhoustinity.blogspot.com

0 Response to "How To Draw The Letter M On Java Applet"
Post a Comment