2011-02-22 97 views
0

下面的代碼是我嘗試創建一個簡單的GUI,要求用戶輸入與圖書有關的信息並顯示它。問題是我想顯示的問題,即一次輸入標題,輸入作者等,而不是每一個顯示一個一次,因爲在我寫的代碼迄今,我也想顯示成本爲雙但不知道如何去做。任何指針請?我想這樣做,而不需要完全改變我在下面寫的代碼,因爲我是初學者,並且希望看看如何構建迄今爲止我所做的。謝謝,西蒙在Java GUI中顯示信息

import javax.swing.JOptionPane; 

public class GUI 

{ 

    public static void main (String args[]) 

    { 
     String title = ""; 
     String author = ""; 
     String year = ""; 
     String publisher = ""; 
     String cost = ""; 

     title = JOptionPane.showInputDialog("Enter Title"); 
     author = JOptionPane.showInputDialog("Enter Author"); 
     year = JOptionPane.showInputDialog("Enter Year"); 
     publisher = JOptionPane.showInputDialog("Enter Publisher");  
     cost = JOptionPane.showInputDialog("Enter Cost"); 

     String message = "The title of the book is :" + title +", " + 
       "and the Author of the Book is :" + author +". It was published in" + year + "by " + publisher + 
       "and retails at" + cost; 

     ; 

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

       System.exit(0); 
    } 


} 

回答