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();
}
}
}

