banner



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 :

  1. drawPolygon(int[] x, int[] y, int numberofpoints) : draws a polygon with the given prepare of x and y points.

    import java.awt.*;

    import javax.swing.*;

    public class poly extends JApplet {

    public void init()

    {

    setSize( 200 , 200 );

    evidence();

    }

    public void start()

    {

    }

    public void cease()

    {

    }

    public void paint(Graphics g)

    {

    int x[] = { ten , 30 , 40 , fifty , 110 , 140 };

    int y[] = { 140 , 110 , 50 , 40 , 30 , 10 };

    int numberofpoints = vi ;

    g.setColor(Color.blue);

    yard.drawPolygon(ten, y, numberofpoints);

    }

    }

    Output :

  2. drawPolygon(Polygon p) : draws a polygon with the given object of Polygon class.

    import java.awt.*;

    import javax.swing.*;

    public course poly extends JApplet {

    public void init()

    {

    setSize( 200 , 200 );

    testify();

    }

    public void start()

    {

    }

    public void stop()

    {

    }

    public void paint(Graphics m)

    {

    int x[] = { 10 , thirty , twoscore , 50 , 110 , 140 };

    int y[] = { 140 , 110 , 50 , 40 , 30 , x };

    int numberofpoints = 6 ;

    Polygon p = new Polygon(ten, y, numberofpoints);

    g.setColor(Color.blue);

    g.drawPolygon(p);

    }

    }

    Output :

  3. 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.

    import java.awt.*;

    import javax.swing.*;

    public course poly extends JApplet {

    public void init()

    {

    setSize( 200 , 200 );

    show();

    }

    public void offset()

    {

    }

    public void cease()

    {

    }

    public void paint(Graphics thou)

    {

    int 10[] = { ten , thirty , forty , l , 110 , 140 };

    int y[] = { 140 , 110 , l , 40 , thirty , x };

    int numberofpoints = 6 ;

    k.setColor(Colour.blue);

    for ( int i = 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

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel