-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmovement.java
More file actions
50 lines (47 loc) · 1.08 KB
/
movement.java
File metadata and controls
50 lines (47 loc) · 1.08 KB
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
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class movement extends JPanel implements KeyListener{
private ImageIcon image;
int x = 750/2, y = 750/2;
ImageIcon i = new ImageIcon("H:\\char.bmp");
public void paint(Graphics g){
i.paintIcon(this, g, x, y);
}
public void up(){
repaint();
y-= 5;
System.out.println("up");
}
public void down(){
repaint();
y+= 5;
}
public void left(){
repaint();
x-= 5;
}
public void right(){
repaint();
x+= 5;
}
public void keyPressed(KeyEvent e){
int code = e.getKeyCode();
if(code == KeyEvent.VK_UP){
up();
}
if(code == KeyEvent.VK_DOWN){
down();
}
if(code == KeyEvent.VK_LEFT){
left();
}
if(code == KeyEvent.VK_RIGHT){
right();
}
}
public void keyTyped(KeyEvent e){}
public void keyReleased(KeyEvent e){}
}