Search code examples
javaswingintegerjoptionpane

How to create a method for JOption Pane in java?


how can I make a method for JOptionPane in java, thats gets and stores the value given by the user in a given variable and converts it into double / int, the variable which I want to store the value in is outside the method and in main class

e.g.

    public static void main(String args[]){
    double num1
    int num2

    // calling the method
    method(pane, num1);
    }

    public void method(String pane, double number){
    String pane = JOptionPane.showInputDialog("choose a number");
    number = Double.parseDouble(pane);
    }
}

which then can be printed like so

system.out.println(num1);

Solution

  • Make the method return double. And make num1 = method()