View difference between Paste ID: DHuEjk65 and
SHOW: | | - or go back to the newest paste.
1-
1+
package com.technomancersonline.technomancers;
2
3
import java.awt.Canvas;
4
import java.awt.Color;
5
import java.awt.Dimension;
6
import java.awt.Graphics;
7
import java.awt.image.BufferStrategy;
8
9
import javax.swing.JFrame;
10
11
public class Game extends Canvas implements Runnable{
12
	/**
13
	 * 
14
	 */
15
	private static final long serialVersionUID = 1L;
16
	public static int width = 300;
17
	public static int height = width/16*9;
18
	public static int scale = 3;
19
		
20
	private Thread thread;
21
	private JFrame frame;
22
	private boolean running = false;
23
	
24
25
	
26
	public Game(){
27
		Dimension size = new Dimension(width * scale, height * scale);
28
		setPreferredSize(size);
29
		
30
		frame = new JFrame();
31
	}
32
	
33
	public synchronized void start () {
34
		running = true;
35
		thread = new Thread (this, "Display");
36
	}
37
	
38
	public synchronized void stop() {
39
		running = false;
40
		try{
41
		thread.join();
42
		} catch(InterruptedException e){
43
		e.printStackTrace();
44
		}
45
	}
46
	public void run(){
47
		while (running) {
48
			update();
49
			render();
50
		}
51
	}
52
	
53
	public void update(){
54
		
55
	}
56
	
57
	public void render(){
58
		BufferStrategy bs = getBufferStrategy();
59
		if (bs == null) {
60
			createBufferStrategy(3);
61
			return;
62
		}
63
		Graphics g = bs.getDrawGraphics();
64
		g.setColor(Color.BLACK);
65
		g.fillRect(0, 0, getWidth(), getHeight());
66
		g.dispose();
67
		bs.show();
68
	}
69
	
70
	public static void main (String[] args) {
71
		Game game = new Game();
72
		game.frame.setResizable(false);
73
		game.frame.setTitle("Technomancers Online");
74
		game.frame.add(game);
75
		game.frame.pack();
76
		game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
77
		game.frame.setLocationRelativeTo(null);
78
		game.frame.setVisible(true);
79
		
80
		game.start();
81
	}
82
}