Solved

Java code to output details input by user not working

Posted on 2011-02-19
2
338 Views
Last Modified: 2012-08-14
Hi, Regarding the Java code below, I want to create a simple GUI that requests the title and author of a book and outputs something like "The title of the book is JAVA FOR DUMMIES and the author is T38" - what am I missing?  Thanks

import javax.swing.JOptionPane;

public class GUI {
      
      public static void main (String args[])
      
      {
            String title  = "";
            String author = "";
            
            title = JOptionPane.showInputDialog("Enter Title");
            
            author = JOptionPane.showInputDialog("Enter Author");
            
            JOptionPane.showMessageDialog(null, "The title of the book is :", "and the Author of the Book is : " Book Details",JOPtionPane.PLAIN_MESSAGE);
            
            System.exit(0);
      }
      

}
0
Comment
Question by:t38
2 Comments
 
LVL 16

Accepted Solution

by:
sjklein42 earned 500 total points
ID: 34933678
Build your message string first.  I don't see where you are concatenating the message parts together.  I think you have messed up your commas, etc.  Also you misspelled JOptionPane.  Try this:
String message =  "The title of the book is :" + title +", and the Author of the Book is :" + author;

JOptionPane.showMessageDialog(null, message, "Book Details", JOptionPane.PLAIN_MESSAGE);

Open in new window

0
 

Author Closing Comment

by:t38
ID: 34933704
Thanks!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Tomcat: Unable to run tomcat service. 2 28
difference between sorce folder and folder in eclipise 3 40
American Express @Work site and Java 4 63
Java array 21 78
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question