Hello there, I've been working on a assignment given to me two weeks ago.
as of now I'm still unable to arrange the code in its consecutive order. this assignment basically was to setup a currency converter from american dollar to YEN, EURO and PESO. Everything is already setup except the formula code that will do the convertion process( If...else statement, or so ) In order to avoid confusion or for better visibility I've pasted the whole code which I'm working on. I would really appreciate your help.
Code:
public class CurrencyConverter extends JFrame
{
// JLabel and JTextField to input dollar amount
private JLabel dollarJLabel;
private JTextField dollarJTextField;
// JLabel and JTextField to input currency type to convert to
private JLabel typeJLabel;
private JTextField typeJTextField;
// JLabel and JTextField to display converted value
private JLabel convertedJLabel;
private JTextField convertedJTextField;
// JButton to initiate conversion
private JButton convertJButton;
// no-argument constructor
public CurrencyConverter()
{
createUserInterface();
}
// create and position GUI components; register event handlers
private void createUserInterface()
{
// get content pane for attaching GUI components
Container contentPane = getContentPane();
// enable explicit positioning of GUI components
contentPane.setLayout( null );
// set up dollarJLabel
dollarJLabel = new JLabel();
dollarJLabel.setBounds( 16, 16, 128, 21 );
dollarJLabel.setText( "Dollars to convert:" );
contentPane.add( dollarJLabel );
// set up dollarJTextField
dollarJTextField = new JTextField();
dollarJTextField.setBounds( 175, 16, 96, 21 );
dollarJTextField.setHorizontalAlignment( JTextField.RIGHT );
contentPane.add( dollarJTextField );
// set up typeJLabel
typeJLabel = new JLabel();
typeJLabel.setBounds( 16, 56, 150, 21 );
typeJLabel.setText( "Convert from dollars to:" );
contentPane.add( typeJLabel );
// set up typeJTextField
typeJTextField = new JTextField();
typeJTextField.setBounds( 175, 56, 96, 21 );
typeJTextField.setHorizontalAlignment( JTextField.RIGHT );
contentPane.add( typeJTextField );
// set up convertedJLabel
convertedJLabel = new JLabel();
convertedJLabel.setBounds( 16, 96, 112, 24 );
convertedJLabel.setText( "Converted amount:" );
contentPane.add( convertedJLabel );
// set up convertedJTextField
convertedJTextField = new JTextField();
convertedJTextField.setBounds( 175, 96, 96, 21 );
convertedJTextField.setHorizontalAlignment(
JTextField.RIGHT );
convertedJTextField.setEditable( false );
contentPane.add( convertedJTextField );
// set up convertJButton and register its event handler
convertJButton = new JButton();
convertJButton.setText( "Convert" );
convertJButton.setBounds( 175, 136, 96, 24 );
contentPane.add( convertJButton );
convertJButton.addActionListener(
new ActionListener() // anonymous inner class
{
// event handler called when convertJButton is pressed
public void actionPerformed ( ActionEvent event )
{
convertJButtonActionPerformed( event );
}
} // end anonymous inner class
); // end call to addActionListener
// set properties of application's window
setTitle( "Currency Converter" ); // set title bar text
setSize( 300, 200 ); // set window size
setVisible( true ); // display window
} // end method createUserInterface
// this method is called when the user clicks convertJButton
private void convertJButtonActionPerformed( ActionEvent event )
{
//FORMULA NEEDEDHERE
}
//
public static void main( String[] args )
{
CurrencyConverter application = new CurrencyConverter();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
}
thank you