YoungDanEn
YoungDanEn

Reputation: 27

JOption.showMessageDialog not working

So I am new to GUI and I have the following code:

import javax.swing.*;
public class GUItest 

{

    String number = JOptionPane.showInputDialog("Enter a number betch");

    int num_1 = Integer.parseInt(number);

    int product = (num_1*2);

    JOptionPane.showMessageDialog(null, "Your product is" + product,"Title", JOptionPane.PLAIN_MESSAGE)
}

So my question is how come when I used JOption in the first case (I mean showInputDialog) it worked with no problems but then when I try to use showMEssageDialog the drop down menu wont even appear and many different syntax errors pop up.

Upvotes: 0

Views: 1014

Answers (1)

Maher Shahmeer
Maher Shahmeer

Reputation: 148

I'll try to elaborate on the comment by my friend @YoungDanEn:

import javax.swing.*;
public class GUItest 

{
    public static void main (String args[])
    {
        String number = JOptionPane.showInputDialog("Enter a number betch");

        int num_1 = Integer.parseInt(number);

        int product = (num_1*2);

        JOptionPane.showMessageDialog(null, "Your product is" + product,"Title",JOptionPane.PLAIN_MESSAGE);
    }

}

You must have entry point defined, So for above class we needed to define the main method.

Upvotes: 2

Related Questions