java - How to restart a JFrame when creating a multiple level game? -


i have 1 level computer game created , , want add level .

here main :

public class main extends jdialog {         private static final long serialversionuid = 1l;     protected static timerthread timerthread;     static jstatusbar statusbar = new jstatusbar();     private static jframe frame;     private static final int frame_location_x = 300;     private static final int frame_location_y = 50;     private static final int frame_size_x = 850; // animator's target frames per second     private static final int frame_size_y = 700; // animator's target frames per second     private static final string worldname = "fps 2013 cg project";     private static final string hard_target = "src/res/target.jpg";     private static final string runningout = "time running out - have : ";      static int interval;     static timer timer1;     static jlabel changinglabel1 = null;       /**      *  new      */      private static timer timer;     private static int count = 60;      private static actionlistener timeraction = new actionlistener()     {         public void actionperformed(actionevent ae)         {             count--;             if (count == 0)                 timer.stop();             changinglabel1.settext(runningout + count + " seconds");          }     };       public static void exitprocedure() {         timerthread.setrunning(false);         system.exit(0);     }           /**          * clock timer1           * @author x2          *          */         public static class timerthread extends thread          {              protected boolean isrunning;              protected jlabel datelabel;             protected jlabel timelabel;              protected simpledateformat dateformat =                      new simpledateformat("eee, d mmm yyyy");             protected simpledateformat timeformat =                     new simpledateformat("h:mm a");              public timerthread(jlabel datelabel, jlabel timelabel) {                 this.datelabel = datelabel;                 this.timelabel = timelabel;                 this.isrunning = true;             }              @override             public void run() {                 while (isrunning) {                     swingutilities.invokelater(new runnable() {                         @override                         public void run() {                             calendar currentcalendar = calendar.getinstance();                             date currenttime = currentcalendar.gettime();                             datelabel.settext(dateformat.format(currenttime));                             timelabel.settext(timeformat.format(currenttime));                         }                     });                      try {                         thread.sleep(5000l);                     } catch (interruptedexception e) {                     }                 }             }              public void setrunning(boolean isrunning) {                 this.isrunning = isrunning;             }          }         public static void main(string[] args)      {             swingutilities.invokelater(new runnable()              {                 @override                 public void run()                  {                      frame = new jframe(worldname);                      container contentpane = frame.getcontentpane();                     contentpane.setlayout(new borderlayout());                      /**                      *  timer of count-down                      */                      timer = new timer(1000, timeraction);                     timer.start();                      changinglabel1 = new jlabel(runningout);                     statusbar.setleftcomponent(changinglabel1);                      final jlabel datelabel = new jlabel();                     datelabel.sethorizontalalignment(jlabel.center);                     statusbar.addrightcomponent(datelabel);                      final jlabel timelabel = new jlabel();                     timelabel.sethorizontalalignment(jlabel.center);                     statusbar.addrightcomponent(timelabel);                      contentpane.add(statusbar, borderlayout.south);                      frame.setdefaultcloseoperation(jframe.do_nothing_on_close);                     frame.addwindowlistener(new windowadapter() {                         @override                         public void windowclosing(windowevent event) {                             exitprocedure();                         }                     });                      timerthread = new timerthread(datelabel, timelabel);                     timerthread.start();                      renderer mycanvas = new renderer();                     final animator animator = new animator(mycanvas);                      toolkit t = toolkit.getdefaulttoolkit();                     bufferedimage originalimage = null;                      try                      {                         originalimage = imageio.read(new file(hard_target));                     }                       catch (exception e1) {e1.printstacktrace();}                     cursor newcursor = t.createcustomcursor(originalimage, new point(0, 0), "none");                       frame.setcursor(newcursor);                     frame.setlocation(frame_location_x, frame_location_y);                     frame.add(mycanvas);                     frame.setsize(frame_size_x, frame_size_y);                     frame.addwindowlistener(new windowadapter()                      {                         @override                         public void windowclosing(windowevent e)                          {                             new thread()                              {                                  @override                                  public void run()                                   {                                      animator.stop();                                      system.exit(0);                                  }                             }.start();                         }                     });                      frame.setvisible(true);                     animator.start();                     mycanvas.requestfocus();                     mycanvas.setfocusable(true);                 }             });     } } 

this main function uses class renderer , i.e.

class renderer extends glcanvas implements gleventlistener, keylistener ,mouselistener ,mousemotionlistener {...} 

and class holds first level of game .

as can see i'm using jframe , jogl 1.0 .

my question : how can reset jframe after i'm done 1st level ? can't use system.exit(0); , since quit entire program .

what want move class holds 2nd level .

how can without exiting system.exit(0); ?

thanks

by using remove(), can stop panel. create new 1 jframe , add() it. consider making jframe creation own function don't have keep rewriting if this.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -