From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../hjp5/examples/Listing2903.java | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/hjp5/examples/Listing2903.java (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing2903.java') 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 -- cgit v1.2.3