Java弹出框不工作

时间:2015-07-30 04:53:34

标签: java jquery debugging popup

我是Java的新手,但对编程并不那么新。在我尝试熟悉语法的过程中,我一直在慢慢开发一个构建复杂性的顺序程序。我试图在弹出框中添加,但是我注意到在使用扫描仪后它无效,但是如果我在扫描仪之前有一个弹出框,它确实有用!有人可以解释一下吗?我在开头的弹出框中注释掉了。当它被注释掉时,代码到达我打算显示的弹出框,显示“完成!”,但弹出框永远不会出现,代码永远不会继续。但是,如果我取消注释该初始空白弹出框,则第二个弹出框确实有效,程序将继续正常运行。

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,所以尽可能详细。谢谢!

1 个答案:

答案 0 :(得分:1)

请试试这个..

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");        
}
}

JOptionPane.showMessageDialog(JF,"!完成&#34);听到你传递JFrame对象作为消息对话框显示的第一个参数。