Вы находитесь на странице: 1из 7

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package cConvert;

/**
*
* @author Mahesh
*/
public class cConverters extends javax.swing.JFrame {

double Nigerian_Naira = 302.96;


double US_Dollar = 1;
double Kenyan_Shilling = 156.21;
double Brazilian_Real = 5.86;
double Canadian_Dollar = 2.03;
double Indian_Rupee = 71;
double Philippine_Peso = 71.74;
double Indonesian_Rupiah = 20746.75;

/**
* Creates new form cConverters
*/
public cConverters() {
initComponents();
}

/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

buttonGroup1 = new javax.swing.ButtonGroup();


buttonGroup2 = new javax.swing.ButtonGroup();
jLabel1 = new javax.swing.JLabel();
jcmbCurrency = new javax.swing.JComboBox();
jlblConvert = new javax.swing.JLabel();
jtxtConvert = new javax.swing.JTextField();
jbtnExit = new javax.swing.JButton();
jbtnReset = new javax.swing.JButton();
jbtnConvert = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setFont(new java.awt.Font("Tahoma", 1, 60)); // NOI18N


jLabel1.setText("Currancy Converter");
jLabel1.setBorder(javax.swing.BorderFactory.createLineBorder(new
java.awt.Color(255, 255, 255), 4));

jcmbCurrency.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N


jcmbCurrency.setModel(new javax.swing.DefaultComboBoxModel(new String[]
{ "Choose One...", "USA", "Nigeria", "Brazil", "Canada", "Kenyan", "Indonesia",
"India", "Philippine" }));
jcmbCurrency.setBorder(javax.swing.BorderFactory.createLineBorder(new
java.awt.Color(0, 0, 0), 4));

jlblConvert.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N


jlblConvert.setBorder(javax.swing.BorderFactory.createLineBorder(new
java.awt.Color(255, 255, 255), 4));
jlblConvert.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

jtxtConvert.setFont(new java.awt.Font("Tahoma", 2, 48)); // NOI18N


jtxtConvert.setHorizontalAlignment(javax.swing.JTextField.CENTER);

jbtnExit.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N


jbtnExit.setText("Exit");
jbtnExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtnExitActionPerformed(evt);
}
});

jbtnReset.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N


jbtnReset.setText("Reset");
jbtnReset.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtnResetActionPerformed(evt);
}
});

jbtnConvert.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N


jbtnConvert.setText("Convert");
jbtnConvert.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtnConvertActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new


javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addComponent(jcmbCurrency,
javax.swing.GroupLayout.PREFERRED_SIZE, 277,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(253, 253, 253))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addComponent(jlblConvert,
javax.swing.GroupLayout.PREFERRED_SIZE, 370,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(207, 207, 207))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addComponent(jtxtConvert,
javax.swing.GroupLayout.PREFERRED_SIZE, 207,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(291, 291, 291))))
.addGroup(layout.createSequentialGroup()
.addGap(275, 275, 275)
.addComponent(jLabel1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(181, 181, 181)
.addComponent(jbtnConvert, javax.swing.GroupLayout.PREFERRED_SIZE,
236, javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35,
Short.MAX_VALUE)
.addComponent(jbtnReset)
.addGap(19, 19, 19)
.addComponent(jbtnExit, javax.swing.GroupLayout.PREFERRED_SIZE,
139, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(154, 154, 154))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(34, 34, 34)
.addComponent(jLabel1)
.addGap(35, 35, 35)
.addComponent(jcmbCurrency, javax.swing.GroupLayout.PREFERRED_SIZE,
44, javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jtxtConvert, javax.swing.GroupLayout.PREFERRED_SIZE,
53, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jlblConvert, javax.swing.GroupLayout.PREFERRED_SIZE,
68, javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 42,
Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jbtnReset,
javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jbtnExit, javax.swing.GroupLayout.PREFERRED_SIZE,
46, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jbtnConvert,
javax.swing.GroupLayout.PREFERRED_SIZE, 60,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(31, 31, 31))
);

pack();
}// </editor-fold>

private void jbtnExitActionPerformed(java.awt.event.ActionEvent evt) {

System.exit(0); // TODO add your handling code here:


}

private void jbtnResetActionPerformed(java.awt.event.ActionEvent evt) {

jtxtConvert.setText(null);
jlblConvert.setText(null);
jcmbCurrency.setSelectedIndex(0);
// TODO add your handling code here:
}

private void jbtnConvertActionPerformed(java.awt.event.ActionEvent evt) {

double British_Pound = Double.parseDouble(jtxtConvert.getText());

if(jcmbCurrency.getSelectedItem().equals("Nigeria"))
{
String cConvert1 = String.format("N %.2f", British_Pound *
Nigerian_Naira);
jlblConvert.setText(cConvert1);

}
if(jcmbCurrency.getSelectedItem().equals("USA"))
{
String cConvert1 = String.format("$ %.2f", British_Pound *
US_Dollar);
jlblConvert.setText(cConvert1);

if(jcmbCurrency.getSelectedItem().equals("Kenyan"))
{
String cConvert1 = String.format("KS %.2f", British_Pound *
Kenyan_Shilling);
jlblConvert.setText(cConvert1);

}
if(jcmbCurrency.getSelectedItem().equals("Brazil"))
{
String cConvert1 = String.format("Bra %.2f", British_Pound *
Brazilian_Real);
jlblConvert.setText(cConvert1);

}
if(jcmbCurrency.getSelectedItem().equals("Canada"))
{
String cConvert1 = String.format("C$ %.2f", British_Pound *
Canadian_Dollar);
jlblConvert.setText(cConvert1);

}
if(jcmbCurrency.getSelectedItem().equals("India"))
{
String cConvert1 = String.format("Inr %.2f", British_Pound *
Indian_Rupee);
jlblConvert.setText(cConvert1);

}
if(jcmbCurrency.getSelectedItem().equals("Philippine"))
{
String cConvert1 = String.format("PhP %.2f", British_Pound *
Philippine_Peso);
jlblConvert.setText(cConvert1);

}
if(jcmbCurrency.getSelectedItem().equals("Indonesia"))
{
String cConvert1 = String.format("Idr %.2f", British_Pound *
Indonesian_Rupiah);
jlblConvert.setText(cConvert1);

}
// TODO add your handling code here:
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code
(optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the
default look and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {

java.util.logging.Logger.getLogger(cConverters.class.getName()).log(java.util.loggi
ng.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(cConverters.class.getName()).log(java.util.loggi
ng.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(cConverters.class.getName()).log(java.util.loggi
ng.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(cConverters.class.getName()).log(java.util.loggi
ng.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new cConverters().setVisible(true);
}
});
}

// Variables declaration - do not modify


private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.ButtonGroup buttonGroup2;
private javax.swing.JLabel jLabel1;
private javax.swing.JButton jbtnConvert;
private javax.swing.JButton jbtnExit;
private javax.swing.JButton jbtnReset;
private javax.swing.JComboBox jcmbCurrency;
private javax.swing.JLabel jlblConvert;
private javax.swing.JTextField jtxtConvert;
// End of variables declaration
}

Вам также может понравиться