package uiintro;

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


public class DrawDemo extends JFrame implements MouseListener, MouseMotionListener {

  private int lastx, lasty;

  public DrawDemo() {
    this.setSize(400, 400);
    this.getContentPane().setBackground(Color.white);
    this.addMouseListener(this);
    this.addMouseMotionListener(this);
    this.setVisible(true);
  }

  public void mousePressed(MouseEvent me) {
    lastx = me.getX();
    lasty = me.getY();
  }

  public void mouseDragged(MouseEvent me) {
    Graphics g = this.getGraphics();
    g.drawLine(lastx, lasty, me.getX(), me.getY());
    lastx = me.getX();
    lasty = me.getY();
  }

  public void mouseReleased(MouseEvent me) {}
  public void mouseClicked(MouseEvent me) {}
  public void mouseEntered(MouseEvent me) {}
  public void mouseExited(MouseEvent me) {}
  public void mouseMoved(MouseEvent me) {}



  public static void main(String args[]) {
    DrawDemo dd = new DrawDemo();

    // the following makes sure that the process exits when we close the window.
    dd.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent we) {
        System.exit(0);
      }
    });
  }

}