gpt4 book ai didi

Java 弹出框不工作

转载 作者:行者123 更新时间:2023-11-30 08:02:17 25 4
gpt4 key购买 nike

我对 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com