Project dan Class Frame Form
Dalam latihan kali ini coba membuat sebuah project dan class
( Mobil ).
public class Mobil extends javax.swing.JFrame {
int ac,central,kaca,total,bayar,harga;
// Code Combo Box ( KodeMobil )
private void CmbKodeActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(CmbKode.getSelectedItem().equals("MAV01")){
tfnama.setText("AVANZA");
harga=125000000;
tfharga.setText(String.valueOf(harga));
if(tftotal.getText().equals("")){
bayar=0;
}
else{
bayar=Integer.parseInt(tftotal.getText());
}
total=bayar+harga;
tftotal.setText(String.valueOf(total));
}
if(CmbKode.getSelectedItem().equals("MXE02")){
tfnama.setText("XENIA");
harga=115000000;
tfharga.setText(String.valueOf(harga));
if(tftotal.getText().equals("")){
bayar=0;
}
else{
bayar=Integer.parseInt(tftotal.getText());
}
total=bayar+harga;
tftotal.setText(String.valueOf(total));
}
if(CmbKode.getSelectedItem().equals("MIN03")){
tfnama.setText("INNOVA");
harga=150000000;
tfharga.setText(String.valueOf(harga));
if(tftotal.getText().equals("")){
bayar=0;
}
else{
bayar=Integer.parseInt(tftotal.getText());
}
total=bayar+harga;
tftotal.setText(String.valueOf(total));
}
}
// Code Radio Button ( CC/DC , Cash )
private void rb2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(rb2.isSelected()){
int a=Integer.parseInt(tfharga.getText());
int b=20000;
int c=a+b;
tfbayar.setText(String.valueOf(b));
tftotal.setText(String.valueOf(c));
}
}
private void rb1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(rb1.isSelected()){
int a=Integer.parseInt(tfharga.getText());
int b=10000;
int c=a+b;
tfbayar.setText(String.valueOf(b));
tftotal.setText(String.valueOf(c));
}
}
// Code Check Box ( AC,Central Lock,Kaca Film )
private void cb2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(cb2.isSelected()){
central=20000;
total=ac+central+kaca+bayar+harga;
tfcentral.setText(String.valueOf(central));
tftotal.setText(String.valueOf(total));
}
else {
central=0;
total=ac+central+kaca+bayar+harga;
tfcentral.setText(String.valueOf(central));
tftotal.setText(String.valueOf(total));
}
}
private void cb1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(cb1.isSelected()){
ac=10000;
total=ac+central+kaca+bayar+harga;
tfac.setText(String.valueOf(ac));
tftotal.setText(String.valueOf(total));
}
else {
ac=0;
total=ac+central+kaca+bayar+harga;
tfac.setText(String.valueOf(ac));
tftotal.setText(String.valueOf(total));
}
}
private void cb3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(cb3.isSelected()){
kaca=50000;
total=ac+central+kaca+bayar+harga;
tfkaca.setText(String.valueOf(kaca));
tftotal.setText(String.valueOf(total));
}
else {
kaca=0;
total=ac+central+kaca+bayar+harga;
tfkaca.setText(String.valueOf(kaca));
tftotal.setText(String.valueOf(total));
}
}
// Code Button ( Bersih )
private void btn1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
tfnama.setText("");
tfbayar.setText("");
tfharga.setText("");
tfac.setText("");
tfcentral.setText("");
tfkaca.setText("");
tftotal.setText("");
cb1.setSelected(false);
cb2.setSelected(false);
cb3.setSelected(false);
}
// Code Button ( Keluar )
private void btn2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JOptionPane.showMessageDialog(null,"ThankYou","Exit",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
/**
* @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(Mobil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Mobil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Mobil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Mobil.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 Mobil().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JComboBox CmbKode;
private javax.swing.JButton btn1;
private javax.swing.JButton btn2;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JCheckBox cb1;
private javax.swing.JCheckBox cb2;
private javax.swing.JCheckBox cb3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JRadioButton rb1;
private javax.swing.JRadioButton rb2;
private javax.swing.JTextField tfac;
private javax.swing.JTextField tfbayar;
private javax.swing.JTextField tfcentral;
private javax.swing.JTextField tfharga;
private javax.swing.JTextField tfkaca;
private javax.swing.JTextField tfnama;
private javax.swing.JTextPane tftotal;
// End of variables declaration
}
int ac,central,kaca,total,bayar,harga;
// Code Combo Box ( KodeMobil )
private void CmbKodeActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(CmbKode.getSelectedItem().equals("MAV01")){
tfnama.setText("AVANZA");
harga=125000000;
tfharga.setText(String.valueOf(harga));
if(tftotal.getText().equals("")){
bayar=0;
}
else{
bayar=Integer.parseInt(tftotal.getText());
}
total=bayar+harga;
tftotal.setText(String.valueOf(total));
}
if(CmbKode.getSelectedItem().equals("MXE02")){
tfnama.setText("XENIA");
harga=115000000;
tfharga.setText(String.valueOf(harga));
if(tftotal.getText().equals("")){
bayar=0;
}
else{
bayar=Integer.parseInt(tftotal.getText());
}
total=bayar+harga;
tftotal.setText(String.valueOf(total));
}
if(CmbKode.getSelectedItem().equals("MIN03")){
tfnama.setText("INNOVA");
harga=150000000;
tfharga.setText(String.valueOf(harga));
if(tftotal.getText().equals("")){
bayar=0;
}
else{
bayar=Integer.parseInt(tftotal.getText());
}
total=bayar+harga;
tftotal.setText(String.valueOf(total));
}
}
// Code Radio Button ( CC/DC , Cash )
private void rb2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(rb2.isSelected()){
int a=Integer.parseInt(tfharga.getText());
int b=20000;
int c=a+b;
tfbayar.setText(String.valueOf(b));
tftotal.setText(String.valueOf(c));
}
}
private void rb1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(rb1.isSelected()){
int a=Integer.parseInt(tfharga.getText());
int b=10000;
int c=a+b;
tfbayar.setText(String.valueOf(b));
tftotal.setText(String.valueOf(c));
}
}
// Code Check Box ( AC,Central Lock,Kaca Film )
private void cb2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(cb2.isSelected()){
central=20000;
total=ac+central+kaca+bayar+harga;
tfcentral.setText(String.valueOf(central));
tftotal.setText(String.valueOf(total));
}
else {
central=0;
total=ac+central+kaca+bayar+harga;
tfcentral.setText(String.valueOf(central));
tftotal.setText(String.valueOf(total));
}
}
private void cb1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(cb1.isSelected()){
ac=10000;
total=ac+central+kaca+bayar+harga;
tfac.setText(String.valueOf(ac));
tftotal.setText(String.valueOf(total));
}
else {
ac=0;
total=ac+central+kaca+bayar+harga;
tfac.setText(String.valueOf(ac));
tftotal.setText(String.valueOf(total));
}
}
private void cb3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(cb3.isSelected()){
kaca=50000;
total=ac+central+kaca+bayar+harga;
tfkaca.setText(String.valueOf(kaca));
tftotal.setText(String.valueOf(total));
}
else {
kaca=0;
total=ac+central+kaca+bayar+harga;
tfkaca.setText(String.valueOf(kaca));
tftotal.setText(String.valueOf(total));
}
}
// Code Button ( Bersih )
private void btn1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
tfnama.setText("");
tfbayar.setText("");
tfharga.setText("");
tfac.setText("");
tfcentral.setText("");
tfkaca.setText("");
tftotal.setText("");
cb1.setSelected(false);
cb2.setSelected(false);
cb3.setSelected(false);
}
// Code Button ( Keluar )
private void btn2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JOptionPane.showMessageDialog(null,"ThankYou","Exit",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
/**
* @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(Mobil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Mobil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Mobil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Mobil.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 Mobil().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JComboBox CmbKode;
private javax.swing.JButton btn1;
private javax.swing.JButton btn2;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JCheckBox cb1;
private javax.swing.JCheckBox cb2;
private javax.swing.JCheckBox cb3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JRadioButton rb1;
private javax.swing.JRadioButton rb2;
private javax.swing.JTextField tfac;
private javax.swing.JTextField tfbayar;
private javax.swing.JTextField tfcentral;
private javax.swing.JTextField tfharga;
private javax.swing.JTextField tfkaca;
private javax.swing.JTextField tfnama;
private javax.swing.JTextPane tftotal;
// End of variables declaration
}
Tidak ada komentar:
Posting Komentar