-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBoard.java
More file actions
59 lines (53 loc) · 1.3 KB
/
Board.java
File metadata and controls
59 lines (53 loc) · 1.3 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
51
52
53
54
55
56
57
58
59
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JPanel;
import javax.swing.Timer;
public class Board extends JPanel {
private Timer timer;
Plane plane;
final int DELAY = 5;
public void updateGame(){
timer = new Timer(DELAY,new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
plane.move();
repaint();
System.out.println("Timer Calling...");
}
});
timer.start();
}
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D twoD = (Graphics2D)g;
if(plane.isVisible()){
twoD.drawImage(plane.getImage(), plane.getX(), plane.getY(), this);
}
// My Painting
}
public Board(){
this.setBounds(0,0,GameOne.BOARD_WIDTH,GameOne.BOARD_HEIGHT);
this.setBackground(Color.CYAN);
plane = new Plane();
this.setFocusable(true);
this.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e){
plane.direction(e);
//repaint();
//System.out.println(e.getKeyCode()+" "+e.getKeyChar());
}
@Override
public void keyReleased(KeyEvent e){
plane.dontMove();
}
});
updateGame();
//this.setSize();
}
}