Sign in to follow this  
Zyndrof

Java: showInputDialog and showMessageDialog?

Recommended Posts

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)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I believe those methods are static methods in JOptionPane.
Try JOptionPane.showInputDialog() and JOptionPane.showMessageDialog()

Share this post


Link to post
Share on other sites
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.*; ^^

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this