Search code examples
javaswingjava.util.scannerjoptionpane

Option pane is not opening


I am trying to display an option pane from a Java application, but it is not working.

Below is the code

package sampleapplication;

import java.util.Scanner;
import javax.swing.JOptionPane;

public class SampleApplication {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Brin");
        int sample = input.nextInt();
        System.out.println("The output number is "+sample);
       JOptionPane.showMessageDialog(null, "sample");
    }
}

Solution

  • dinesh,

    input.nextInt() - will wait for the user to enter integer value in the console. once you entered the value click enter. then your messagedialogue box will be displayed.

    use this code for showing the user entered value in message box: JOptionPane.showMessageDialog(null, String.valueOf(sample));

    keep learning..