summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/Listing2903.java
blob: 33438fc66b38131b319d676b9874182aa3f1b71f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* Listing2903.java */

import java.awt.*;
import java.awt.event.*;

public class Listing2903
extends Frame
{
  public static void main(String[] args)
  {
    Listing2903 wnd = new Listing2903();
    wnd.setSize(300,200);
    wnd.setLocation(200,100);
    wnd.setVisible(true);
  }

  public Listing2903()
  {
    super("Mausklicks");
    addWindowListener(new WindowClosingAdapter(true));
    addMouseListener(new MyMouseListener());
  }

  class MyMouseListener
  extends MouseAdapter
  {
    int cnt = 0;

    public void mousePressed(MouseEvent event)
    {
      Graphics g = getGraphics();
      int x = event.getX();
      int y = event.getY();
      if (event.getClickCount() == 1) { //Gesicht
        ++cnt;
        //Kopf und Augen
        g.drawOval(x-10,y-10,20,20);
        g.fillRect(x-6,y-5,4,5);
        g.fillRect(x+3,y-5,4,5);
        //Mund
        if (event.isMetaDown()) { //grimmig
           g.drawLine(x-5,y+7,x+5,y+7);
        } else {                  //l�cheln
           g.drawArc(x-7,y-7,14,14,225,100);
        }
        //Z�hler
        g.drawString(""+cnt,x+10,y-10);
      } else if (event.getClickCount() == 2) { //Brille
        g.drawLine(x-9,y-3,x+9,y-3);
      }
    }
  }
}