views:

44

answers:

2

I am supposed edit some code for an assignment, and he gave us the framework and wants us to implement code for it. I load the project into netbeans and can't figure out how I'm supposed to edit the swing components. I don't see how to edit source vs. design.

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
    }

}

This is what we were given, but I can't do anything with it inside the GUI editor. (Can't even get to the GUI editor). I have been staring at this for about an hour. Any ideas?

+1  A: 

Layout don't seem to be defined here.. they just gave you which components should be displayed but it's up to you to place them..

so I would advice to forget about netbeans editor (since it's a simple currency converter with 2 textfields, 2 comboboxes and a button) and try to build it by yourself.

As you can notice the class extends JFrame so you can directly instantiate the instance variables already present and add them to the frame itself.

It would be useful because you will learn how GUI works without exploiting, then for a so simple excercise you can easily go by code!

Jack
+1  A: 

I think you should build a new CurrencyConverterGUI class with netbeans, place the swing components (with the given names that seem to be the default names with which netbeans would create them), then add the CurrencyConverter class at the end of the file.

Maurice Perry