• Advertisement
Sign in to follow this  

Java: showInputDialog and showMessageDialog?

This topic is 4278 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement