gpt4 book ai didi

java - 基于预定义代码构建的 Netbeans GUI

转载 作者:行者123 更新时间:2023-11-30 05:13:13 25 4
gpt4 key购买 nike

我应该为一项作业编辑一些代码,他给了我们框架并希望我们为其实现代码。我将项目加载到 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 编辑器)。我已经盯着这个看了大约一个小时了。有什么想法吗?

最佳答案

布局似乎没有在这里定义..他们只是给了你应该显示哪些组件,但由你来放置它们..

所以我建议忘记 netbeans 编辑器(因为它是一个简单的货币转换器,有 2 个文本字段、2 个组合框和一个按钮)并尝试自己构建它。

正如您所注意到的,该类扩展了 JFrame,因此您可以直接实例化已经存在的实例变量并将它们添加到框架本身。

这会很有用,因为您将了解 GUI 如何工作而无需利用,然后对于如此简单的练习,您可以轻松地通过代码进行!

关于java - 基于预定义代码构建的 Netbeans GUI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2613875/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com