我应该为编辑编辑一些代码,他给了我们框架并希望我们为它实现代码。我将项目加载到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编辑器)。我一直盯着这个约一个小时。有什么想法吗?
答案 0 :(得分:1)
布局似乎没有在这里定义..它们只是给了你应该显示哪些组件但是你可以放置它们。
所以我建议忘记netbeans编辑器(因为它是一个带有2个文本字段,2个组合框和一个按钮的简单货币转换器)并尝试自己构建它。
您可以注意到类扩展了JFrame
,因此您可以直接实例化已存在的实例变量并将它们添加到框架本身。
这将非常有用,因为您将了解GUI如何在不利用的情况下工作,然后对于如此简单的练习,您可以轻松地通过代码进行操作!
答案 1 :(得分:1)
我认为您应该使用netbeans构建一个新的CurrencyConverterGUI类,放置swing组件(给定的名称似乎是netbeans将创建它们的默认名称),然后在文件末尾添加CurrencyConverter类