Click to See Complete Forum and Search --> : my own little program


munchy1988
10-20-2004, 03:23 PM
well, i got bored in class, and made my own little "destry the world program", u kno, the usual.

heres to code for it. im just a beginner so its not that advanced.


class countries
{

public static void main(String[] args)
{
int seconds = 0;
int countries = 0;
int count = 0;
String msg = "";
String msg1= "";
seconds = IO.getInt("How many seconds will the process take?");

while ((seconds<1) || (seconds>50))
{
seconds = IO.getInt("Process is either too long or undefinable. Please re-enter process time");
}

countries = IO.getInt("How many countries?");

if (countries == 1)
{
msg1+= ("1 Billion Chinese People ");
}

if (countries == 2)
{
msg1+= ("China and Germany ");
}

if (countries == 3)
{
msg1+= ("China, Germany, and The Pinko Commies ");
}

if (countries == 4)
{
msg1+= ("China, Germany, Russia, and Japan ");
}

if (countries == 5)
{
msg1+= ("China, Germany, Russia, Japan, and another third world country with terrorists ");
}

if (countries == 6)
{
msg1+= ("China, Germany, Russia, Japan, France, and Mongolia ");
}

if (countries > 6)
{
msg1+= (countries + " countries ");
}

for (count = seconds; count > 0; count--)
{
msg +=(msg1 +"will be demolished in: " + count + '\n');
IO.showMsg(msg);
msg = new String("");
}

IO.showMsg(msg1 + "are now destroyed" + '\n' + '\n' +
"The U.S. government has officially pwn3d you." + '\n' + '\n' +
"**** Cheney now owns all of your assets. Thank you for your participation in this program.");

System.exit(0);
}
}

well, what i want to kno is, instead of making a new IO.showMsg box appear, how can i make it count down to 0 with only the 1 box shoing up? is it even possible to do a thing like this with a time second delay?

**i probably should have mentioned this is in java...srry about that guys.:o

munchy1988
10-23-2004, 11:04 AM
anybody know how to make it count down in the same IO.showMsg?

cjohnson
10-24-2004, 09:23 AM
What is this "IO" class you refer to in your code? There's no import in what you posted, and no "IO" in java.lang, so telling whether or not you can do whatever it is you want to do with "one IO.showMsg box", is kind of hard.

munchy1988
10-25-2004, 11:00 PM
oo sorry....i forgot to mention that our school uses an IO.java file that is needed to compile so we can run windows, instead of using System.out.println().

if u want the code for it, PM me, because the program is LONG and ill post it for you to compile. basically, i want only 1 System.out.println to change the seconds to what the current value would be after a 1 second delay.

is there a delay function in java?

rock
10-25-2004, 11:36 PM
What kind of delay? You can use Thread.sleep(int millis) to pause execution for a little while.

munchy1988
10-26-2004, 04:52 PM
i put in that thread.sleep to pause the IO.showMsg box, but it tells me "unreported exception java.lang.InterruptedException; must be caught or declared to be thrown". what do i need to run that thread.sleep function in my IO.showMsg box??

** this is what i did, and this is the only thing i did


for (count = seconds; count > 0; count--)
{
msg +=(msg1 +"will be demolished in: " + count);
IO.showMsg(msg);
Thread.sleep(50);
msg = "";

}

should i declare an int in the beginning ( int millis = 50; ), and then intead of 50, just put millis in the parenthesis?

rock
10-26-2004, 06:10 PM
Thread.sleep() can throw an exception (a java.lang.InterruptedException to be specific). So you need to catch that exception in case it's thrown:


try {
Thread.sleep(50);
} catch (Exception e) {}


This is allow it to compile. If it's interrupted, the empty catch block just lets execution to progress.

munchy1988
10-27-2004, 10:30 PM
Originally posted by rock
Thread.sleep() can throw an exception (a java.lang.InterruptedException to be specific). So you need to catch that exception in case it's thrown:


try {
Thread.sleep(50);
} catch (Exception e) {}


This is allow it to compile. If it's interrupted, the empty catch block just lets execution to progress.

yay it works:D but only for a System.out.println() message...oh well. ill try to find why it doesnt work with an IO.showMsg box. im guessing because u have to click "ok" to go to the next box is why it wont work? ill try asking how to automatically click ok with the thread.sleep method.

just as a question, when the System.out.println() prints the message, how do i get the box to clear before it goes to the next message? it just gets cluttered and confusing for the simple-minded when i show them this program;)