Você está na página 1de 4

Program GUI Sederhana

Membuat data base

Membuat Form hotel


berikut source code:

1 package tugas;
2 import java.sql.*;
3 import java.text.SimpleDateFormat;
4 import java.util.Date;
5 import java.util.logging.Level;
6 import java.util.logging.Logger;
7 import javax.swing.JOptionPane;
8 /**
9 *
10 * @author takaoni
11 */
12public class hotel extends javax.swing.JFrame {
13int harga,lama,biaya,bayar;
14Connection db;
15Statement s;
16ResultSet r;
17String nama,kode,tipe,Hkamar,Lama,Fasilitas,tgl;
18int f,total,v,a;
19 /**
20 * Creates new form hotel
21 */
22 public hotel() {
23 initComponents();
24 }
25
26 void koneksi() throws SQLException{
27 db =
28DriverManager.getConnection("jdbc:mysql://localhost/tugas","root","");
29 //s = db.createStatement();
30 String query = "insert into
31data(nama,kode,tipe,tanggal,lama,fasilitas) values
32('"+nama+"','"+kode+"','"+tipe+"','"+tgl+"','"+lama+"','"+Fasilitas+"')";
33 PreparedStatement d = db.prepareStatement (query);
34 d.execute();
35 JOptionPane.showMessageDialog(null,"Data di
36simpan","Pesan",JOptionPane.INFORMATION_MESSAGE);
37
38 }
39 void tanggal(){
40 Date d = new Date();
41 SimpleDateFormat sdf = new SimpleDateFormat("E dd-MM-yyyy");
42 tgl = sdf.format(d);
43 jTanggal.setText(tgl);
44 }
45
46
47 void bayar() throws SQLException{
48
49 nama = (String)jNama.getText();
50 tgl = (String) jTanggal.getText();
51 Lama = (String)jLama.getText();
52 if(jcKode.getSelectedItem().equals("01TPLP")){
53 kode = "01TPLP";
54 }else if(jcKode.getSelectedItem().equals("02TPLE")){
55 kode = "02TPLE";
56 }else if(jcKode.getSelectedItem().equals("03TPLA")){
57 kode = "03TPLA";
58 }else if(jcKode.getSelectedItem().equals("04TPLS")){
59 kode = "04TPLS";
60 }
61
62 if(jrMawar.isSelected()){
63 tipe = "Mawar";
64 }else if(jrTulip.isSelected()){
65 tipe = "Tulip";
66 }else if(jrBugenvil.isSelected()){
67 tipe ="Bugenvil";
68 }
69
70 if(jTv.isSelected()){
71 Fasilitas = "Televisi";
72 }else if(jWf.isSelected()){
73 Fasilitas = "Wifi";
74 }
75 koneksi();
76 total = Integer.parseInt(jTotal.getText());
77 v = Integer.parseInt(jBayar.getText());
78 a = v - total;
79 jKembali.setText(""+a);
80
81 }
82 void kamar(){
83
if(jrMawar.isSelected()){
84 harga = 300000;
85 }else if(jrTulip.isSelected()){
86 harga = 500000;
}else if(jrBugenvil.isSelected()){
harga = 1000000;
}
jHargakamar.setText(""+harga);
}
1 private void jTvActionPerformed(java.awt.event.ActionEvent evt) {
2 // TODO add your handling code here:
3 if (jTv.isSelected()){
4 jTelevisi.setText(""+100000);
5 jWifi.setText("");
6 jWf.setSelected(false);
7 jFasilitas.setText("Televisi");
8 }else{
9 jTelevisi.setText("");
10 jFasilitas.setText("");
11 }
12 }
1 private void jWfActionPerformed(java.awt.event.ActionEvent evt) {
2 // TODO add your handling code here:
3 if (jWf.isSelected()){
4 jWifi.setText(""+150000);
5 jTelevisi.setText("");
6 jTv.setSelected(false);
7 jFasilitas.setText("Wifi");
8 }else{
9 jWifi.setText("");
10 jFasilitas.setText("");
11 }
12 }
1 private void jLamaActionPerformed(java.awt.event.ActionEvent evt) {
2 // TODO add your handling code here:
3 harga = Integer.parseInt(jHargakamar.getText());
4 lama = Integer.parseInt(jLama.getText());
5 biaya = harga * lama ;
6 jBiaya.setText(""+biaya);
7
8 }
1 private void jbHitungActionPerformed(java.awt.event.ActionEvent evt) {
2 // TODO add your handling code here:
3 harga = Integer.parseInt(jBiaya.getText());
4 if (jWf.isSelected()){
5 f = 150000;
6 }else if(jTv.isSelected()){
7 f = 100000;
8 }
9 bayar = harga + f;
10 jTotal.setText(""+bayar);
11 }
private void jbBayarActionPerformed(java.awt.event.ActionEvent evt) {
1
try {
2
// TODO add your handling code here:
3
bayar();
4
} catch (SQLException ex) {
5
Logger.getLogger(hotel.class.getName()).log(Level.SEVERE, null,
6
ex);
7
}
8
}
1private void jbKeluarActionPerformed(java.awt.event.ActionEvent evt) {
2 // TODO add your handling code here:
3 hotel2 b = new hotel2();
4 b.setVisible(true);
5 this.dispose();
6 }

berikut hasil run:

Você também pode gostar