Kras2.java
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.applet.*;
public class Kras2 extends JApplet
implements MouseMotionListener, MouseListener
{
private Point p, q;
public void init()
{
addMouseMotionListener(this);
addMouseListener(this);
p = new Point();
q = new Point();
}
public void paint(Graphics g)
{
Dimension d = getSize();
g.drawRect(0, 0, d.width-1, d.height-1);
}
public void mouseDragged(MouseEvent e)
{
Graphics g = getGraphics();
p.x = e.getX();
p.y = e.getY();
g.drawLine(q.x, q.y, p.x, p.y);
q.x = p.x;
q.y = p.y;
}
public void mouseMoved(MouseEvent e){}
//bepalen van begintoestand waar de muis zich bevindt
//als er mee geklikt wordt.
public void mousePressed(MouseEvent e)
{
q.x = e.getX();
q.y = e.getY();
}
// hier volgen een aantal verplichte (lege) methoden
public void mouseReleased(MouseEvent e){}
public void mouseClicked(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
}