program sederhan tanpa memakai database (Java)


Kita akan belajar gimana cara membuat program sederhan tanpa memakai database dijava.karna tidak memakai database pasti pada bingung.gimana cara nyimpannya data yang kita inputkan karna dia tak punya databasenya utuk penyimpanan misalnya kita input datanya, karna tidak memakai database berarti hanya bisa menyimpann sementara aja jika programnya di stop atau dikeluarkan maka datanya akan kembali ke nol. Pasti pada bingung lagi dimana letak penyimpanan data sementarannya.jika hanya program yang lagi jalan aja datanya akan tesimpan. Kita akan menggunakan table utuk penyimpanan sementara.. seperti yang sudah di jelaskan program penyimpanan ini hanya bisa ketika program lagi aktif.

 Sekarang akan kita buat program Penjualan tanpa memakai database. Buatlah tampilan seperti gambar dibawah ini
Jangn lupa kita juga memakai rumus cara mencari jumlah..
Rumusnya total= harga *qty
Jika sudah dapat jumla =- total- (total*10%)
rumusmencari pajak.. =total+(total*10%)
dan seterusnya

ini perintah koding dibawah in : copy passte aja



* penjualan.java
 *
*/
public class penjualan extends javax.swing.JFrame {

    /** Creates new form penjualan*/
    public penjualan () {
        initComponents();
           tabel.setModel(tblmodel);

    }
 String data[]=new String[6];
    private javax.swing.table.DefaultTableModel
            tblmodel=getDefaultTableModel();
    int row=0;

    private javax.swing.table.DefaultTableModel getDefaultTableModel(){
        return new javax.swing.table.DefaultTableModel
                (new Object[][]{},new String[]{"kode barang","nama","harga","qty","disc","jumlah"})
                {
           boolean canedit []=new boolean []{false,false,false,false,false};
                    public boolean isCellEditTable (int rowint,int colint)
                    {
                        return canedit[colint];
                    }

        };
    }
    public void tampil(){
           row=tabel.getSelectedRow();
           jTextField5.setText(tblmodel.getValueAt(row,0).toString());

               jTextField6.setText(tblmodel.getValueAt(row,1).toString());
              jTextField7.setText(tblmodel.getValueAt(row,2).toString());
               jTextField8.setText(tblmodel.getValueAt(row,3).toString());
                jTextField9.setText(tblmodel.getValueAt(row,4).toString());
              jTextField10.setText(tblmodel.getValueAt(row,5).toString());
        }

  public void total(){
            int totsks=0;
            int jumrec= tabel.getRowCount();
            for(int i=0;i<jumrec;i++)
            {
                totsks=  (int) (totsks + Double.parseDouble(tblmodel.getValueAt(i, 5).toString()));
            }
          jTextField11.setText(String.valueOf(totsks));
  }
private void jTextField9ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        int a=Integer.parseInt(jTextField7.getText());
        int b=Integer.parseInt(jTextField8.getText());
        int c=Integer.parseInt(jTextField9.getText());
        int d;
        int s;
        int hasil;
        d=a*b;
        s=d*c/100;
        hasil=d-s;


        jTextField10.setText(String.valueOf(hasil));
}

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        data[0] =jTextField5.getText();
        data[1]= jTextField6.getText();
        data[2] =jTextField7.getText();
        data[3] =jTextField8.getText();
        data[4] =jTextField9.getText();
        data[5] =jTextField10.getText();
        tblmodel.insertRow(row, data);
        total();
         clear ();
    }

    private void jTextField12KeyReleased(java.awt.event.KeyEvent evt) {
        // TODO add your handling code here:
       
}

    private void jTextField14KeyPressed(java.awt.event.KeyEvent evt) {
        // TODO add your handling code here:
   
}

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        data[0] =jTextField5.getText();
        data[1]= jTextField6.getText();
        data[2] =jTextField7.getText();
        data[3] =jTextField8.getText();
        data[4] =jTextField9.getText();
        data[5] =jTextField10.getText();
        tblmodel.removeRow(row);
        tblmodel.insertRow(row, data);
          total();
          clear();
}

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
         data[0] =jTextField5.getText();
        data[1]= jTextField6.getText();
        data[2] =jTextField7.getText();
        data[3] =jTextField8.getText();
        data[4] =jTextField9.getText();
        data[5] =jTextField10.getText();
        tblmodel.removeRow(row);
          total();

    }

    private void tabelMouseClicked(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
         if(evt.getClickCount()==1){
            tampil();
        }
    }

    private void jTextField9KeyReleased(java.awt.event.KeyEvent evt) {
        // TODO add your handling code here:
    }

    private void jTextField9KeyPressed(java.awt.event.KeyEvent evt) {
        // TODO add your handling code here:
    }

    private void jTextField12ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        int a=Integer.parseInt(jTextField11.getText());
        int b=Integer.parseInt(jTextField12.getText());
        int d;
        int s;
        int c=a*b/100;
        s=a+c;
        jTextField13.setText(String.valueOf(s));
    }

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

    private void jTextField14ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
            int a=Integer.parseInt(jTextField13.getText());
        int b=Integer.parseInt(jTextField14.getText());
        int c;
        c=b-a;
        jTextField15.setText(String.valueOf(c));
    }

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        this.dispose();
    }
public void clear (){
      jTextField1.setText("");
    jTextField2.setText("");
    jTextField3.setText("");
     jTextField4.setText("");
       jTextField5.setText("");
    jTextField6.setText("");
    jTextField7.setText("");
     jTextField8.setText("");
       jTextField9.setText("");
    jTextField10.setText("");


semoga bermafaat





 

No comments:

Post a Comment

VIRUS

Do not open any attachment received from the unknown or untrusted sender Do not plug in any external USB drive into the company ...