diff options
Diffstat (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing2903.java')
| -rw-r--r-- | Master/Reference Architectures and Patterns/hjp5/examples/Listing2903.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2903.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2903.java new file mode 100644 index 0000000..33438fc --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2903.java @@ -0,0 +1,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);
+ }
+ }
+ }
+}
\ No newline at end of file |
