2010-04-10 110 views
1

Netbeans的GUI構建我應該Edit,用於分配一些代碼,他給我們的框架,並要我們執行的代碼吧。我加載項目到NetBeans和想不通,我應該如何編輯Swing組件。我看不到如何編輯源代碼和設計。預先定義的代碼

import javax.swing.*; 
import java.util.*; 
import java.io.*; 

public class CurrencyConverterGUI extends javax.swing.JFrame { 
/************************************************************************************************************** 
insert your code here - most of this will be generated by NetBeans, however, you must write code for the event listeners and handlers for the two ComboBoxes, the two TextBoxes, and the Button. Please note you must also 
poulate the ComboBoxes withe currency symbols (which are contained in the KeyList attribute of 
CurrencyConverter CC) 
***************************************************************************************************************/ 

    private CurrencyConverter CC; 
    private javax.swing.JTextField Currency1Field; 
    private javax.swing.JComboBox Currency1List; 
    private javax.swing.JTextField Currency2Field; 
    private javax.swing.JComboBox Currency2List; 
    private javax.swing.JButton jButton1; 
    private javax.swing.JPanel jPanel1; 
} 


class CurrencyConverter{ 
    private HashMap HM; // contains the Currency symbols and conversion rates 
    private ArrayList KeyList; // contains the list of currency symbols 

    public CurrencyConverter() { 
     /************************************************** 
     Instantiate HM and KeyList and load data into them. 
     Do this by reading the data from the Rates.txt file 
     ***************************************************/ 
    } 

    public double convert(String FromCurrency, String ToCurrency, double amount){ 
    /*************************************************************************** 
     Will return the converted currency value. For example, to convert 100 USD 
     to GBP, FromCurrency is USD, ToCurrency is GBP and amount is 100. The rate 
     specified in the file represent the amount of each currency which is 
     equivalent to one Euro (EUR). Therefore, 1 Euro is equivalent to 1.35 USD 
    Use the rate specified for USD to convert to equivalent GBP: 

    amount/USD_rate * GBP_rate 
     ****************************************************************************/ 
    } 

    public ArrayList getKeys(){ 
    // return KeyList 
    } 

} 

這就是我們給出的,但在GUI編輯器中我無法做任何事情。 (甚至不能進入GUI編輯器)。我一直盯着這裏約一個小時。有任何想法嗎?

回答

1

佈局似乎並不在此定義..他們只是給了你應顯示組件,但它給你把他們..

,所以我會建議有關NetBeans編輯忘記(因爲它是2個文本框,組合框2和一個按鈕一個簡單的貨幣轉換器),並試圖自己建立它。

正如你可以看到該類擴展JFrame這樣你就可以直接實例的實例變量已經存在,並將它們添加到框架本身。

這將是有用的,因爲您將學習如何GUI作品,未經開發,那麼對於這麼簡單的練習中,您可以很容易地通過代碼去!

1

我想你應該使用NetBeans創建一個新的CurrencyConverterGUI類,並將擺動組件(使用給定的名稱,這些名稱似乎是NetBeans創建它們的默認名稱),然後將CurrencyConverter類添加到文件。