Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 基于预定义代码的Netbeans GUI构建_Java_User Interface_Swing_Netbeans - Fatal编程技术网

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

Java 基于预定义代码的Netbeans GUI构建,java,user-interface,swing,netbeans,Java,User Interface,Swing,Netbeans,我应该为一项任务编辑一些代码,他给了我们框架,并希望我们为它实现代码。我将项目加载到netbeans中,但不知道应该如何编辑swing组件。我不知道如何编辑源代码与设计 import javax.swing.*; import java.util.*; import java.io.*; public class CurrencyConverterGUI extends javax.swing.JFrame { /****************************************

我应该为一项任务编辑一些代码,他给了我们框架,并希望我们为它实现代码。我将项目加载到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编辑器(因为它是一个简单的货币转换器,有两个文本字段、两个组合框和一个按钮),试着自己构建它

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


这将是非常有用的,因为您将了解GUI是如何工作的,而无需利用它,那么对于一个如此简单的练习,您可以轻松地使用代码

我认为您应该使用netbeans构建一个新的CurrencyConverterGUI类,放置swing组件(使用给定的名称,这些名称似乎是netbeans创建它们的默认名称),然后在文件末尾添加CurrencyConverter类