import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class StoereKreisenicht extends Applet implements MouseListener, MouseMotionListener {

       private int first_x, first_y, last_x, last_y;
       private int x, y, hoehe, breite;
       private boolean klick = false;

       public void init() {
              this.setBackground(Color.yellow);
              this.addMouseListener(this);
              this.addMouseMotionListener(this);
       }



    // Die anderen, nicht verwendeten Methoden des MouseListener-Interfaces
    public void mouseClicked (MouseEvent e) {
           if (klick == false) {
              first_x = e.getX();
              first_y = e.getY();
              klick = true;
           }
           else {
              last_x = e.getX();
              last_y = e.getY();
              Graphics g = this.getGraphics();

              if ((first_x < last_x) && (first_y < last_y)) {
              /* es gibt vier Fälle, wo die Punkte sitzen können */
                 x = first_x;
                 y = first_y;
                 breite = last_x-first_x;
                 hoehe = last_y-first_y;
              }

              if ((first_x > last_x) && (first_y < last_y)) {
                 x = last_x;
                 y = first_y;
                 breite = Math.abs(last_x-first_x);
                 hoehe = Math.abs(last_y-first_y);
              }

              if ((first_x > last_x) && (first_y > last_y)) {
                 x = last_x;
                 y = last_y;
                 breite = Math.abs(last_x-first_x);
                 hoehe = Math.abs(last_y-first_y);
              }

              if ((first_x < last_x) && (first_y > last_y)) {
                 x = first_x;
                 y = last_y;
                 breite = Math.abs(last_x-first_x);
                 hoehe = Math.abs(last_y-first_y);
              }
              g.setColor(Color.blue);
              g.fillOval(x, y, breite, hoehe);
              g.setColor(Color.red);
              g.drawOval(x, y, breite, hoehe);
              klick = false;
           }
    }
    // die nicht verwendeten Methoden des MouseListeners
    public void mouseEntered (MouseEvent e) { }
    public void mouseExited (MouseEvent e) { }
    public void mousePressed (MouseEvent e) { }
    public void mouseDragged (MouseEvent e) { }
    public void mouseReleased (MouseEvent e) { }

    // Die andere, nicht verwendete Methode des MouseMotionListener-Interfaces
    public void mouseMoved (MouseEvent e) { }

}



