java - Game Loop not Running -


i making space shooter game in java. using runnable interface, meaning run() method should automatically called. inside method, have loop keeps on running until sets boolean running false. loop should printing working, not doing so. here code:

package main;  import javax.swing.jframe; import javax.swing.jpanel;  public class game extends jpanel implements runnable {      private static final long serialversionuid = 1l;     public static final int width = 800;     public static final int height = 600;     public static final string title = "space shooter";      private boolean running = false;     private thread thread;       public game() {      }      private synchronized void start() {         if (running)             return;          running = true;         thread = new thread();         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);     }      @override     public void run() {         while (running) {             system.out.println("working");         }         stop();     }      public static void main(string[] args) {          game game = new game();         jframe frame = new jframe(title);          frame.setsize(width, height);         frame.setdefaultcloseoperation(jframe.exit_on_close);         frame.setresizable(false);         frame.add(game);         frame.setvisible(true);           game.start();      }  } 

you forgot pass runnable instance thread constructor:

 thread = new thread(this); 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -