Java弹出框不工作
我是Java新手,但对编程并不陌生。在我试图熟悉语法的过程中,我一直在缓慢地开发一个复杂的顺序程序。我试图添加一个弹出框,但是我注意到它在我使用扫描仪后不起作用,但是如果我在扫描仪前有一个弹出框,它确实起作用!有人能解释一下吗?我已经注释掉了开头的弹出框。当它被注释掉时,代码到达我打算显示的弹出框,它显示“完成!”,但弹出框从未出现,代码也从未继续。但是,如果我取消注释掉初始的空白弹出框,第二个弹出框将正常工作,程序将继续正常运行Java弹出框不工作,java,jquery,debugging,popup,Java,Jquery,Debugging,Popup,我是Java新手,但对编程并不陌生。在我试图熟悉语法的过程中,我一直在缓慢地开发一个复杂的顺序程序。我试图添加一个弹出框,但是我注意到它在我使用扫描仪后不起作用,但是如果我在扫描仪前有一个弹出框,它确实起作用!有人能解释一下吗?我已经注释掉了开头的弹出框。当它被注释掉时,代码到达我打算显示的弹出框,它显示“完成!”,但弹出框从未出现,代码也从未继续。但是,如果我取消注释掉初始的空白弹出框,第二个弹出框将正常工作,程序将继续正常运行 import java.util.*; import javax
import java.util.*;
import javax.swing.JOptionPane;
public class Tutorial1
{
static final double PINUM = 3.141592654; // Declaring a constant
public static void main(String[] args)
{
//JOptionPane.showMessageDialog(null,"");
int myInt = 4, i; // Declares an integer
double myDouble; // Declares Double
int[] myArray = new int[50]; // Declares Array
Scanner in = new Scanner(System.in);
System.out.println("\n\nWelcome! Please enter your name!");
String userName = in.nextLine();
System.out.println("Nice to meet you, " + userName + ".\n");
System.out.println("\nThe largest float this machine can create is = " + Float.MAX_VALUE);
System.out.println("\nThe largest double this machien can create is = " + Double.MAX_VALUE);
System.out.println("\nThis is a test Program for learning Java \nCreated by " + userName
+ "\n7/29/15\n\n"); // the + carries this line from the last
myInt++;
System.out.println("Value : " + myInt);
myDouble = 4.77;
myDouble = (myInt-1)/myDouble;
System.out.println("Value : " + myDouble + "\n");
for(myInt = 5; myInt >= 0; myInt--)
{
System.out.println("Loop Value : " + myInt);
}
System.out.println("\n\nTesting Popup box...");
JOptionPane.showMessageDialog(null,"Complete!");
System.out.println("\n\nTest Done");
}
}
那么,对于为什么会发生这种情况,以及如何解决它,有什么想法吗?我希望学习并熟悉Java,所以尽可能详细。谢谢 请试试这个
import java.util.*;
import javax.swing.JOptionPane;
public class Tutorial1 extends JFrame
{
static final double PINUM = 3.141592654; // Declaring a constant
public static void main(String[] args)
{
JFrame jf=new JFrame();
//JOptionPane.showMessageDialog(null,"");
int myInt = 4, i; // Declares an integer
double myDouble; // Declares Double
int[] myArray = new int[50]; // Declares Array
Scanner in = new Scanner(System.in);
System.out.println("\n\nWelcome! Please enter your name!");
String userName = in.nextLine();
System.out.println("Nice to meet you, " + userName + ".\n");
System.out.println("\nThe largest float this machine can create is = " + Float.MAX_VALUE);
System.out.println("\nThe largest double this machien can create is = " + Double.MAX_VALUE);
System.out.println("\nThis is a test Program for learning Java \nCreated by " + userName
+ "\n7/29/15\n\n"); // the + carries this line from the last
myInt++;
System.out.println("Value : " + myInt);
myDouble = 4.77;
myDouble = (myInt-1)/myDouble;
System.out.println("Value : " + myDouble + "\n");
for(myInt = 5; myInt >= 0; myInt--)
{
System.out.println("Loop Value : " + myInt);
}
System.out.println("\n\nTesting Popup box...");
JOptionPane.showMessageDialog(jf,"Complete!");
System.out.println("\n\nTest Done");
}
}
showMessageDialog(jf,“完成!”);听到您将JFrame对象作为消息对话框显示的第一个参数传递 感谢您的快速回复,@mukesh!你的解决方案基本上奏效了。我不得不将javax.swing更改为通配符导入,以使其工作,但这解决了我遇到的问题。再次感谢!