GraphicsApp API
Eine überarbeitete und angepasste Variante der originalen GraphicsApp-Umgebung
GraphicsAppMouseEvent.java
gehe zur Dokumentation dieser Datei
1package de.ur.mi.oop.events;
2
3import java.awt.event.MouseEvent;
4
5public abstract class GraphicsAppMouseEvent extends Event {
6
7 private final int xPos;
8 private final int yPos;
9 private final MouseEventType type;
10
11 public GraphicsAppMouseEvent(long timestamp, int xPos, int yPos, MouseEventType type) {
12 super(timestamp);
13 this.xPos = xPos;
14 this.yPos = yPos;
15 this.type = type;
16 }
17
19 return this.type;
20 }
21
22 public int getXPos() {
23 return this.xPos;
24 }
25
26 public int getYPos() {
27 return this.yPos;
28 }
29
30 public static GraphicsAppMouseEvent createMouseEventFromAWT(MouseEvent event, MouseEventType type) {
31 long timestamp = System.currentTimeMillis();
32 int xPos = event.getX();
33 int yPos = event.getY();
34 MouseButton button = MouseButton.values()[event.getButton()];
35 switch(type) {
36 case PRESSED:
37 return new MousePressedEvent(timestamp, xPos, yPos, button);
38 case RELEASED:
39 return new MouseReleasedEvent(timestamp, xPos, yPos, button);
40 case MOVED:
41 return new MouseMovedEvent(timestamp, xPos, yPos);
42 case DRAGGED:
43 return new MouseDraggedEvent(timestamp, xPos, yPos);
44 default:
45 return null;
46 }
47 }
48
49}
final long timestamp
Definition: Event.java:8
static GraphicsAppMouseEvent createMouseEventFromAWT(MouseEvent event, MouseEventType type)
GraphicsAppMouseEvent(long timestamp, int xPos, int yPos, MouseEventType type)