gpt4 book ai didi

java - JOption.showMessageDialog 不工作

转载 作者:行者123 更新时间:2023-12-02 04:19:37 25 4
gpt4 key购买 nike

所以我是 GUI 新手,我有以下代码:

import javax.swing.*;
public class GUItest

{

String number = JOptionPane.showInputDialog("Enter a number betch");

int num_1 = Integer.parseInt(number);

int product = (num_1*2);

JOptionPane.showMessageDialog(null, "Your product is" + product,"Title", JOptionPane.PLAIN_MESSAGE)
}

所以我的问题是,为什么当我在第一种情况下使用 JOption (我的意思是 showInputDialog)时它没有任何问题,但是当我尝试使用 >showMEssageDialog 下拉菜单甚至不会出现,并且会弹出许多不同的语法错误。

最佳答案

我会尝试详细说明我的 friend @YoungDanEn 的评论:

import javax.swing.*;
public class GUItest

{
public static void main (String args[])
{
String number = JOptionPane.showInputDialog("Enter a number betch");

int num_1 = Integer.parseInt(number);

int product = (num_1*2);

JOptionPane.showMessageDialog(null, "Your product is" + product,"Title",JOptionPane.PLAIN_MESSAGE);
}

}

您必须定义入口点,因此对于上面的类,我们需要定义 main 方法。

关于java - JOption.showMessageDialog 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32927374/

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