-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplay.java
More file actions
68 lines (54 loc) · 1.42 KB
/
Copy pathDisplay.java
File metadata and controls
68 lines (54 loc) · 1.42 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
60
61
62
63
64
65
66
67
68
import java.awt.Color;
import java.awt.Graphics;
import java.awt.*;
import java.awt.Graphics2D;
import java.awt.Canvas;
import java.awt.event.ActionEvent;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import static java.lang.Character.*;
import java.awt.image.BufferedImage;
import java.awt.event.ActionListener;
import java.lang.Thread;
public class Display extends Canvas implements Runnable
{
private BufferedImage back;
private Simulate sim;
public Display()
{
setBackground(Color.WHITE);
setVisible(true);
sim = new Simulate();
new Thread(this).start();
// new Thread(this).start();
}
public void update(Graphics window){
paint(window);
}
public void paint(Graphics window)
{
Graphics2D twoDGraph = (Graphics2D)window;
if(back==null)
back = (BufferedImage)(createImage(getWidth(),getHeight()));
Graphics graphToBack = back.createGraphics();
graphToBack.setColor(Color.white);
graphToBack.fillRect(0, 0, Runner.WIDTH, Runner.HEIGHT);
graphToBack.setFont(new Font("Aerial", Font.PLAIN, 45));
// Draw here
sim.draw(graphToBack);
twoDGraph.drawImage(back, null, 0, 0);
}
public void run()
{
try
{
while(true)
{
repaint();
Thread.currentThread().sleep(81);
}
}catch(Exception e)
{
}
}
}