import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import javax.swing.event.*;

/*

  This is a "pure" java application that does not require any ObjectDraw
  code in order to compile or run.

  You can build a "standalone" version of this program using the
  "Jar Bundler" application (in the Developer Utilities folder on your Mac).

  On the command line, you can compile by typing:

    javac PureJava.java

  And then run it with:

    java PureJava



  For more information on the code found here:

  Swing:

  http://java.sun.com/docs/books/tutorial/uiswing/

    Especially:

      Getting Started:
         http://java.sun.com/docs/books/tutorial/uiswing/start/index.html

      Components:
        http://java.sun.com/docs/books/tutorial/uiswing/components/index.html


  2D Graphics:

  http://java.sun.com/docs/books/tutorial/2d/index.html

 */
public class PureJava extends JApplet
    implements MouseListener, MouseMotionListener {

    /** Keep a reference to the graphics context for this object */
    private Graphics2D g;


    /**
     * The "init" method is like "begin" for objectdraw programs.
     */
    public void init() {
        // grab a copy of the graphics context
        g = (Graphics2D)getGraphics();

        // tell this class to listen to mouse events
        addMouseListener(this);
        addMouseMotionListener(this);
    }


    public void mouseClicked(MouseEvent e) {}

    public void mouseEntered(MouseEvent e) {}

    public void mouseExited(MouseEvent e) {}

    public void mousePressed(MouseEvent e) {
        g.drawString("You Clicked at (" + e.getX() + ", " + e.getY() + ")",
                     e.getX(), e.getY());
    }

    public void mouseReleased(MouseEvent e) {}

    public void mouseDragged(MouseEvent e) {
        g.fill(new Rectangle2D.Double(e.getX()-5, e.getY()-5, 10, 10));
    }

    public void mouseMoved(MouseEvent e) {}

    /**
     * The "main" method only gets run when the program is run from the
     * terminal or by double-clicking.  We just create a window and
     * put the Applet inside it so it will run.  Note the final call to
     * the "init" method, which starts the applet as if it was being
     * run from a web page.
     */
    public static void main(String[] args) {

        JFrame frame = new JFrame("PureJava");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(false);
        frame.setSize(800, 600);
        frame.setLayout(new BorderLayout());

        PureJava pj = new PureJava();
        frame.add(pj, BorderLayout.CENTER);

        frame.validate();
        frame.setVisible(true);

        pj.init();
    }


}

