Create an Applet - Source

This is the source of PolarApplet.java.

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JApplet;
import javax.swing.JLabel;
import javax.swing.JPanel;

import net.mumie.mathletfactory.action.handler.Affine2DKeyboardTranslateHandler;
import net.mumie.mathletfactory.action.handler.Affine2DMouseTranslateHandler;
import net.mumie.mathletfactory.action.updater.DependencyAdapter;
import net.mumie.mathletfactory.appletskeleton.system.MathletRuntime;
import net.mumie.mathletfactory.display.g2d.MMG2DCanvas;
import net.mumie.mathletfactory.math.number.MDouble;
import net.mumie.mathletfactory.math.number.NumberFactory;
import net.mumie.mathletfactory.mmobject.geom.affine.MMAffine2DAngle;
import net.mumie.mathletfactory.mmobject.geom.affine.MMAffine2DEllipse;
import net.mumie.mathletfactory.mmobject.geom.affine.MMAffine2DLineSegment;
import net.mumie.mathletfactory.mmobject.geom.affine.MMAffine2DPoint;
import net.mumie.mathletfactory.mmobject.geom.affine.MMCoordinateSystem;
import net.mumie.mathletfactory.mmobject.number.MMDouble;

public class PolarApplet extends JApplet {

    Class NUMBER_CLASS = MDouble.class;

    MMG2DCanvas canvas;

    MMAffine2DPoint point;
    MMAffine2DEllipse circle;
    MMAffine2DAngle angle;
    MMAffine2DLineSegment line;

    MMDouble rho, phi;
//        NumberFactory.getNewMMInstanceFor(NumberFactory.newInstance(NUMBER_CLASS));

    MathletRuntime runtime = MathletRuntime.createStaticRuntime(null);

    public void init() {
        canvas = new MMG2DCanvas();

        point = new MMAffine2DPoint(NUMBER_CLASS, 2, 2);
        point.setLabel("P_1$NOC[=]");
        circle = new MMAffine2DEllipse(new double[] {0, 0}, 0, 1, 1);
        circle.setLabel("C");
        angle = new MMAffine2DAngle(point, 2);
        line = new MMAffine2DLineSegment(NUMBER_CLASS, 0, 0, 2, 2);

        point.addHandler(new Affine2DMouseTranslateHandler(canvas));
        point.addHandler(new Affine2DKeyboardTranslateHandler(canvas));
        point.setEditable(true);

        angle.dependsOn(point, new DependencyAdapter() {
            public void doUpdate() {
                angle.setSecondPoint(point);
            }
        });
        line.dependsOn(point, new DependencyAdapter() {
            public void doUpdate() {
                line.setEndPoint(point);
            }
        });

        rho = new MMDouble();
        rho.setLabel("\\rho=");
        phi = new MMDouble();
        phi.setLabel("\\phi=");

        rho.dependsOn(point, new DependencyAdapter() {
            public void doUpdate() {
                rho.setDouble(
                        Math.sqrt(
                                Math.pow(point.getXAsDouble(), 2) + 
                                Math.pow(point.getYAsDouble(), 2)));
            }
        });
        phi.dependsOn(point, new DependencyAdapter() {
            public void doUpdate() {
                phi.setDouble(
                        Math.atan2(
                                point.getYAsDouble(), 
                                point.getXAsDouble()));
            }
        });

        circle.getDisplayProperties().setFilled(false);
        angle.getDisplayProperties().setObjectColor(Color.BLUE);

        canvas.addObject(new MMCoordinateSystem().getAsCanvasContent());
        canvas.addObject(circle.getAsCanvasContent());
        canvas.addObject(angle.getAsCanvasContent());
        canvas.addObject(line.getAsCanvasContent());
        canvas.addObject(point.getAsCanvasContent());
        canvas.autoScale(true);

        JPanel controlPane = new JPanel();
        controlPane.add(point.getAsContainerContent());
        controlPane.add(rho.getAsContainerContent());
        controlPane.add(phi.getAsContainerContent());
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(new JLabel("Polarkoordinaten"), BorderLayout.NORTH);
        getContentPane().add(canvas, BorderLayout.CENTER);
        getContentPane().add(controlPane, BorderLayout.SOUTH);
    }
}

Add picture from clipboard (Maximum size: 500 MB)