0

I used this method for the creation of a square:

public void displayCircle() {
    JFrame frame = new JFrame();
    frame.setSize(400, 300);
    int x1 = (int) A.getX();
    int x2 = (int) B.getX();
    int x3 = (int) C.getX();
    int x4 = (int) D.getX();
    // 25, 156, 175, 80
    int y1 = (int) A.getY();
    int y2 = (int) B.getY();
    int y3 = (int) C.getY();
    int y4 = (int) D.getY();

    applet = new CircleApplet(new int[] { x1, x2, x3, x4 }, new int[] { y1, y2, y3, y4 });
    int R = (int) ((Math.random()) * 256);
    int G = (int) ((Math.random()) * 256);
    int Bb = (int) ((Math.random()) * 256);

    applet.setForeground(new Color(R, G, Bb, 200));
    frame.getContentPane().add(applet);
    frame.addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent we) {
            applet.stop();
            applet.destroy();
            System.exit(0);
        }
    });

    frame.setVisible(true);
    applet.init();
    applet.start();

}

with this circle applet:

import java.applet.*;
import java.awt.*;


@SuppressWarnings("deprecation")
public class CircleApplet extends Applet {

    int[] pointsX,pointsY;
    int numPoints=0;
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public CircleApplet() {}

    public CircleApplet(int[] pointsX, int[] pointsY) {
        this.pointsX=pointsX;
        this.pointsY=pointsY;
        this.numPoints=Math.min(pointsX.length, pointsY.length);
    }

    public void paint(Graphics g) {
        //System.out.println(this.numPoints);
        if (this.numPoints>0)
            g.fillPolygon(pointsX,pointsY,numPoints);
        for(int x = 0; x < numPoints; x++){
            g.setColor(new Color(0, 0, 0));
            char alpha = 'X';
            switch (x){
                case 0:
                    alpha = 'A';
                    break;
                case 1:
                    alpha = 'B';
                    break;
                case 2:
                    alpha = 'C';
                    break;
                case 3:
                    alpha = 'D';
                    break;
                default:
                    break;
            }
            g.drawString(alpha +" (" + pointsX[x] + " , " + pointsY[x] + ")", pointsX[x], pointsY[x]);
        }
    }

}

I wanted to create circle mentioned above, how do I create a circle? Do I use arcs or do I have to rewrite it, the problem itself is straight forward but I still do not understand applets.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    1) Why use AWT? See [this answer](http://stackoverflow.com/questions/6255106/java-gui-listeners-without-awt/6255978#6255978) for many good reasons to abandon AWT components in favor of Swing. 2) Why code an applet? If it is due to the teacher specifying it, please refer them to [Why CS teachers should **stop** teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). 3) See [Java Plugin support deprecated](http://www.gizmodo.com.au/2016/01/rest-in-hell-java-plug-in/) and .. – Andrew Thompson Jan 23 '18 at 04:16
  • 1
    .. [Moving to a Plugin-Free Web](https://blogs.oracle.com/java-platform-group/moving-to-a-plugin-free-web). – Andrew Thompson Jan 23 '18 at 04:16

0 Answers0