Guest User

Just learning.

a guest
Oct 10th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. package Virescence.Game;
  2.  
  3. import java.awt.Canvas;
  4. import java.awt.Dimension;
  5.  
  6. import javax.swing.JFrame;
  7.  
  8. public class Game extends Canvas implements Runnable {
  9.  
  10. /**
  11. * My stuff
  12. */
  13. private static final long serialVersionUID = 1L;
  14.  
  15. public static int width = 300;
  16. public static int height = width / 16 * 9;
  17. public static int scale = 3;
  18.  
  19. private Thread thread;
  20. private JFrame frame;
  21. private boolean running = false;
  22.  
  23. public Game() {
  24. Dimension size = new Dimension(width * scale, height * scale);
  25. setPreferredSize(size);
  26.  
  27. frame = new JFrame();
  28. }
  29.  
  30. public synchronized void start() {
  31. running = true;
  32. thread = new Thread(this, "Display");
  33. thread.start();
  34. }
  35.  
  36. public synchronized void stop() {
  37. running = false;
  38. try {
  39. thread.join();
  40. } catch (InterruptedException e) {
  41. e.printStackTrace();
  42. }
  43. }
  44. public void run() {
  45. while (running) {
  46. System.out.println("Running...");
  47. }
  48. }
  49.  
  50. public static void main(String[] args) {
  51. Game game = new Game();
  52. game.frame.setResizable(false);
  53. game.frame.setTitle("Rain");
  54. game.frame.add(game);
  55. game.frame.pack();
  56. game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  57. game.frame.setLocationRelativeTo(null);
  58. game.frame.setVisible(true);
  59.  
  60. game.start();
  61. }
  62. }
Add Comment
Please, Sign In to add comment