0

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.

YoungDanEn
  • 27
  • 6
  • Are you sure you're not missing a main method here? – Tunaki Oct 03 '15 at 20:49
  • Possible duplicate of [Causes of 'java.lang.NoSuchMethodError: main Exception in thread "main"'](http://stackoverflow.com/questions/5407250/causes-of-java-lang-nosuchmethoderror-main-exception-in-thread-main) – VGR Oct 04 '15 at 14:57

1 Answers1

2

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.

Brad Larson
  • 168,330
  • 45
  • 388
  • 563
Maher Shahmeer
  • 148
  • 1
  • 10