Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sum.kern.*;
- public abstract class Anwendung {
- // Objekte
- private Bildschirm canvas;
- private Maus mouse;
- private Tastatur keyboard;
- private Buntstift pen;
- // Variabeln
- private boolean eventState = false;
- private int mouseX = -1,
- mouseY = -1;
- public Anwendung(int width, int height, boolean doublebuffer) {
- this.canvas = new Bildschirm(width, height, doublebuffer);
- this.canvas.setAlwaysOnTop(true);
- this.mouse = new Maus();
- this.keyboard = new Tastatur();
- this.pen = new Buntstift();
- this.startEventLoop();
- }
- // Events
- abstract void mouseKlickEvent() {};
- abstract void mouseDoubleKlickEvent() {};
- abstract void mouseMoveEvent(int x, int y) {};
- abstract void keyboardEvent(char c) {};
- private void eventLoop() {
- // mouseLeft
- if(this.mouse.istGedrueckt()) {
- this.mouseKlickEvent();
- }
- // mouseDouble
- if(this.mouse.doppelKlick()) {
- this.mouseDoubleKlickEvent();
- }
- // mouseMove
- if(this.mouse.hPosition() != this.mouseX
- || this.mouse.vPosition() != this.mouseY) {
- this.mouseX = this.mouse.hPosition();
- this.mouseY = this.mouse.vPosition();
- this.mouseMoveEvent(this.mouseX, this.mouseY);
- }
- // keyboard
- if(this.keyboard.wurdeGedrueckt()) {
- this.keyboardEvent(this.keyboard.zeichen());
- this.keyboard.weiter();
- }
- }
- public void startEventLoop() {
- this.eventState = true;
- while(this.eventState) {
- this.eventLoop();
- }
- }
- public void stopEventLoop() {
- this.eventState = false;
- }
- }
Add Comment
Please, Sign In to add comment