• 0

stop a java program from ending


Question

does anyone know how to stop a program from stopping?

my program contains a menu and when the user selects quit, it shows a message... however, it shows the message then quits, not giving the user time to read it.

i put the break code in and that didnt do nothing.

any ideas?

thanks

matt

Link to comment
Share on other sites

14 answers to this question

Recommended Posts

  • 0

Is this message shown in a dialog? If so, make it modal... Modal won't let any more code execute until the dialog is closed...

Link to comment
Share on other sites

  • 0

heres the code, its in DOS so there is no GUI atm, sorry

if (iMenu == 9)

{

bContinue = false;

System.out.print("\nThank you for using the mortgage calculator\nGoodbye now\n\n");

}

it displays the message, but as i said, it quits straight away, not giving enough time to read it. cant i do it so that the message displays and the user must press any key to continue the quit ?

thanks people,

matt

Link to comment
Share on other sites

  • 0

so you're saying that it should be:

if (iMenu == 9)

{

bContinue = false;

System.out.print("\nThank you for using the mortgage calculator\nGoodbye now\n\n");

import java.lang.Thread;

Thread.sleep(long millis);

}

cause if so, it aint working, it seys:

illegal start of expression

import java.lang.Thread;

'.class' expected

Thread.sleep(long millis);

')' expected

Thread.sleep(long millis);

i dont understand this

:wacko: :wacko:

cheers

matt

Link to comment
Share on other sites

  • 0
so you're saying that it should be:

?  if (iMenu == 9)

? ? {

? ?  bContinue = false;

? ?  System.out.print("\nThank you for using the mortgage calculator\nGoodbye now\n\n");

? ?  import java.lang.Thread;

? ?  Thread.sleep(long millis);

? ? }

cause if so, it aint working, it seys:

illegal start of expression

import java.lang.Thread;

'.class' expected

Thread.sleep(long millis);

')' expected

Thread.sleep(long millis);

i dont understand:wacko:br:wacko:cko:? :wacko:

cheers

matt

/slap

Type the number of milliseconds you want it to sleep (1000 milliseconds = 1 second) instead of "long millis".

Also, the import statement goes at the top of the code.

Link to comment
Share on other sites

  • 0

Here's what your code should read, if you want it to hold for 5 seconds:

if (iMenu == 9)
{
     bContinue = false;
     System.out.print("\nThank you for using the mortgage calculator\nGoodbye now\n\n");
     import java.lang.Thread;
     Thread.sleep(5000);
}

Is that how you put it in?

Link to comment
Share on other sites

  • 0

ummm u got a GUI, and ur displaying a message inside the console? why dont u just show a messagebox, and then when the user clicks ok, which means they have read it, then end your application.

Link to comment
Share on other sites

  • 0

Here's what your code needs to look like:

Put this at the TOP of your code file:

import java.lang.Thread;

And this for your if statement:

if (iMenu == 9)
{
    bContinue = false;
    System.out.print("\nThank you for using the mortgage calculator\nGoodbye now\n\n");
    Thread.sleep(5000);
}

You should have no problem now.

Link to comment
Share on other sites

  • 0

ok, the second line shows no errors, though the first one still does

import java.lang.Thread;

41: illegal start of expression

hmm... this is getting very annoying now. and i am using command prompt btw.

matt

Link to comment
Share on other sites

  • 0
ok, the second line shows no errors, though the first one still does

import java.lang.Thread;

41: illegal start of expression

hmm... this is getting very annoying now. and i am using command prompt btw.

matt

Sorry, it should actually be after your "package" statement I believe. Been too long since I've done Java.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.