Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Help with dialog box

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Help with dialog box

    All,

    Hello...I am extremely new to the java scene, I am working on my first assignment in my java class. My problem is I cannot get my input in String Degrees to calculate and then display my the degrees entered. The input box comes up from String Degrees and allows for an input of data, but then disappears when you click ok and nothing happens. but after this if I type the degrees into the CMD Prompt it calculates and displays the second Message box with the answer. I need it to on click ok calculate using the formula and then automatically display the answer. I Would extremely appreciate a lil nudge in the right direction considering this is due tonight. Stupid Vista took me a 3 Days to figure out how to get JAVAC to compile anything in Vista. Thanks in advance for all of your help.

    import java.util.Scanner; //program that uses a class scanner
    import java.lang.Double;
    import javax.swing.JOptionPane; //Dialog Boxes
     
    //program that converts Farenheit to Celsius
     
    public class DegreeCalculation
    {
    	public static void main( String args[] )
    	{
    		Scanner input = new Scanner( System.in );
     
    		double number1;
    		double sum;
     
    	                     //User Enters Degrees 
    	String degrees=
    		JOptionPane.showInputDialog("Input Degrees in Farenhiet:");
    		number1 = input.nextDouble(); //reads the first number				
     
    		double number2 = Double.parseDouble(degrees);
    		sum = (number2 - 32) * (5.0 / 9);
     
    		//Prints Message containing conversion
    	String message=
    		String.format("Sum is: %.15f\n", sum);
     
    		JOptionPane.showMessageDialog(null, message);				
     
    	} //end method main
     
    } //end class DegreeCalculation
    Last edited by 03EVOAWD; August 4th, 2009 at 10:53 AM. Reason: more specific information added


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Help with dialog box

    delete this line

    number1 = input.nextDouble(); //reads the first number

    Chris

  3. The Following User Says Thank You to Freaky Chris For This Useful Post:

    03EVOAWD (August 4th, 2009)

  4. #3
    Junior Member
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help with dialog box

    Wow.....Thanks for the quick reply

  5. #4
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Help with dialog box

    Your welcome, if thats everything then mark as solved please

    Thanks,
    Chris

  6. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Help with dialog box

    Hello 03EVOAWD.

    Welcome to the forums.

    Good work Chris! Helpful as always
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  7. #6
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Help with dialog box

    Well I do my best

Similar Threads

  1. setting location of a dialog relative to the parent
    By dewboy3d in forum AWT / Java Swing
    Replies: 1
    Last Post: August 1st, 2009, 05:42 PM
  2. Facing problem with open modeless dialog from modal window
    By Divya in forum Java Theory & Questions
    Replies: 1
    Last Post: May 14th, 2009, 03:18 AM