下面的代码是我尝试创建一个简单的 GUI 来要求用户输入与书籍相关的信息并显示它。问题是我想一次显示问题,即输入标题、输入作者等,而不是像我到目前为止编写的代码那样每次显示一个问题,我也想将成本显示为双倍但不知道如何去做。有什么指示吗?我想在不完全更改下面编写的代码的情况下完成此操作,因为我是初学者,并且想了解如何在我迄今为止所做的基础上进行构建。谢谢,西蒙
import javax.swing.JOptionPane;
public class GUI
{
public static void main (String args[])
{
String title = "";
String author = "";
String year = "";
String publisher = "";
String cost = "";
title = JOptionPane.showInputDialog("Enter Title");
author = JOptionPane.showInputDialog("Enter Author");
year = JOptionPane.showInputDialog("Enter Year");
publisher = JOptionPane.showInputDialog("Enter Publisher");
cost = JOptionPane.showInputDialog("Enter Cost");
String message = "The title of the book is :" + title +", " +
"and the Author of the Book is :" + author +". It was published in" + year + "by " + publisher +
"and retails at" + cost;
;
JOptionPane.showMessageDialog(null, message, "Book Details", JOptionPane.PLAIN_MESSAGE);
System.exit(0);
}
}
最佳答案
您使用的JOptionPane,一般只用于基本IO,但从来不作为完整的GUI。
您需要了解 JFrame 和其他 Swing 组件。
从这里开始,http://www.javabeginner.com/java-swing/java-swing-tutorial
关于java - 在 Java GUI 中显示信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5083802/