![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2008
Posts: 15
Rep Power: 0
![]() |
How to return to an instance?
I am having a problem. If I have a JFrame open in a class and it performing and processing, when I close it, it still performs the work, which is good because this is what I want it to do. How do I actually return to that instance of the running program, if I go back to the main menu and click the button to load it up again, it makes a brand new instance. I need to return to the already running one.
Code for the back button MainMenu m = new MainMenu(); m.setVisible(true); dispose(); Code for loading up JFRAME Again from Main Menu SandHopper sHopper = new SandHopper(); dispose(); sHopper.setVisible(true); If someone can help me out here it would be great. Thank you. |
|
|
|
|
|
#2 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 747
Rep Power: 3
![]() |
Re: How to return to an instance?
You'll want a slightly different design where you keep a SandHopper object and instead of creating a new one each time you set it visible again. You can wrap this into a static method similar to this:
class SandHopper {
private static SandHopper onlySandHopper;
public static SandHopper GetSandHopper() {
if(onlySandHopper == null) {
onlySandHopper = new SandHopper();
}
return onlySandHopper;
}
// .. the rest of your class...
}
__________________
<insert disclaimer here> <insert shameless plug for Visual Studio here> |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Return type - main() / ISO C standard | sharadpro | C | 2 | Mar 14th, 2007 6:02 AM |
| FTP and return code fetching | Serinth | C | 2 | May 28th, 2006 11:05 PM |
| Function crashes on return | Polyphemus_ | C++ | 5 | Nov 9th, 2005 3:03 PM |
| using `char' return type in functions | atreyu | C | 6 | Jul 22nd, 2005 12:13 PM |
| return a value from a function | paulmedic555 | C++ | 1 | Jan 22nd, 2005 7:00 AM |