-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameCanvas.java
More file actions
44 lines (32 loc) · 1.08 KB
/
GameCanvas.java
File metadata and controls
44 lines (32 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
package ru.gb.jtwo.online.circles;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class GameCanvas extends JPanel {
private MainCircles gameWindow;
private long lastFrameTime;
GameCanvas(MainCircles gameWindow) {
this.gameWindow = gameWindow;
addMouseListener(new MouseController(this));
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
long currentTime = System.nanoTime();
float delta = (currentTime - lastFrameTime) * 0.000000001f;
lastFrameTime = currentTime;
try {
Thread.sleep(17);
} catch (InterruptedException e) {
e.printStackTrace();
}
gameWindow.onDrawPanel(this, g, delta);
repaint();
}
public int getLeft() { return 0; }
public int getRight() { return getWidth() - 1; }
public int getTop() { return 0; }
public int getBottom() { return getHeight() - 1; }
public MainCircles getGameWindow(){return gameWindow;};
}