[英]Display information in Java GUI
下面的代码是我试图创建一个简单的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。
您需要了解JFrames和其他Swing组件。
从这里开始, http://www.javabeginner.com/java-swing/java-swing-tutorial
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.