Your SlideShare is downloading. ×
Arsip coding java rev1
Arsip coding java rev1
Arsip coding java rev1
Arsip coding java rev1
Arsip coding java rev1
Arsip coding java rev1
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Arsip coding java rev1

58

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
58
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. //Merubah tampilan cursorprivate void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { jTextField1.setCursor(new Cursor(Cursor.WAIT_CURSOR));}//Ngeprint JTableprivate void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { MessageFormat header = new MessageFormat("Data Siswa"); MessageFormat footer = new MessageFormat("Jumlah yang telah dibayar : " +jTable1.getRowCount()); try { jTable1.print(JTable.PrintMode.FIT_WIDTH, header, footer); } catch (java.awt.print.PrinterException e) { System.err.format("Cannot print %s%n", e.getMessage()); }}//Entity Classpublic class Buku { private String id_buku; private String nid; private String nama_buku; private String penerbit; private String tahun_buku; private String jenjang_buku; private String jumlah; private String status_buku; private String harga_buku; public String getId_buku() { return id_buku; } public void setId_buku(String id_buku) { this.id_buku = id_buku; } public String getNid() { return nid; } public void setNid(String nid) { this.nid = nid; } public String getNama_buku() { return nama_buku; }
  • 2. public void setNama_buku(String nama_buku) { this.nama_buku = nama_buku;}public String getPenerbit() { return penerbit;}public void setPenerbit(String penerbit) { this.penerbit = penerbit;}public String getTahun_buku() { return tahun_buku;}public void setTahun_buku(String tahun_buku) { this.tahun_buku = tahun_buku;}public String getJenjang_buku() { return jenjang_buku;}public void setJenjang_buku(String jenjang_buku) { this.jenjang_buku = jenjang_buku;}public String getJumlah() { return jumlah;}public void setJumlah(String jumlah) { this.jumlah = jumlah;}public String getStatus_buku() { return status_buku;}public void setStatus_buku(String status_buku) { this.status_buku = status_buku;}public String getHarga_buku() { return harga_buku;}public void setHarga_buku(String harga_buku) { this.harga_buku = harga_buku;}
  • 3. }//Multiple Selection TableString list = "Jumlah terseleksi : "+jTable1.getSelectedRowCount()+"n";int i [] = jTable1.getSelectedRows();for (int j = 0; j < i.length; j++) { list += jTable1.getValueAt(i[j], 0)+"n";}JOptionPane.showMessageDialog(null, list);//Multiple Selection Delete Tableint i [] = tableBuku.getSelectedRows();for (int j = 0; j < i.length; j++) { bukuService.deleteBuku(tableBuku.getValueAt(i[j], 0).toString());}//addItem jCombo tahun dan setSelectedItemCombo berdasarkan tahun sekarangint tahun = 1981;for (int i = 0; i < 50; i++) { comboTahun.addItem(""+tahun++);}comboTahun.setSelectedItem(setTahun());public String setTahun(){ Date date = new Date(); SimpleDateFormat formatTahun = new SimpleDateFormat("yyyy"); String tahun1 = formatTahun.format(date); return tahun1;}//Loginpublic boolean isLoginAdmin(String user, String pass){ try { preparedStatement = null; preparedStatement = DatabaseUtilities.getConnection().prepareStatement( "SELECT * FROM ADMIN WHERE NID = ? and Password = ?"); preparedStatement.setString(1, user); preparedStatement.setString(2, pass); ResultSet rs = preparedStatement.executeQuery(); if(rs.next()){ return true; }else{ return false;
  • 4. } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "Login Gagal, Karena : "+ex.getMessage()); } return false;}//Insert Bukupublic void insertBuku(Buku buku){ preparedStatement = null; try { preparedStatement = DatabaseUtilities.getConnection().prepareStatement( "INSERT INTO BUKU (ID_BUKU, NID, NAMA_BUKU, PENERBIT, " + "TAHUN_BUKU, JENJANG_BUKU, JUMLAH, STATUS_BUKU, " + "HARGA_BUKU) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); preparedStatement.setString(1, buku.getId_buku()); preparedStatement.setString(2, buku.getNid()); preparedStatement.setString(3, buku.getNama_buku()); preparedStatement.setString(4, buku.getPenerbit()); preparedStatement.setString(5, buku.getTahun_buku()); preparedStatement.setString(6, buku.getJenjang_buku()); preparedStatement.setString(7, buku.getJumlah()); preparedStatement.setString(8, buku.getStatus_buku()); preparedStatement.setString(9, buku.getHarga_buku()); int insertBuku = preparedStatement.executeUpdate(); if(insertBuku == 1){ JOptionPane.showMessageDialog(null, "Insert berhasil"); }else{ JOptionPane.showMessageDialog(null, "Insert gagal","ErrorMessage",JOptionPane.ERROR_MESSAGE); } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "Insert gagal karena :"+ex.getMessage(),"Error Message",JOptionPane.ERROR_MESSAGE); }}//Update Bukupublic void updateBuku(Buku buku){ preparedStatement = null; try { preparedStatement = DatabaseUtilities.getConnection().prepareStatement( "UPDATE BUKU SET NID = ?, NAMA_BUKU = ?, PENERBIT = ?, " + "TAHUN_BUKU = ?, JENJANG_BUKU = ?, JUMLAH = ?, STATUS_BUKU = ?, " + "HARGA_BUKU = ? WHERE ID_BUKU = ?");
  • 5. preparedStatement.setString(1, buku.getNid()); preparedStatement.setString(2, buku.getNama_buku()); preparedStatement.setString(3, buku.getPenerbit()); preparedStatement.setString(4, buku.getTahun_buku()); preparedStatement.setString(5, buku.getJenjang_buku()); preparedStatement.setString(6, buku.getJumlah()); preparedStatement.setString(7, buku.getStatus_buku()); preparedStatement.setString(8, buku.getHarga_buku()); preparedStatement.setString(9, buku.getId_buku()); int update = preparedStatement.executeUpdate(); if(update == 1 ){ JOptionPane.showMessageDialog(null, "Edit buku berhasil"); }else{ JOptionPane.showMessageDialog(null, "Edit buku gagal","ErrorMessage",JOptionPane.ERROR_MESSAGE); } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "Edit buku gagal karena :"+ex.getMessage(),"Error Message",JOptionPane.ERROR_MESSAGE); }}//Delete Bukupublic void deleteBuku(String id_buku){ preparedStatement = null; try { preparedStatement = DatabaseUtilities.getConnection().prepareStatement( "DELETE FROM BUKU WHERE ID_BUKU = ?"); preparedStatement.setString(1, id_buku); int delete = preparedStatement.executeUpdate(); if(delete == 1){ JOptionPane.showMessageDialog(null, "Hapus buku berhasil"); }else{ JOptionPane.showMessageDialog(null, "Hapus buku gagal","ErrorMessage",JOptionPane.ERROR_MESSAGE); } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "Hapus buku gagal karena : "+ex.getMessage()); }}
  • 6. //Default Table Modelpublic DefaultTableModel getAllSiswa(){ DefaultTableModel model = null; model = new DefaultTableModel(); model.addColumn("NIS"); model.addColumn("NID"); model.addColumn("NAMA SISWA"); model.addColumn("SEKOLAH SISWA"); model.addColumn("KELAS SISWA"); model.addColumn("JENIS KELAMIN"); statement = null; try { statement = DatabaseUtilities.getConnection().createStatement(); ResultSet rs = statement.executeQuery("SELECT * FROM SISWA"); while(rs.next()){ model.addRow(new Object[]{rs.getString("NIS"), rs.getString("NID"), rs.getString("NAMA_SISWA"), rs.getString("SEKOLAH_SISWA"), rs.getString("KELAS_SISWA"), rs.getString("JENIS_KELAMIN_SISWA")}); } } catch (SQLException ex) { Logger.getLogger(SiswaService.class.getName()).log(Level.SEVERE, null, ex); } return model;}

×