import java.awt.Canvas;
import java.awt.Dimension;
import javax.swing.JFrame;
public class Shoot_better extends Canvas implements Runnable{
private boolean running = false ;
private Thread thread ;
private synchronized void start() { // starts the game loop
if(running) {
return ; }
running = true ;
thread = new Thread(this) ;
thread.start();
}
private synchronized void stop() {
if(!running)
return;
running = false ;
try {
thread.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.exit(1);
}
public void run() {
while(running) {
System.out.println("RUNNING") ; //GAME LOOP
}
}
public static void main(String[] args) {
JFrame frame = new JFrame() ;
Shoot_better obj = new Shoot_better() ;
obj.setPreferredSize(new Dimension(200,200));
obj.setMaximumSize(new Dimension(200,200));
obj.setMinimumSize(new Dimension(200,200));
frame.setResizable(false);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.add(obj) ;
obj.start();
}
}