MASON-INTEREST-L Archives

February 2008

MASON-INTEREST-L@LISTSERV.GMU.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Sean Luke <[log in to unmask]>
Reply To:
MASON Multiagent Simulation Toolkit <[log in to unmask]>
Date:
Wed, 20 Feb 2008 16:53:51 -0500
Content-Type:
multipart/mixed
Parts/Attachments:
text/plain (316 bytes) , Display2D.java (66 kB) , Display3D.java (126 kB) , text/plain (126 kB) , HeatBugsWithSimpleUI.java (4 kB) , text/plain (4 kB)
Siamak asked how one might go about displaying only a Display2D.   
I've been fooling around a little bit to put together a bit of code  
explaining this.

Before I go on, here are some very slightly revised files for  
Display2D and Display3D which I'll commit to CVS when I am able (I'm  
typing this on the plane :-) ...




The first step is to start the Console by yourself, rather than having the user do it. This is easy: you just call Console.pressPlay (). For example, in the main() method of HeatBugsWithUI, you could do this:      public static void main(String[] args)          {          HeatBugsWithSimpleUI heatbugs = new HeatBugsWithSimpleUI();          Console c = new Console(heatbugs); c.pressPlay(); } The second step is to hide the Console. There are two parts to this. First, you keep it from showing up in the first place, and second, you remove the menu option on the Display2D or Display3D which pops it up later. To keep it from showing in the first place, just don't call Console.setVisible() in your main method. In the main method above, notice that it's not called. To eliminate the menu, I have a simple hack: you'll need to prevent Display2D and Display3D's createConsoleMenu() from doing anything when called. For example, in HeatBugsWithUI's init() method, you change display = new Display2D(400,400,this,1) to... display = new Display2D(400,400,this,1) { public void createConsoleMenu() { } }; Basically we're making an anonymous subclass of Display2D which does our bidding. Third, you need to prevent the close box from merely HIDING the Display2D rather than doing something smarter, like exiting the program. To do this, add this to the very end of your init() method in HeatBugsWithUI: // change the behavior of the display so when we close it, the program quits. // other options are: // HIDE_ON_CLOSE hide the window // DISPOSE_ON_CLOSE close and delete the window but don't quit the program // DO_NOTHINg_ON_CLOSE Ignore the close button displayFrame.setDefaultCloseOperation (javax.swing.JFrame.EXIT_ON_CLOSE); This isn't the greatest approach because the quit() method is never called on your GUIState. This has various undesirable results: for example, if the user is making a movie, it won't get flushed out properly when he closes the window. Instead you could set the default close operation to be dispose: displayFrame.setDefaultCloseOperation (javax.swing.JFrame.EXIT_ON_CLOSE); This disposes the window but it doesn't quit the program. How do we quit the program? When the Display2D's default JFrame is disposed, the first thing it does is call Display2D.quit(). We can tap into this in our Display2D subclass to call the doClose() method on our console, which clicks the *Console's* close box and quits the program cleanly:          // Make the Display2D. We'll have it display stuff later.          display = new Display2D(400,400,this,1) { public void createConsoleMenu() { } public void quit() { super.quit(); ((Console)c).doClose(); } }; Not that to do this, you need to make the Controller c final in init's argument list. Last, you may wish to eliminate the entire header of the Display2D so the user can't scale, skip frames, make movies, etc. This is straightforward: in the init method, you just call: display.remove(display.header); // get rid of the header bar I've put together an example which does all of this for your viewing pleasure:
Sean

ATOM RSS1 RSS2