Solved

Java code to output details input by user not working

Posted on 2011-02-19
2
331 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

743 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now