JOptionPane Input Dialog Problem
Questions/Tutorials for any programming language not covered in other sections.
4 posts
Page 1 of 1
Because I am a VB.NET Programmer . I don't know what the hell is going on in my code.
I am a college student and we are now on JAVA programming.
Ok so I'm trying to do a JOptionPane and this is my code :
PS : there is no error at all. And I don't know what is happening.
I am a college student and we are now on JAVA programming.
Ok so I'm trying to do a JOptionPane and this is my code :
Code: Select all
When I started to run this. Only the First and Second number was running. I wait for the InputDialogBox to appear but nothings happen. Scanner nn = new Scanner (System.in);
String dlg;
int n1,n2,x1;
System.out.print("First Number : ");
n1 = nn.nextInt();
System.out.print("Second Number : ");
n2 = nn.nextInt();
dlg = JOptionPane.showInputDialog("Enter your Choice :");
PS : there is no error at all. And I don't know what is happening.
If this is your whole code, then there are many possible error sources.
First of all, you should make sure to import both the Scanner and the JOptionPane classes. This is done with the following code:
First of all, you should make sure to import both the Scanner and the JOptionPane classes. This is done with the following code:
Code: Select all
Secondly, your code should be within a class, which has the same name as your filename. For example, if your filename is dialogs.java, you should declare your class like so:import java.util.Scanner;
import javax.swing.JOptionPane;
Code: Select all
Then, inside your class, as you've already done, you can declare your Scanner object:public class dialogs {
}
Code: Select all
Also, every Java program needs a main class, which you haven't declared here, so add this under the Scanner declaration line:static Scanner nn = new Scanner(System.in);
Code: Select all
Inside the main function, you can now add the rest of your code:public static void main(String[] args) {
}
Code: Select all
Your entire code should now look like this: String dlg;
int n1, n2, x1;
System.out.print("First Number: ");
n1 = nn.nextInt();
System.out.print("Second Number: ");
n2 = nn.nextInt();
dlg = JOptionPane.showInputDialog("Enter your Choice:");
Code: Select all
If you compile this with javac and then run it, it should work (does for me) cooll;import java.util.Scanner;
import javax.swing.JOptionPane;
public class dialogs {
static Scanner nn = new Scanner(System.in);
public static void main(String[] args) {
String dlg;
int n1, n2, x1;
System.out.print("First Number: ");
n1 = nn.nextInt();
System.out.print("Second Number: ");
n2 = nn.nextInt();
dlg = JOptionPane.showInputDialog("Enter your Choice:");
}
}
No offend
I said there is no error sir.
The only problem is it not popping up as it should. I am using NetBeans as IDE
I said there is no error sir.
The only problem is it not popping up as it should. I am using NetBeans as IDE
Sorry . Maybe the problem is at my IDE. Not in my code.
Somebody mark this as solved
Somebody mark this as solved
4 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023