contactmail

Untitled

Nov 2nd, 2013
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. package ms.bunt;
  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.     private static final long serialVersionUID = 1L;
  10.    
  11.     public static int width = 300;
  12.     public static int height = width / 16 * 9;
  13.     public static int scale = 3;
  14.    
  15.     private Thread thread;
  16.     private JFrame frame;
  17.     private boolean running = false;
  18.    
  19.     public Game(){
  20.         Dimension size = new Dimension(width*scale, height * scale);
  21.         setPreferredSize(size);
  22.        
  23.         frame = new JFrame();
  24.     }
  25.    
  26.    
  27.     public synchronized void start(){
  28.         running = true;
  29.         thread = new Thread(this, "Display");
  30.         thread.start();
  31.     }
  32.    
  33.     public synchronized void stop(){
  34.         running = false;
  35.         try{
  36.             thread.join();
  37.         } catch(InterruptedException e){
  38.             e.printStackTrace();
  39.         }
  40.     }
  41.  
  42.     public void run() {
  43.         while (running == true){
  44.             System.out.println("Hello, world.");
  45.         }
  46.     }
  47.    
  48.     public static void main(String[] args){
  49.         Game game = new Game();
  50.         game.frame.setResizable(false);
  51.         game.frame.setTitle("Bunt Alpha build");
  52.         game.frame.add(game);
  53.         game.frame.pack();
  54.         game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  55.         game.frame.setLocation(null);
  56.         game.frame.setVisible(true);
  57.        
  58.         game.start();
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment