Professional Documents
Culture Documents
Latihan Java
Latihan Java
*/
@SuppressWarnings("unchecked")
// Cara Pembuatan Method :
void hitung(){
if(chidangan.getSelectedItem().toString().equalsIgnoreCase("BAKAR") &&
rbtnayam.isSelected()){
tharga.setText("20000");
ckemasan.requestFocus();
}
else if(chidangan.getSelectedItem().toString().equalsIgnoreCase("BAKAR") &&
rbtnbebek.isSelected()){
tharga.setText("30000");
ckemasan.requestFocus();
}
else if(chidangan.getSelectedItem().toString().equalsIgnoreCase("GULAI") &&
rbtnayam.isSelected()){
tharga.setText("15000");
ckemasan.requestFocus();
}
else if(chidangan.getSelectedItem().toString().equalsIgnoreCase("GULAI") &&
rbtnbebek.isSelected()){
tharga.setText("25000");
ckemasan.requestFocus();
}
else{
tharga.setText("0");
rbtnayam.requestFocus();
}
}
--------------------------------------------------------------------------------------1. Radio Button Ayam :
private void rbtnayamActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// Pemanggilan method :
hitung();
}
2. Radio Button Bebek :
private void rbtnbebekActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// Pemanggilan method :
hitung();
}
3. Combo Box Hidangan :
private void chidanganActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// Pemanggilan method :
hitung();
}
6. Button Bersih :
private void btnbersihActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
btngrpmkn.clearSelection();
chidangan.setSelectedIndex(0);
tharga.setText("0");
ckemasan.setSelectedIndex(0);
ttotal.setText("0");
tpot.setText("0");
ttotber.setText("0");
tbayar.setText("0");
tkembali.setText("0");
rbtnayam.requestFocus();
}
7. Button Keluar :
private void btnkeluarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int keluar=JOptionPane.showConfirmDialog(null,"Ingin
Keluar?","Pertanyaan",JOptionPane.YES_NO_OPTION);
if(keluar==0){
System.exit(0);
}
else{
return;
}
}
Penjualan
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package penjualan;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author dery
*/
public class Penjualan {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String kode_barang = "";
int jumlah_barang = 0;
String cara_beli = "";
String nama_barang = "";
double harga = 0;
double total_harga = 0;
double diskon = 0;
double bayar = 0;
BufferedReader baca = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Program Penjualan");
System.out.println("");
try {
System.out.print("Kode Barang : ");
kode_barang = baca.readLine();
System.out.print("Jumlah Barang : ");
jumlah_barang = Integer.valueOf(baca.readLine());
System.out.print("Cara Beli : ");
cara_beli = baca.readLine();
if (kode_barang.equalsIgnoreCase("SPT")) {
nama_barang = "Sepatu";
harga = 200000;
} else if (kode_barang.equalsIgnoreCase("SND")) {
nama_barang = "Sandal";
harga = 100000;
} else if (kode_barang.equalsIgnoreCase("TST")) {
nama_barang = "T-Shirt";
harga = 150000;
} else if (kode_barang.equalsIgnoreCase("TOP")) {
nama_barang = "Topi";
harga = 750000;
} else {
nama_barang = "-";
harga = 0;
}
total_harga = harga * jumlah_barang;
if (cara_beli.equalsIgnoreCase("T")) {
if (jumlah_barang > 20) {
diskon = total_harga * 0.1;
} else {
diskon = total_harga * 0.05;
}
} else if (cara_beli.equalsIgnoreCase("K")) {
if (jumlah_barang > 20) {
diskon = total_harga * 0.1;
} else {
diskon = total_harga;
}
}
bayar = total_harga - diskon;
System.out.println("Nama Barang : " + nama_barang);
System.out.println("Harga Barang : " + harga);
System.out.println("Total Harga : " + total_harga);
System.out.println("Diskon : " + diskon);
System.out.println("Bayar : " + bayar);
}
}
anpa Basa basi sekarang kita akan berusaha memahami cara penerapan Program JAVA menggunakan
NetBeans IDE.. Kita Langsung ke contoh permasalahan saja..
Cekibroooot...
>> Disini kita akan membuat contoh Form penjualan Mobil seperti gambar berikut ini
{
bayar=Integer.parseInt(tftotal.getText());
}
total = bayar + harga;
tftotal.setText(String.valueOf(total));
}
else 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));
}
else if(cmbkode.getSelectedItem().equals("MIN03")){
tfnama.setText("INNOVA");
harga=135000000;
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));
}
}
>> Untuk RadioButton (kita permisalkan rd1 & rd2) ketikan Listing berikut ini..
private void rd1ActionPerformed(java.awt.event.ActionEvent evt) {
if(rd1.isSelected()){
int a=Integer.parseInt(tfharga.getText());
int b = 20000;
int c = a+b;
tfbayar.setText(String.valueOf(b));
tftotal.setText(String.valueOf(c));
}
}
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));
}
}
>> Dan terakhir untuk Button Bersih & Keluar, Ketikan Listing berikut ini:
private void jbbersihActionPerformed(java.awt.event.ActionEvent evt) {
tfnama.setText("");
tfharga.setText("");
tfharga.setText("");
tfcentral.setText("");
tfac.setText("");
tfkaca.setText("");
tftotal.setText("");
tfbayar.setText("");
ch1.setSelected(false);
ch2.setSelected(false);
ch3.setSelected(false);
buttonGroup1.clearSelection();
}
private void jbkeluarActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
Maka Hasilnya sebagai contoh akan tampak kurang lebih seperti ini :