Java 弹出框不工作

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

最佳答案

请尝试这个..

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,"完成!");听到您将 JFrame 对象作为第一个参数传递,其中消息对话框显示。

关于Java 弹出框不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31715418/

相关文章:

java继承相关基础知识

javascript - 对 Django 数据库值 : views. py、模板或 Javascript 执行计算?

Python 调试器 : interactive debugging vs. 硬编码断点

debugging - 为什么 IntelliJ IDEA 删除了强制步入按钮?

Java 8 Streams API HAVING 子句等同于 GroupingBy?

java - 如何使用 Java 8 Streams 在一次迭代中对 2 个不同的字段进行平面映射?

java - Hibernate查询一对一关系

javascript - 在 div 中居中图像,如设置背景位置

jquery - 如何从 iframe 隐藏滚动条?

node.js - 无法使用 Chrome DevTools 调试 node.js