Guest User

Untitled

a guest
Oct 18th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. import sum.kern.*;
  2.  
  3. public abstract class Anwendung {
  4.     // Objekte
  5.     private Bildschirm canvas;
  6.     private Maus mouse;
  7.     private Tastatur keyboard;
  8.     private Buntstift pen;
  9.    
  10.     // Variabeln
  11.     private boolean eventState = false;
  12.     private int mouseX = -1,
  13.                 mouseY = -1;
  14.    
  15.     public Anwendung(int width, int height, boolean doublebuffer) {
  16.         this.canvas = new Bildschirm(width, height, doublebuffer);
  17.         this.canvas.setAlwaysOnTop(true);
  18.         this.mouse = new Maus();
  19.         this.keyboard = new Tastatur();
  20.         this.pen = new Buntstift();
  21.        
  22.         this.startEventLoop();
  23.     }
  24.    
  25.     // Events
  26.     abstract void mouseKlickEvent() {};
  27.     abstract void mouseDoubleKlickEvent() {};
  28.     abstract void mouseMoveEvent(int x, int y) {};
  29.     abstract void keyboardEvent(char c) {};
  30.    
  31.     private void eventLoop() {
  32.         // mouseLeft
  33.         if(this.mouse.istGedrueckt()) {
  34.             this.mouseKlickEvent();
  35.         }
  36.        
  37.         // mouseDouble
  38.         if(this.mouse.doppelKlick()) {
  39.             this.mouseDoubleKlickEvent();
  40.         }
  41.        
  42.         // mouseMove
  43.         if(this.mouse.hPosition() != this.mouseX
  44.         || this.mouse.vPosition() != this.mouseY) {
  45.             this.mouseX = this.mouse.hPosition();
  46.             this.mouseY = this.mouse.vPosition();
  47.             this.mouseMoveEvent(this.mouseX, this.mouseY);
  48.         }
  49.        
  50.         // keyboard
  51.         if(this.keyboard.wurdeGedrueckt()) {
  52.             this.keyboardEvent(this.keyboard.zeichen());
  53.             this.keyboard.weiter();
  54.         }
  55.     }
  56.    
  57.     public void startEventLoop() {
  58.         this.eventState = true;
  59.         while(this.eventState) {
  60.             this.eventLoop();
  61.         }
  62.     }
  63.     public void stopEventLoop() {
  64.         this.eventState = false;
  65.     }
  66. }
Add Comment
Please, Sign In to add comment