-
Notifications
You must be signed in to change notification settings - Fork 1
/
Controller.java
79 lines (65 loc) · 1.59 KB
/
Controller.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package GraphicTest;
import java.awt.Component;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
public class Controller implements KeyListener, MouseListener, MouseMotionListener{
public float mouseX, mouseY;
public boolean[] characters = new boolean[255];
public boolean hoppa = true;
private boolean pressed = false;
public Controller(Component parent) {
// Sätt kontrollern till lyssnare på en komponent
parent.addMouseListener(this);
parent.addMouseMotionListener(this);
parent.addKeyListener(this);
}
@Override
public void mouseDragged(MouseEvent arg0) {
}
/*
* Lyssnar på musens position och sparar undan
*/
@Override
public void mouseMoved(MouseEvent arg0) {
mouseX = arg0.getX();
mouseY = arg0.getY();
}
@Override
public void mouseClicked(MouseEvent arg0) {
}
@Override
public void mouseEntered(MouseEvent arg0) {
}
@Override
public void mouseExited(MouseEvent arg0) {
}
@Override
public void mousePressed(MouseEvent arg0) {
}
@Override
public void mouseReleased(MouseEvent arg0) {
}
/*
* Metoder sätter en flagga till sann eller falsk beroende pÃ¥
* tangenters status.
*/
@Override
public void keyPressed(KeyEvent arg0) {
if(!pressed){
characters[arg0.getKeyCode()] = true;
pressed = true;
}
}
@Override
public void keyReleased(KeyEvent arg0) {
characters[arg0.getKeyCode()] = false;
hoppa = true;
}
@Override
public void keyTyped(KeyEvent arg0) {
characters[arg0.getKeyCode()] = false;
}
}