Java: showInputDialog and showMessageDialog?

Started by
1 comment, last by Zyndrof 17 years, 10 months ago
I'm writing a program that calculates the volume and area of sphere, but I get errors when I'm trying to use showMessageDialog and showInputDialog, why?
import javax.swing.JOptionPane.*;

public class Main {
    public static void main(String[] arg) {
        String s = showInputDialog(null, "What is the radius of the sphere?");
        double radius = Double.parseDouble(s);
        double volume = (4*3.14*radius*radius*radius)/3;
        double area = 4*3.14*radius*radius;
        showMessageDialog(null, "The volume is " + volume + " and the area is " + area);
    }
}

Error:
Main.java:5: cannot find symbol
symbol  : method showInputDialog(<nulltype>,java.lang.String)
location: class Main
        String s = showInputDialog(null, "What is the radius of the sphere?");
Main.java:9: cannot find symbol
symbol  : method showMessageDialog(<nulltype>,java.lang.String)
location: class Main
        showMessageDialog(null, "The volume is " + volume + " and the area is " + area);
2 errors
BUILD FAILED (total time: 0 seconds)
Advertisement
I believe those methods are static methods in JOptionPane.
Try JOptionPane.showInputDialog() and JOptionPane.showMessageDialog()
Quote:Original post by Anonymous Poster
I believe those methods are static methods in JOptionPane.
Try JOptionPane.showInputDialog() and JOptionPane.showMessageDialog()


The word static woke me up. I should've written import static javax.swing.JOptionPane.*; ^^

This topic is closed to new replies.

Advertisement