0

I no the problem is not with the program its with my pc. I am able to compile this program fine on my school's pc but i can't on my laptop.

The program is

public class SwingIO
{
    public static void main(String[] args)
    {
        /*
           (To contrast this sample with the ConsoleIO program, note
           that no "throws IOException" clause is required above in
           the declaration of the method: main. Note also that the
           swing input routines do not require declarations analagous
           to those of InputStreamReader and BufferedReader objects
           of the ConsoleIO program.)
        */

        /*
           Following are the input variables of this sample program.
           Note that numbers must be read in as Strings and then
           converted.
        */
        String name;
        String numberString; // Each number will be read here in turn

        /*
           Numeric inputs will be converted to ints and placed in
           these two variables.
        */
        int number1, number2;

        /*
           Following produces an input window to pop us with the prompt
           message shown in the parameter. Whatever the user enters is
           stored in the name variable.
        */
        name = JOptionPane.showInputDialog("What is your first name?");

        /*
           Read and convert the first integer. Note: the program will
           crash in the conversion process if a value entered for either
           the first or second integer are not valid integer numbers.
        */
        numberString = JOptionPane.showInputDialog(
            "Enter first integer value:");
        number1 = Integer.parseInt(numberString);

        /*
           Read and convert the second integer (see note just above).
        */
        numberString = JOptionPane.showInputDialog(
            "Enter second integer value:");
        number2 = Integer.parseInt(numberString);

        // Calculates and displays the answer
        JOptionPane.showMessageDialog(null, "Hello, " + name + "!" + "\n" +
            "The sum of " + number1 + " and " + number2 +
            " is " + (number1 + number2) + ".");
    }
}

And the error message is

C:\Documents and Settings\Admin\My Documents\Java Programs\SwingIO.java:34: cannot resolve symbol
symbol  : variable JOptionPane 
location: class SwingIO
        name = JOptionPane.showInputDialog("What is your first name?");
                       ^
C:\Documents and Settings\Admin\My Documents\Java Programs\SwingIO.java:41: cannot resolve symbol
symbol  : variable JOptionPane 
location: class SwingIO
        numberString = JOptionPane.showInputDialog(
                               ^
C:\Documents and Settings\Admin\My Documents\Java Programs\SwingIO.java:48: cannot resolve symbol
symbol  : variable JOptionPane 
location: class SwingIO
        numberString = JOptionPane.showInputDialog(
                               ^
C:\Documents and Settings\Admin\My Documents\Java Programs\SwingIO.java:53: cannot resolve symbol
symbol  : variable JOptionPane 
location: class SwingIO
        JOptionPane.showMessageDialog(null, "Hello, " + name + "!" + "\n" +
                ^
4 errors

Tool completed with exit code 1

Edited by Reverend Jim: Fixed formatting

2
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by rinoa04
0

Also i should have mentioned that i am useing the same compiler on my laptop that i us at school "Textpad". My school has Java 2 SDK ,SE v1.4.2_12 installed. I have that and J2SE Runtime Enviroment 5.0 update 6.

Any advise?

0

There is nothing wrong with your program nor your compiler. It is only that you forgot to include this statement:

import javax.swing.JOptionPane;

That is why the compiler doesn't recognise JOptionPane function.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.