Skip to content

Commit

Permalink
Merge pull request #1 from jiajun0308/jiajun0308-patch-1
Browse files Browse the repository at this point in the history
Update Finance_Hub.java
  • Loading branch information
jiajun0308 authored Apr 23, 2017
2 parents 7071b7c + ec8cb51 commit fee901b
Showing 1 changed file with 45 additions and 7 deletions.
52 changes: 45 additions & 7 deletions Finance_Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
class Finance_Hub extends JFrame{

public JLabel poundJLabel;
public JCheckBox rupeeJCheckBox, euroJCheckBox;
public JTextField poundJTextField, rupeeJTextField,euroJTextField;
public JCheckBox rupeeJCheckBox, euroJCheckBox, dollarJCheckBox, yenJCheckBox;
public JTextField poundJTextField, rupeeJTextField,euroJTextField, dollarJTextField, yenJTextField;
public JButton convertJButton;

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -46,7 +46,7 @@ public void creatGUI(){
contentPane.setLayout( null );

poundJLabel = new JLabel();
poundJLabel.setText( "Amount £: " );
poundJLabel.setText( "Amount £: " );
poundJLabel.setBounds(20,20,120,30);
contentPane.add(poundJLabel);

Expand All @@ -55,11 +55,21 @@ public void creatGUI(){
rupeeJCheckBox.setBounds(20,60,100,20);
contentPane.add(rupeeJCheckBox);

euroJCheckBox = new JCheckBox();
euroJCheckBox = new JCheckBox();
euroJCheckBox.setText( "Euro" );
euroJCheckBox.setBounds(20,100,100,20);
contentPane.add(euroJCheckBox);

dollarJCheckBox = new JCheckBox();
dollarJCheckBox.setText( "Dollar" );
dollarJCheckBox.setBounds(20,140,100,20);
contentPane.add(dollarJCheckBox);

yenJCheckBox = new JCheckBox();
yenJCheckBox.setText( "Yen" );
yenJCheckBox.setBounds(20,180,100,20);
contentPane.add(yenJCheckBox);

poundJTextField = new JTextField();
poundJTextField.setBounds(130,20,80,30);
poundJTextField.setHorizontalAlignment(JTextField.RIGHT);
Expand Down Expand Up @@ -87,10 +97,24 @@ public void keyPressed(KeyEvent e){
euroJTextField = new JTextField();
euroJTextField.setBounds(130,100,80,20);
euroJTextField.setHorizontalAlignment(JTextField.RIGHT);
euroJTextField.setText( "€ 0.00" );
euroJTextField.setText( "€ 0.00" );
euroJTextField.setEditable(false);
contentPane.add(euroJTextField);


dollarJTextField = new JTextField();
dollarJTextField.setBounds(130,140,80,20);
dollarJTextField.setHorizontalAlignment(JTextField.RIGHT);
dollarJTextField.setText( "$ 0.00" );
dollarJTextField.setEditable(false);
contentPane.add(dollarJTextField);

yenJTextField = new JTextField();
yenJTextField.setBounds(130,180,80,20);
yenJTextField.setHorizontalAlignment(JTextField.RIGHT);
yenJTextField.setText( "¥ 0.00" );
yenJTextField.setEditable(false);
contentPane.add(yenJTextField);

convertJButton = new JButton();
convertJButton.setText( "Calculate Foreign Currency" );
convertJButton.setBounds(20,220,200,30);
Expand Down Expand Up @@ -125,11 +149,23 @@ public void convertActionPerformed(ActionEvent e){

if(euroJCheckBox.isSelected()){

DecimalFormat dfr = new DecimalFormat( "€ 0.00" );
DecimalFormat dfr = new DecimalFormat( "€ 0.00" );
double euroAmount = amount * findExchangeRateAndConvert("GBP", "EUR", 1);
euroJTextField.setText(dfr.format(euroAmount));
}

if(dollarJCheckBox.isSelected()){

DecimalFormat dfd = new DecimalFormat( "$ 0.00" );
double dollarAmount = amount * findExchangeRateAndConvert("GBP", "USD", 1);
dollarJTextField.setText(dfd.format(dollarAmount));
}

if(yenJCheckBox.isSelected()){

DecimalFormat dfd = new DecimalFormat( "¥ 0.00" );
double yenAmount = amount * findExchangeRateAndConvert("GBP", "JPY", 1);
yenJTextField.setText(dfd.format(yenAmount));
}
};

Expand All @@ -138,6 +174,8 @@ public void poundsKeyPressed(KeyEvent e){

rupeeJTextField.setText( "0" );
euroJTextField.setText( "0" );
dollarJTextField.setText( "0" );
yenJTextField.setText( "0" );
}

//---------------------------------------------------------------------------------
Expand Down

0 comments on commit fee901b

Please sign in to comment.