简体   繁体   English

在Java GUI中显示信息

[英]Display information in Java GUI

The code below is my attempt at creating a simple GUI to ask a user to input information relating to a book and display it. 下面的代码是我试图创建一个简单的GUI来要求用户输入与书籍有关的信息并进行显示的尝试。 the problem is i'd like to display the questions ie enter title, enter author etc. in one go rather than each one displaying one at a time as in the code i've written so far, also i want to display the cost as Double but not sure how to go about it. 问题是我想一次性显示问题,例如输入标题,输入作者等,而不是像我到目前为止编写的代码那样每次显示一个问题,我也想将成本显示为加倍但不确定如何去做。 any pointers please? 有任何指示吗? i'd like to do it without completely changing the code i've written below as i'm a beginner and want to see how to build on what i've done so far. 我想在不完全改变我下面写的代码的情况下做这件事,因为我是一个初学者,并且想看看如何在目前为止的工作基础上继续工作。 thanks, Simon 谢谢西蒙

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);
    }


}

Your using JOptionPane, which is generally only used for basic IO, but never as a complete GUI. 您正在使用JOptionPane,它通常仅用于基本IO,但从未用作完整的GUI。

You need to learn about JFrames and other Swing components. 您需要了解JFrames和其他Swing组件。

Start here, http://www.javabeginner.com/java-swing/java-swing-tutorial 从这里开始, http://www.javabeginner.com/java-swing/java-swing-tutorial

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM