Results 1 to 4 of 4
Thread: Question about JOptionPane
- 01-20-2012, 05:08 AM #1
Member
- Join Date
- Jan 2012
- Location
- Chicago, Illinois, USA
- Posts
- 19
- Rep Power
- 0
Question about JOptionPane
I am a programming student, and I unfortunately missed class today. Today my professor probably discussed what JOptionPane is, which I missed.
I'm currently working on a problem where I must declare an object keyboard of type Scanner, then declare and initialize a variable 'num', and declare and initialize a String variable to store user input. My next task is to prompt the user for input from the keyboard, and then store the user input into the String variable. So far, this is what I've got:
Now, I'm not sure what JOptionPane actually does, because I've missed today's lecture. But the above code is from an example he left on the Blackboard site. So I now have two questions: (1) instead of the last line of the above code, could I just use the following? :Java Code:Scanner keyboard = new Scanner(System.in); int num = 0; String inputString; inputString = JOptionPane.showInputDialog("Enter an integer: ");
Question (2) Considering I use the method described in my question (1), does the following make sense to use to complete the program? :Java Code:System.out.println("Enter an integer: "); inputString = keyboard.nextString();
Any help would be greatly appreciated!Java Code://convert input to integer num = Integer.parseInt(inputString); //display the results JOptionPane.showMessageDialog(null, "The value of the integer is: " + num); //end program System.exit(0); }
- 01-20-2012, 05:51 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
Re: Question about JOptionPane
Yes and yes. I think - but you'll be sure when you try them.
JOptionPane is discussed on the How to Make Dialogs page of Oracle's Tutorial.
- 01-20-2012, 06:03 AM #3
Member
- Join Date
- Jan 2012
- Location
- Chicago, Illinois, USA
- Posts
- 19
- Rep Power
- 0
Re: Question about JOptionPane
Thank you very much! :) I am having some trouble compiling the .java file, however. But I think it is unrelated to the code and more of an issue with the compiler. I'm not sure if I have everything I need to compile and run java code. I'm using Linux -- Xubuntu 11.10. Would you by any chance know what packages I would need to be able to work with java?
- 01-20-2012, 06:27 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
Re: Question about JOptionPane
I don't know offhand. But ?Ubuntu is generally pretty good about installing packages.
My guess would be
If you have an existing Java runtime or compiler you may have to check after an install that "which java" and "which javac" report the correct (and same!) versions.Java Code:sudo apt-get install openjdk-7-jre
Similar Threads
-
Simple question involving Strings and JOptionPane
By Napkins in forum New To JavaReplies: 6Last Post: 02-02-2011, 02:30 AM -
JOptionPane
By izzy in forum New To JavaReplies: 1Last Post: 03-17-2010, 04:55 PM -
Help with JOptionPane
By sanctishit in forum New To JavaReplies: 1Last Post: 03-10-2010, 10:20 AM -
JOptionpane
By tommyyyy in forum New To JavaReplies: 2Last Post: 03-20-2009, 08:33 AM -
JOptionPane String to int question
By blackstormattack in forum New To JavaReplies: 3Last Post: 03-08-2009, 12:14 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks