简体   繁体   中英

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. 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.

You need to learn about JFrames and other Swing components.

Start here, http://www.javabeginner.com/java-swing/java-swing-tutorial

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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