Sie sind auf Seite 1von 2

import static java.lang.Class.

forName;
import java.sql.*;
import java.text.*;
import javax.swing.*;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.JOptionPane;
import javax.swing.plaf.OptionPaneUI;

public class Quiz extends javax.swing.JFrame {


public Connection con;
public Statement st;
public ResultSet rs;
public String sql="";

public Quiz() {
initComponents();
setLocationRelativeTo(null);
koneksi();
Proses
int harga=0;
int jmlbeli=0;
int totharga=0;
Float diskon;
int jmlbayar;
String bonus="";
int totbayar=0;

harga = Integer.parseInt(vharga.getText());
jmlbeli = Integer.parseInt(vjmlbeli.getText());

totharga=jmlbeli*harga;

vtotharga.setText(String.valueOf(totharga));

if(totharga >=1000000)
{
diskon=(float)0.25*totharga;
bonus="Kipas Angin";
}
else if(totharga >=5000000)
{
diskon=(float)0.22*totharga;
bonus="Strika";
}
else if(totharga >=1000000)
{
diskon=(float)0.15*totharga;
bonus="Payung";
}
else if(totharga >=50000)
{
diskon=(float)0.1*totharga;
bonus="Gelas Kaca";
}
else
{
diskon=(float)0*totharga;
bonus="Kantong Plastik";
}

vdiskon.setText(String.valueOf(diskon));
vbonus.setText(String.valueOf(bonus));

totbayar = (int) (totharga-diskon);

vjmlbayar.setText(String.valueOf(totbayar));
bersih/tambah
vnama.setText("");
vbarang.setText("");
vdiskon.setText("");
vharga.setText("");
vjmlbayar.setText("");
vtotharga.setText("");
vbonus.setText("");
vjmlbeli.setText("");
keluar
this.dispose();
simpan
try {
sql ="insert into transaksi values('"+vnama.getText()
+"','"+vbarang.getText()
+"','"+vharga.getText()
+"','"+vjmlbeli.getText()
+"','"+vtotharga.getText()
+"','"+vdiskon.getText()
+"','"+vbonus.getText()
+"','"+vjmlbayar.getText()+"')";
st.execute(sql);
JOptionPane.showMessageDialog(rootPane, "Berhasil Menyimpan");
} catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, "Gagal Menyimpan"+e);
}

private void koneksi() {


try {
Class.forName("com.mysql.jdbc.Driver");
con =DriverManager.getConnection("jdbc:mysql://localhost/penjualan","root","");
st =con.createStatement();
JOptionPane.showMessageDialog(rootPane, "OKE");
} catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, "GAGAL"+e);
}
}
}

Das könnte Ihnen auch gefallen