1. berikut coding yang saya buat :
/*
* 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 tugas;
import javax.swing.JOptionPane;
/**
*
* @author ucuu
*/
public class TugasU extends javax.swing.JFrame {
/**
* Creates new form TugasU
*/
public TugasU() {
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() {
btngroup = new javax.swing.ButtonGroup();
btngroup.add(btnUSD);
btngroup.add(btnEUR);
btngroup.add(btnMYR);
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
txtuang = new javax.swing.JTextField();
btnUSD = new javax.swing.JRadioButton();
btnEUR = new javax.swing.JRadioButton();
btnMYR = new javax.swing.JRadioButton();
jLabel4 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
outIDR = new javax.swing.JTextField();
btnclear = new javax.swing.JButton();
btnexit = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setFont(new java.awt.Font("Trebuchet MS", 0, 14)); // NOI18N
jLabel1.setText("konversi Mata Uang Di Dunia");
jLabel2.setText("Uang Yang Di Konversi");
jLabel3.setText("Besarnya Uang");
btnUSD.setText("USD (Dolar USA)");
btnUSD.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnUSDActionPerformed(evt);
}
});
btnEUR.setText("EURO");
btnEUR.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEURActionPerformed(evt);
}
});
btnMYR.setText("MYR ( Ringgit Malaysia)");
btnMYR.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnMYRActionPerformed(evt);
}
});
jLabel4.setText("Uang Hasil Konversi");
jLabel6.setText("IDR Rupiah");
btnclear.setText("Clear");
btnclear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnclearActionPerformed(evt);
}
});
btnexit.setText("Exit");
btnexit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnexitActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(61, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(btnEUR)
.addGap(18, 18, 18)
.addComponent(btnUSD)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, Short.MAX_VALUE)
.addComponent(btnMYR))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel3)
.addGap(18, 18, 18)
.addComponent(txtuang, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(btnclear, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnexit, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel6)
.addGap(54, 54, 54)
.addComponent(outIDR, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(43, 43, 43)))
.addComponent(jLabel2))
.addGap(0, 0, Short.MAX_VALUE)))
.addGap(35, 35, 35))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(35, 35, 35)
.addComponent(jLabel1)
.addGap(39, 39, 39)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(txtuang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnEUR)
.addComponent(btnMYR)
.addComponent(btnUSD))
.addGap(85, 85, 85)
.addComponent(jLabel4)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(outIDR, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnclear, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnexit, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(59, 59, 59))
);
pack();
}// </editor-fold>
private void btnUSDActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int b1=Integer.parseInt(txtuang.getText());
if(btnUSD.isSelected()){
int b2=b1*12506;
outIDR.setText(""+b2);
}else
outIDR.setText(" ");
}
private void btnclearActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(JOptionPane.showConfirmDialog(null,"Data Akan Di Hapus??","CLEAR",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE)==JOptionPane.YES_OPTION){
txtuang.setText(" ");
outIDR.setText(" ");
btnEUR.setSelected(false);
btnUSD.setSelected(false);
btnMYR.setSelected(false);
}else{
JOptionPane.showMessageDialog(null,"Anda Membatalkan","Pesan",JOptionPane.CANCEL_OPTION);
}
}
private void btnEURActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int b1=Integer.parseInt(txtuang.getText());
if(btnEUR.isSelected()){
int b2=b1*14175;
outIDR.setText(""+b2);
}else
outIDR.setText(" ");
}
private void btnMYRActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int b1=Integer.parseInt(txtuang.getText());
if(btnMYR.isSelected()){
int b2=b1*3463;
outIDR.setText(""+b2);
}else
outIDR.setText(" ");
}
private void btnexitActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(JOptionPane.showConfirmDialog(null,"Yakin Akan Keluar?","EXIT",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE)==JOptionPane.YES_OPTION){
System.exit(0);
}else{
JOptionPane.showMessageDialog(null,"Anda Membatalkan","Pesan",JOptionPane.CANCEL_OPTION);
}
}
/**
* @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(TugasU.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(TugasU.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(TugasU.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(TugasU.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TugasU().setVisible(true);
JOptionPane.showMessageDialog(null,"Selamat Datang DI Konversi Rupiah","Pesan",JOptionPane.INFORMATION_MESSAGE);
}
});
}
// Variables declaration - do not modify
private javax.swing.JRadioButton btnEUR;
private javax.swing.JRadioButton btnMYR;
private javax.swing.JRadioButton btnUSD;
private javax.swing.JButton btnclear;
private javax.swing.JButton btnexit;
private javax.swing.ButtonGroup btngroup;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel6;
private javax.swing.JTextField outIDR;
private javax.swing.JTextField txtuang;
// End of variables declaration
}
2. hasil Run file:
