Problem with dialog box

This program will display the dialog box, but it will only take user inputs if he/she enters it in the systems dialog box. it doesnt recognize inputs in the input dialog box.

can someone tell me what im doing wrong?

import javax.swing.JOptionPane;

import java.util.*;

class Book

{

public String title;

}

publicclass delete

{

publicstaticvoid main (String [] args)

{

Book[] volumes;

charanswer;

intquantity = 0,

limit = 0;

Scanner keyboard =new Scanner (System.in);

JOptionPane.showInputDialog(null,"How many books will you enter? : ");

limit = Integer.parseInt(keyboard.nextLine());

volumes =new Book[limit];

while (quantity < limit){

volumes[quantity] =new Book();

JOptionPane.showInputDialog(null,"\nEnter book " + (quantity+1) +"'s title : ");

volumes[quantity].title = keyboard.nextLine();

quantity++;

}

if (quantity > 0){

JOptionPane.showInputDialog(null,"\nHere are the volumes in your collection:");

for (int i = 0; i < quantity; i++)

System.out.println("\"" + volumes[i].title);

System.out.println();

}

}

}

Heres my original code that works fine but i need this converted to a pop up window

publicclass blah

{

publicstaticvoid main (String [] args)

{

Book[] volumes;// our array of book objects

charanswer;// Y/N response from the user

intquantity = 0,// current number of books entered by the user

limit = 0;// user-specified quantity of books to be entered

Scanner keyboard =new Scanner (System.in);// source of user input

System.out.print("How many books will you enter? : ");

limit = Integer.parseInt(keyboard.nextLine());

volumes =new Book[limit];

while (quantity < limit){

volumes[quantity] =new Book();

System.out.print("\nEnter book " + (quantity+1) +"'s title : ");

volumes[quantity].title = keyboard.nextLine();

System.out.print("Enter \"" + volumes[quantity].title

+"\"'s author : ");

volumes[quantity].author = keyboard.nextLine();

System.out.print("Enter \"" + volumes[quantity].title

+"\"'s copyright date : ");

volumes[quantity].copyright = Integer.parseInt(keyboard.nextLine());

quantity++;

}

if (quantity > 0){

System.out.println("\nHere are the volumes in your collection:");

for (int i = 0; i < quantity; i++)

System.out.println("\"" + volumes[i].title +"\", by "

+ volumes[i].author

+" (" + volumes[i].copyright +")");

System.out.println();

}

}

}

[4873 byte] By [kumiko2ua] at [2007-11-27 2:02:35]
# 1

> JOptionPane.showInputDialog(null, "\nEnter book "

> + (quantity+1) + "'s title : ");

> volumes[quantity].title =

> keyboard.nextLine();

It's only taking keyboard input because you're still using the keyboard. For instance, the above code should be just

> volumes[quantity].title = JOptionPane.showInputDialog(null, "\nEnter book " + (quantity+1) + "'s title : ");

use the string return value from the input dialog

tjacobs01a at 2007-7-12 1:44:10 > top of Java-index,Java Essentials,New To Java...
# 2

Thanks! It runs smoothly now!

The only problem im having now is getting the last part of the program to display properly.

im trying to get the list of books on this dialog box. but all it shows is the message and no book title.

if (quantity > 0) {

JOptionPane.showInputDialog(null, "Choose a book to purchase or 4 to quit");

for (int i = 0; i < quantity; i++)

JOptionPane.showInputDialog(null, "\"" + volumes[i].title);

kumiko2ua at 2007-7-12 1:44:10 > top of Java-index,Java Essentials,New To Java...