Reputation: 3
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 i.e. 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);
}
}
Upvotes: 0
Views: 5777
Reputation: 8949
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
Upvotes: 1