?
Solved

Java code to output details input by user not working

Posted on 2011-02-19
2
Medium Priority
?
347 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
sjklein42 earned 2000 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month12 days, 3 hours left to enroll

752 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