Friday, 19 July 2019

Aplikasi Sederhana Menggunakan Netbeans & MYSQL

Aplikasi berikut adalah aplikasi sederhana yg dibuat dengan Netbeans dan bisa di konek dengan mysql.

Berikut adalah Sreen Shoot hasilnya :








Source Code :

package tugas;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
/**
 *
 *
 */
public class hotel extends javax.swing.JFrame {
int harga,lama,biaya,bayar;
Connection db;
Statement s;
ResultSet r;
String nama,kode,tipe,Hkamar,Lama,Fasilitas,tgl;
int f,total,v,a;
    /**
     * Creates new form hotel
     */
    public hotel() {
        initComponents();
    }

    void koneksi() throws SQLException{
        db = DriverManager.getConnection("jdbc:mysql://localhost/tugas","root","");
        //s = db.createStatement();
        String query = "insert into data(nama,kode,tipe,tanggal,lama,fasilitas) values ('"+nama+"','"+kode+"','"+tipe+"','"+tgl+"','"+lama+"','"+Fasilitas+"')";
        PreparedStatement d = db.prepareStatement (query);
        d.execute();
        JOptionPane.showMessageDialog(null,"Data di simpan","Pesan",JOptionPane.INFORMATION_MESSAGE);

    }
    void tanggal(){
        Date d = new Date();
         SimpleDateFormat sdf = new SimpleDateFormat("E dd-MM-yyyy");
     tgl = sdf.format(d);
     jTanggal.setText(tgl);
    }

    void bayar() throws SQLException{

        nama = (String)jNama.getText();
        tgl = (String) jTanggal.getText();
        Lama = (String)jLama.getText();
        if(jcKode.getSelectedItem().equals("01TPLP")){
            kode = "01TPLP";
        }else if(jcKode.getSelectedItem().equals("02TPLE")){
            kode = "02TPLE";
        }else if(jcKode.getSelectedItem().equals("03TPLA")){
            kode = "03TPLA";
        }else if(jcKode.getSelectedItem().equals("04TPLS")){
            kode = "04TPLS";
        }

    if(jrMawar.isSelected()){
        tipe = "Mawar";
    }else if(jrTulip.isSelected()){
        tipe = "Tulip";
    }else if(jrBugenvil.isSelected()){
        tipe ="Bugenvil";
    }

    if(jTv.isSelected()){
        Fasilitas = "Televisi";
    }else if(jWf.isSelected()){
        Fasilitas = "Wifi";
    }
    koneksi();
    total = Integer.parseInt(jTotal.getText());
    v = Integer.parseInt(jBayar.getText());
    a = v - total;
    jKembali.setText(""+a);

    }
    void kamar(){
    if(jrMawar.isSelected()){
        harga = 300000;
    }else if(jrTulip.isSelected()){
        harga = 500000;
    }else if(jrBugenvil.isSelected()){
        harga = 1000000;
    }
    jHargakamar.setText(""+harga);
}
private void jTvActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        if (jTv.isSelected()){
            jTelevisi.setText(""+100000);
            jWifi.setText("");
            jWf.setSelected(false);
            jFasilitas.setText("Televisi");
        }else{
            jTelevisi.setText("");
            jFasilitas.setText("");
        }
    }
private void jWfActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        if (jWf.isSelected()){
            jWifi.setText(""+150000);
            jTelevisi.setText("");
            jTv.setSelected(false);
            jFasilitas.setText("Wifi");
        }else{
            jWifi.setText("");
            jFasilitas.setText("");
        }
    }
private void jLamaActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        harga = Integer.parseInt(jHargakamar.getText());
        lama = Integer.parseInt(jLama.getText());
        biaya = harga * lama ;
        jBiaya.setText(""+biaya);

    }
private void jbHitungActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        harga = Integer.parseInt(jBiaya.getText());
        if (jWf.isSelected()){
          f = 150000;
        }else if(jTv.isSelected()){
            f = 100000;
        }
        bayar = harga + f;
        jTotal.setText(""+bayar);
    }
private void jbBayarActionPerformed(java.awt.event.ActionEvent evt) {
    try {
        // TODO add your handling code here:
        bayar();
    } catch (SQLException ex) {
        Logger.getLogger(hotel.class.getName()).log(Level.SEVERE, null, ex);
    }
    }
private void jbKeluarActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        hotel2 b = new hotel2();
        b.setVisible(true);
        this.dispose();
    }.

Semoga Bermanfaat ^^.

No comments:

Post a Comment