• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Probably a stupid question but...

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am very new to programming. Have not programmed since early 80's and that was in BASIC.
I have been studying Java. With a wife and 3 children that can be difficult.
Made the mistake of trying to learn Java and Net Beans at the same time.(Thought it would be easier if I had something to help with the code!).
Found out had to back-up and start actually trying to learn the code so that I knew what Net Beans is doing for me.
I understand some of Java, but I often get stuck on simple things.

The problem -
Have a main GUI which is also my Main Class.
6 indepenedt programs (classes) need to switch between the main program and the sub programs.
Believe it or not I am on the verge of figuring this out.

On three of the sub programs(classes) I have a simple OK button that sends a:

System.exit(0);

As you know this closes the current GUI. But how do I get it to call the main GUI back and then close?

I am not being lazy. The reason for my desire to learn Java is that I have a project which may mean something significant to my family. So please any help I would greatly appreciate.

Thanks,
George
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.
Your GUI with 6 additional classes doesn't sound like a "beginner's" project.

You are confusing System.exit(0); with the OK buttons on a GUI.
System.exit(0); closes your entire app as a "normal" termination; for an "abnormal" termination [after an error, for example, it is customary to use a non-zero argument, eg System.exit(1);].

If you want to push an OK button you would use something like:-

if(JOptionPane.showConfirmDialog("Do you wish to proceed?") == JOptionPane.OK)
System.out.print("OK button clicked.");

You would do well to check the exact use of JOptionPane in the API specification; I can't just at the moment because my mouse is playing up :-(.
 
George Sparks
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My thought was that System.exit(0); would kill the Welcome screen and return to the MainMenu.
That just kills the application Welcome, not the Main Application.
Correct?

Because there is no terminating code in the MainMenu it simply becomes either
setVisible(true);
//or
setVisible(false);


Depending on the instance from the buttons.
There are exit.Menu items and the good old (CLOSE_ON_EXIT).
But unless one of these is used it does not terminate.

Thanks,
George
 
Campbell Ritchie
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I have had a chance to check.
Are you simply putting up a message dialogue?



If you use that, what happens is that a JOptionPane dialogue appears, telling you that you are exiting; if you click "OK" or push enter, your program terminates; you use the 0 because it is a normal termination if you click the Exit Button.

Change the body of the actionPerformed method to read something like this:-


Then you will get a box asking whether you are sure you wish to exit, and you exit by clicking YES.

Have I answered your question?
About returning to your original GUI, then exiting, I don't think I can answer that without knowing more details.

PS: There are rules about naming. Please check with the naming policy that G. H. Sparks is acceptable, rather than George Sparks.
 
Campbell Ritchie
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. System.exit(0) will terminate everything you have got running. If you started from a command line or shell, it terminates everything started from that command or shell.

CR
 
George Sparks
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I registered it ask me for my first and last name which I enetered. It said that initials were okay.

I will change it shortly.

The Welcome screen actually does more than that.
The Welcome application pulls out a Corel word perfect text file that is a little more involved than a simples screen.
That is why I am wanting to handle it as a seperate program.

I have used some similar code as what you have for the contact info. it worked great.

Thanks,
George
 
George Sparks
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just changed/added my first name. Looks like that should fix it.

Okay, so System.exit(0); kills both programs.

I can work around that.

Think this will be easier if I just used one program and used all of the others as inner classes?

I tried to avoid this because
3 of the jFrames are simple.
3 are quite complex.

From the 3 that are complex one is a user manual with quite a bit of organized text.
One is a JDBC that will tie to a databse.
One is a mega amount of techincal information (thank the Lord it is in my field)but it will have graphics, engineeering reference specs., and a few minor details all of which will need to work with the database and independently of the database.

P.S. This is an application (desktop) not web based.

Thanks,
George
 
Campbell Ritchie
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.
I thought your problem didn't sound like a beginner's problem.
Don't know anything about Corel wordperfect files.
You are quite right that the setVisible() method will cause your welcome screen to appear or disappear.
Glad to have been of assistance.

CR
 
George Sparks
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank me? Than you!!!
This is one of the best web sites I have found for Java!!

I like the way that I can actually describe the problem instead of posting the code, because it is easier for me to relate to.

And you know what -----nobody fusses!!!

Thanks so much for your help,

Have some DUKE dollars lol

George
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, George, good to see you getting settled in here.

We could probably talk at length about program design. It's common to divide Swing applications up into Model, View and Controller parts - MVC.

In short, your View (the Swing panels) gets data from the Model (all your complex data). When the user clicks or enters something, the View sends the event to the Controller, which interprets the event into something meaningful, such as open or close a window, or pass new data or some option into the model for calculation or storage. Then the Controller tells the View there is new data available and the View gets it from the Model and we start over.

While it sounds like a lot more work at first to build three classes or sets of classes to get something done, the separation of concerns pays of nicely in the long run. You can often develop the Model and all of the data and computations and business rules without the View. When that's working, it's a simple matter to hook up the View and Controller.

If all that sounds interesting, scroll down to the Objects, UML, etc forum and ask about Swing & MVC. (Be sure to say "Swing" because for many in the world today MVC is a web design pattern that has little to do with your situation.)
reply
    Bookmark Topic Watch Topic
  • New Topic