Jumat, 21 Juli 2017

                                 

                                                     Assalamualikum wr.wb
             Pada kesempatan kali saya akan menjelaskan tentang program input data pasien, langsung      
         saja saya akan menjelaskan dibawah ini..


1. buat databese
 

2. kemudian designnya 











3.source codenya;;;;;package rifan;
import com.mysql.jdbc.Statement;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import koneksi.conek;
import javax.swing.table.DefaultTableModel;


/**
 *
 * @author ERWIN
 */
public class Fan extends javax.swing.JFrame {
int BAYAR;
    /**
     * Creates new form Fan
     */
    public Fan() {
        initComponents();
        datatable();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
    private void initComponents() {

        NAMA = new javax.swing.JLabel();
        ALAMAT = new javax.swing.JLabel();
        RAWAT = new javax.swing.JLabel();
        EXIT = new javax.swing.JButton();
        DATA = new javax.swing.JLabel();
        txt1 = new javax.swing.JTextField();
        txt3 = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        table = new javax.swing.JTable();
        cmb1 = new javax.swing.JComboBox<>();
        jLabel1 = new javax.swing.JLabel();
        SAVE = new javax.swing.JButton();
        txt4 = new javax.swing.JTextField();
        REFRESH = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txt2 = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        NAMA.setText("NAMA");

        ALAMAT.setText("ALAMAT");

        RAWAT.setText("RAWAT INAP");

        EXIT.setText("EXIT");
        EXIT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EXITActionPerformed(evt);
            }
        });

        DATA.setText("DATA PASIEN");

        table.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(table);

        cmb1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1 HARI", "1 MINGGU", "1 BULAN", "1 TAHUN", " " }));
        cmb1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmb1ActionPerformed(evt);
            }
        });

        jLabel1.setText("PENYAKIT");

        SAVE.setText("SAVE");
        SAVE.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SAVEActionPerformed(evt);
            }
        });

        REFRESH.setText("REFRESH");
        REFRESH.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                REFRESHActionPerformed(evt);
            }
        });

        jLabel2.setText("BAYAR");

        txt2.setColumns(20);
        txt2.setRows(5);
        jScrollPane1.setViewportView(txt2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 410, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                            .addComponent(ALAMAT)
                                            .addGap(121, 121, 121))
                                        .addGroup(layout.createSequentialGroup()
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(RAWAT)
                                                .addComponent(jLabel1)
                                                .addComponent(NAMA))
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(7, 7, 7)
                                        .addComponent(SAVE)
                                        .addGap(97, 97, 97)))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(REFRESH)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(EXIT)
                                        .addGap(27, 27, 27))
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(cmb1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(txt1)
                                        .addComponent(jScrollPane1)
                                        .addComponent(txt3)
                                        .addComponent(txt4)))))
                        .addContainerGap(12, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(0, 0, Short.MAX_VALUE))))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(194, 194, 194)
                    .addComponent(DATA)
                    .addContainerGap(188, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(51, 51, 51)
                        .addComponent(txt1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(NAMA)
                        .addGap(36, 36, 36)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ALAMAT, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmb1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(RAWAT))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txt3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(txt4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(53, 53, 53)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(SAVE)
                    .addComponent(REFRESH)
                    .addComponent(EXIT))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(DATA)
                    .addContainerGap(490, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>                       

    private void cmb1ActionPerformed(java.awt.event.ActionEvent evt) {                                    
        // TODO add your handling code here:
        if (cmb1.getSelectedItem().equals("1 HARI")){
            txt3.setText("jantung");
            BAYAR=50000;
            txt4.setText(""+BAYAR);
        }
        else if (cmb1.getSelectedItem().equals("1 MINGGU")){
            txt3.setText("paru-paru");
            BAYAR=300000;
            txt4.setText(""+BAYAR);
        }
        else if (cmb1.getSelectedItem().equals("1 BULAN")){
            txt3.setText("asma");
            BAYAR=20000000;
            txt4.setText(""+BAYAR);
        }
        else if (cmb1.getSelectedItem().equals("1 TAHUN")){
            txt3.setText("kanker");
            BAYAR=10000000;
            txt4.setText(""+BAYAR);
        }
    }                                   

    private void SAVEActionPerformed(java.awt.event.ActionEvent evt) {                                    
        // TODO add your handling code here:
        String nama=txt1.getText();
        String alamat=txt2.getText();
        String rawat=(String)cmb1.getSelectedItem();
        String penyakit=txt3.getText();
        String bayar=txt4.getText();
       
        try{
            Statement sta =(Statement) conek.GetConnection().createStatement();
            sta.executeUpdate("INSERT INTO tbdata VALUES('"+nama+"','"+alamat+"','"+rawat+"','"+penyakit+"','"+bayar+"')");
            JOptionPane.showMessageDialog(null,"Data telah Di Simpan silahkan REFRESH");
           
        }catch(Exception e){
            JOptionPane.showMessageDialog(null,"Terjadi kesalahan");
        }
       
    }                                   

    private void REFRESHActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
        DefaultTableModel tbl = new DefaultTableModel();
        tbl.addColumn("nama");
        tbl.addColumn("alamat");
        tbl.addColumn("rawat");
        tbl.addColumn("penyakit");
        tbl.addColumn("bayar");
        table.setModel(tbl);
        try{
            Statement sta=(Statement) conek.GetConnection().createStatement();
            ResultSet res=sta.executeQuery("SELECT * FROM tbdata");
            while(res.next())
            {
                tbl.addRow(new Object[]{
                   res.getString("nama"),
                    res.getString("alamat"),
                    res.getString("rawat"),
                    res.getString("penyakit"),
                    res.getString("bayar"),
                   
                });
            table.setModel(tbl);
            }
        }catch(Exception e){
            JOptionPane.showMessageDialog(null,"Terjadi Kesalahan saat menampilkan data");
        }
    }                                      

    private void EXITActionPerformed(java.awt.event.ActionEvent evt) {                                    
        // TODO add your handling code here:
        dispose();
    }                                   

    public void datatable(){
        DefaultTableModel tbl = new DefaultTableModel();
        tbl.addColumn("nama");
        tbl.addColumn("alamat");
        tbl.addColumn("rawat");
        tbl.addColumn("penyakit");
        tbl.addColumn("bayar");
        table.setModel(tbl);
        try{
            Statement sta=(Statement) conek.GetConnection().createStatement();
            ResultSet res=sta.executeQuery("SELECT * FROM tbdata");
            while(res.next())
            {
                tbl.addRow(new Object[]{
                   res.getString("nama"),
                    res.getString("alamat"),
                    res.getString("rawat"),
                    res.getString("penyakit"),
                    res.getString("bayar"),
                   
                });
            table.setModel(tbl);
            }
        }catch(Exception e){
            JOptionPane.showMessageDialog(null,"Terjadi Kesalahan saat menampilkan data");
        }
    }
    /**
     * @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(Fan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Fan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Fan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Fan.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 Fan().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                    
    private javax.swing.JLabel ALAMAT;
    private javax.swing.JLabel DATA;
    private javax.swing.JButton EXIT;
    private javax.swing.JLabel NAMA;
    private javax.swing.JLabel RAWAT;
    private javax.swing.JButton REFRESH;
    private javax.swing.JButton SAVE;
    private javax.swing.JComboBox<String> cmb1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable table;
    private javax.swing.JTextField txt1;
    private javax.swing.JTextArea txt2;
    private javax.swing.JTextField txt3;
    private javax.swing.JTextField txt4;
    // End of variables declaration                  
}
                                              sekian danterimakasih