From ec8cb5102e31ef99e99844f8a49e7983c96d4f27 Mon Sep 17 00:00:00 2001 From: Jia Jun Date: Sun, 23 Apr 2017 02:20:39 +0100 Subject: [PATCH] Update Finance_Hub.java I have added two currency options to the program which will enhance the program's features. I am looking forward to change the interface to make it more accessible through web platforms but at the moment I will stick with this first. Please review the work and check if the code I applied is appropriate. --- Finance_Hub.java | 52 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/Finance_Hub.java b/Finance_Hub.java index 29867cf..0a78176 100644 --- a/Finance_Hub.java +++ b/Finance_Hub.java @@ -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; //----------------------------------------------------------------------------- @@ -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); @@ -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); @@ -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); @@ -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)); } }; @@ -138,6 +174,8 @@ public void poundsKeyPressed(KeyEvent e){ rupeeJTextField.setText( "0" ); euroJTextField.setText( "0" ); + dollarJTextField.setText( "0" ); + yenJTextField.setText( "0" ); } //---------------------------------------------------------------------------------