school assignment

Hello and thank you in advance,

My java text book supplies the following programming assignment:

Type in and run the following program:

import javax.swing.JOptionPane;

public class DialogTester

{

public static void main(String[] args)

{

JOptionPane.showMessageDialog(null, "Hello, World!");

System.exit(0);

}

}

So I type this into the compiler (BlueJ) editor and no errors occur. Then I right click on the class I created and select "static void main(String[] args)," which is supposed to run the program inside the terminal window in the compiler, but nothing happens.

Any ideas?

[665 byte] By [datawerd2a] at [2007-11-26 16:47:04]
# 1

I guess You need not so fast CPU to see any thing ;))

Exit comes too fast for a human being...

Oh, yes. It is from book.

Make modiffications like this:

JOptionPane.showMessageDialog(null, "Hello, World!");

sleep(3000);

System.exit(0);

Message was edited by:

_Dima_

_Dima_a at 2007-7-8 23:14:31 > top of Java-index,Java Essentials,New To Java...
# 2

just execute java -cp . DialogTester from the command line in the directory where your .class file is located... Don't know how what you are doing, but I never heard of running a java program like that. Are you using an IDE or just some editor with command line?

@_Dima_ That's nonsense. System.exit(0) is only called after you close the dialog box.

JOptionPane.showMessageDialog(null, "Hello, World!"); is a blocking statement.

Message was edited by:

Peetzore

Peetzorea at 2007-7-8 23:14:31 > top of Java-index,Java Essentials,New To Java...
# 3
he's using that idiocy they call BlueJ which claims to be an ideal IDE for teaching kids Java but in fact teaches them nothing at all.
jwentinga at 2007-7-8 23:14:31 > top of Java-index,Java Essentials,New To Java...
# 4
I've just searched for BlueJ and I'd say get rid of it! From what I see from the documentation, it's not the best way to get started with Java at all!
Peetzorea at 2007-7-8 23:14:31 > top of Java-index,Java Essentials,New To Java...
# 5
> JOptionPane.showMessageDialog(null, "Hello, World!");> is a blocking statement.May be. Will not argue. For me it seem ridicules to have syncronous show method.
_Dima_a at 2007-7-8 23:14:31 > top of Java-index,Java Essentials,New To Java...
# 6
try [url http://www.textpad.com] Textpad [/url]gurnah
G_Abubakra at 2007-7-8 23:14:31 > top of Java-index,Java Essentials,New To Java...
# 7
BTW, if " is supposed to run the program inside the terminal window in the compiler" how it can show any grafix?
_Dima_a at 2007-7-8 23:14:31 > top of Java-index,Java Essentials,New To Java...
# 8
> try [url http://www.textpad.com] Textpad [/url] ++
_Dima_a at 2007-7-8 23:14:31 > top of Java-index,Java Essentials,New To Java...
# 9

From the Javadoc:

All dialogs are modal. Each showXxxDialog method blocks the current thread until the user's interaction is complete.

It's quite logical since it is used for user interaction. You have to wait for user input before you can decide what to do next. This is quite a common concept in most languages.

Peetzorea at 2007-7-8 23:14:31 > top of Java-index,Java Essentials,New To Java...
# 10
> BTW, if " is supposed to run the program inside the> terminal window in the compiler" how it can show any> grafix?what do mean by your sentence
G_Abubakra at 2007-7-8 23:14:31 > top of Java-index,Java Essentials,New To Java...
# 11
> what do mean by your sentenceTheoretically it is possible to limit an app to one particular window...But I guess it is not the case.It was more or less as a joke. ;)
_Dima_a at 2007-7-8 23:14:31 > top of Java-index,Java Essentials,New To Java...
# 12
well what I usually do to compile and run programs, just o make sure they work is:javac -cp .;. Program.classjava -cp .;. Program
KrimsonEagla at 2007-7-8 23:14:31 > top of Java-index,Java Essentials,New To Java...
# 13

So I tried running this program from the command prompt, in the directory where the files were created and compiled. I entered "java -cp.Dialogtester," only this time I received an error message: "Unrecognized option -cp.DialogTester

Could not create the Java virtual machine" I have JVM 6.0 and JDK 6.0 installed on my computer, using Windows XP. Whats next?

I think the book required by my university is a total piece of **** too.

datawerd2a at 2007-7-8 23:14:31 > top of Java-index,Java Essentials,New To Java...
# 14
Type a space between -cp and . and DialogTesterMessage was edited by: Peetzore
Peetzorea at 2007-7-8 23:14:31 > top of Java-index,Java Essentials,New To Java...