Konverter Mata Uang
Pada project kali ini kami berdua membuat sebuah aplikasi yang dapat membantu banyak orang yang mungkin pada saat orang tersebut lagi tidak ada di negeri tersebut, maka aplikasi yang kami akan membantu mereka. Anggota yang membuat project ini adalah :
- Muhammad Naufaldillah - 05111940000202
- Aji Rindra Fakhrezi Putra Faisal - 05111940000205
Asal mula kami memikirkan untuk membuat project ini adalah, banyak orang yang berpergian untuk keluar negeri dan yang pastinya di luar negeri akan mengeluarkan beberapa uang yang dibawanya. Oleh karena itu, orang-orang yang berpergian akan melakukan perhitungan pada saat diluar negeri untuk mengeluarkan berapa banyak uang yang akan dikeluarkan. Maka dari itu kami membuat aplikasi Konverter Mata Uang, dengan aplikasi ini para pengguna bisa mengetahui berapa banyak nominal yang mereka akan keluar dalam bentuk mata uang negara lain. Aplikasi ini dapat membantu para pengguna untuk merencanakan berapa banyak uang yang akan dikeluarkan. Aplikasi ini hanya memiliki satu class :
- CurrencyConverterClass.java : merupakan class utama yang berisikan JFrame untuk windowsnya dan algoritma untuk menghitung berapa nominal yang akan di hitung menjadi mata uang yang diinginkan
import java.awt.EventQueue; | |
import javax.swing.JFrame; | |
import java.awt.GridBagLayout; | |
import java.awt.BorderLayout; | |
import javax.swing.JLabel; | |
import java.awt.Font; | |
import javax.swing.SwingConstants; | |
import javax.swing.JComboBox; | |
import javax.swing.DefaultComboBoxModel; | |
import javax.swing.JButton; | |
import java.awt.event.ActionListener; | |
import java.awt.event.ActionEvent; | |
import javax.swing.JTextField; | |
public class CurrencyConverterClass { | |
// Nilai Mata Uang | |
double Pounds = 0.74; | |
double European_Euro = 0.82; | |
double Australian_Dollar = 1.29; | |
double Canadian_Dollar = 1.27; | |
double Hongkong_Dollar = 7.76; | |
double Indonesian_Rupiah = 14135.35; | |
double Indian_Rupee = 73.38; | |
double Japanese_Yen = 103.95; | |
double Southkorean_won = 1093.01; | |
//String mata uang | |
String[] currencyUnits = { | |
"Units", | |
"US Dollar", | |
"Pound Sterling", | |
"European Euro", | |
"Australian Dollar", | |
"Canadian Dollar", | |
"Hong Kong Dollar", | |
"Indonesian Rupiah", | |
"Indian Rupee", | |
"Japanese Yen", | |
"South Korean Won" | |
}; | |
private JFrame frame; | |
private JTextField textField; | |
private JTextField textField_1; | |
//Deklarasi variable | |
private JComboBox<String> comboBox; | |
private JComboBox<String> comboBox_1; | |
private JLabel lblNewLabel_2; | |
private JLabel lblNewLabel_2_1; | |
private JLabel lblNewLabel; | |
private JLabel lblNewLabel_1; | |
private JLabel lblNewLabel_1_1; | |
private JButton btnNewButton; | |
private JButton btnReset; | |
private JButton btnKeluar; | |
/** | |
* Launch the application. | |
*/ | |
public static void main(String[] args) { | |
EventQueue.invokeLater(new Runnable() { | |
public void run() { | |
try { | |
CurrencyConverterClass window = new CurrencyConverterClass(); | |
window.frame.setVisible(true); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
}); | |
} | |
/** | |
* Create the application. | |
*/ | |
public CurrencyConverterClass() { | |
initialize(); | |
} | |
/** | |
* Initialize the contents of the frame. | |
*/ | |
private void initialize() { | |
frame = new JFrame(); | |
frame.setBounds(100, 100, 700, 400); | |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
frame.getContentPane().setLayout(null); | |
lblNewLabel = new JLabel("Konverter Mata Uang"); | |
lblNewLabel.setBounds(0, 0, 686, 28); | |
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER); | |
lblNewLabel.setFont(new Font("Arial", Font.PLAIN, 24)); | |
frame.getContentPane().add(lblNewLabel); | |
lblNewLabel_1 = new JLabel("Dari Mata Uang"); | |
lblNewLabel_1.setFont(new Font("Arial", Font.PLAIN, 14)); | |
lblNewLabel_1.setBounds(69, 90, 110, 13); | |
frame.getContentPane().add(lblNewLabel_1); | |
lblNewLabel_1_1 = new JLabel("Ke Mata Uang"); | |
lblNewLabel_1_1.setFont(new Font("Arial", Font.PLAIN, 14)); | |
lblNewLabel_1_1.setBounds(424, 91, 110, 13); | |
frame.getContentPane().add(lblNewLabel_1_1); | |
comboBox = new JComboBox(); | |
comboBox.setFont(new Font("Arial", Font.PLAIN, 18)); | |
comboBox.setModel(new DefaultComboBoxModel(new String[] {"Pilih Salah Satu...", "USD", "GBP" ,"EUR", "AUD", "CAD", "HKD", "IDR", "INR", "JPY", "KRW"})); | |
comboBox.addItemListener(new java.awt.event.ItemListener() { | |
public void itemStateChanged(java.awt.event.ItemEvent evt) { | |
firstCountryItemStateChanged(evt); | |
} | |
}); | |
comboBox.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
firstCountryActionPerformed(evt); | |
} | |
}); | |
comboBox.setBounds(69, 113, 208, 21); | |
frame.getContentPane().add(comboBox); | |
comboBox_1 = new JComboBox(); | |
comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"Pilih Salah Satu...", "USD", "GBP" ,"EUR", "AUD", "CAD", "HKD", "IDR", "INR", "JPY", "KRW"})); | |
comboBox_1.addItemListener(new java.awt.event.ItemListener() { | |
public void itemStateChanged(java.awt.event.ItemEvent evt) { | |
secondCountryItemStateChanged(evt); | |
} | |
}); | |
comboBox_1.setFont(new Font("Arial", Font.PLAIN, 18)); | |
comboBox_1.setBounds(424, 114, 208, 21); | |
frame.getContentPane().add(comboBox_1); | |
btnNewButton = new JButton("Konversi Mata Uang"); | |
btnNewButton.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent e) { | |
double amountToChange=Double.parseDouble(textField.getText()); | |
double amountChanged=0.0; | |
double amountInDollar=0.0; | |
switch(comboBox.getSelectedItem().toString()) | |
{ | |
case "USD":amountInDollar = amountToChange;break; | |
case "GBP":amountInDollar = amountToChange/Pounds;break; | |
case "EUR":amountInDollar = amountToChange/European_Euro;break; | |
case "AUD":amountInDollar = amountToChange/Australian_Dollar;break; | |
case "CAD":amountInDollar = amountToChange/Canadian_Dollar;break; | |
case "HKD":amountInDollar = amountToChange/Hongkong_Dollar;break; | |
case "IDR":amountInDollar = amountToChange/Indonesian_Rupiah;break; | |
case "INR":amountInDollar = amountToChange/Indian_Rupee;break; | |
case "JPY":amountInDollar = amountToChange/Japanese_Yen;break; | |
case "KRW":amountInDollar = amountToChange/Southkorean_won;break; | |
default:amountInDollar = 0.0; | |
} | |
//Jumlah diubah dalam UK Poundsterling | |
switch(comboBox_1.getSelectedItem().toString()) | |
{ | |
case "USD":amountChanged = amountInDollar;break; | |
case "GBP":amountChanged = amountInDollar * Pounds;break; | |
case "EUR":amountChanged = amountInDollar * European_Euro;break; | |
case "AUD":amountChanged = amountInDollar * Australian_Dollar;break; | |
case "CAD":amountChanged = amountInDollar * Canadian_Dollar;break; | |
case "HKD":amountChanged = amountInDollar * Hongkong_Dollar;break; | |
case "IDR":amountChanged = amountInDollar * Indonesian_Rupiah;break; | |
case "INR":amountChanged = amountInDollar * Indian_Rupee;break; | |
case "JPY":amountChanged = amountInDollar * Japanese_Yen;break; | |
case "KRW":amountChanged = amountInDollar * Southkorean_won;break; | |
default:amountChanged = amountInDollar * 0.0; | |
} | |
String value = String.format("%.2f",amountChanged); | |
textField_1.setText(value); | |
} | |
}); | |
btnNewButton.setFont(new Font("Arial", Font.PLAIN, 18)); | |
btnNewButton.setBounds(27, 261, 208, 31); | |
frame.getContentPane().add(btnNewButton); | |
btnReset = new JButton("Atur Ulang"); | |
btnReset.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent e) { | |
comboBox.setSelectedIndex(0); | |
comboBox_1.setSelectedIndex(0); | |
textField.setText(""); | |
textField_1.setText(""); | |
} | |
}); | |
btnReset.setFont(new Font("Arial", Font.PLAIN, 18)); | |
btnReset.setBounds(245, 261, 208, 31); | |
frame.getContentPane().add(btnReset); | |
btnKeluar = new JButton("Keluar"); | |
btnKeluar.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent e) { | |
System.exit(0); | |
} | |
}); | |
btnKeluar.setFont(new Font("Arial", Font.PLAIN, 18)); | |
btnKeluar.setBounds(463, 261, 208, 31); | |
frame.getContentPane().add(btnKeluar); | |
textField = new JTextField(); | |
textField.setFont(new Font("Arial", Font.PLAIN, 18)); | |
textField.setBounds(69, 144, 208, 28); | |
frame.getContentPane().add(textField); | |
textField.setColumns(10); | |
textField_1 = new JTextField(); | |
textField_1.setFont(new Font("Arial", Font.PLAIN, 18)); | |
textField_1.setColumns(10); | |
textField_1.setBounds(424, 144, 208, 28); | |
frame.getContentPane().add(textField_1); | |
lblNewLabel_2 = new JLabel("Units"); | |
lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT); | |
lblNewLabel_2.setFont(new Font("Arial", Font.PLAIN, 14)); | |
lblNewLabel_2.setBounds(69, 182, 208, 13); | |
frame.getContentPane().add(lblNewLabel_2); | |
lblNewLabel_2_1 = new JLabel("Units"); | |
lblNewLabel_2_1.setHorizontalAlignment(SwingConstants.RIGHT); | |
lblNewLabel_2_1.setFont(new Font("Arial", Font.PLAIN, 14)); | |
lblNewLabel_2_1.setBounds(424, 182, 208, 13); | |
frame.getContentPane().add(lblNewLabel_2_1); | |
} | |
private void firstCountryActionPerformed(java.awt.event.ActionEvent evt) | |
{ | |
} | |
private void firstCountryItemStateChanged(java.awt.event.ItemEvent evt) | |
{ | |
lblNewLabel_2.setText(currencyUnits[comboBox.getSelectedIndex()]); | |
} | |
private void secondCountryItemStateChanged(java.awt.event.ItemEvent evt) | |
{ | |
lblNewLabel_2_1.setText(currencyUnits[comboBox_1.getSelectedIndex()]); | |
} | |
} |
Output :
Konverter Mata Uang
Comments
Post a Comment