Aplikasi sederhana ini bisa dinamakan sebagai aplikasi pendaftaran haji dan umroh yang mana menggunakan data base mysql untuk menyimpan data yang telah dimasukkan. . . .lansung ke TKP adja. . . . . ..
Desain Form
Pada menu utama ini terlihat berbagai menu yang mana dalam menu itu ada,menu item selanjuttnya. . . . . . . .,,,
ini adalah ketika menu pada laporan dipilih
ini adalah tampilan ketika menu daftar dipilih
koding loggin
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tugas;
import javax.swing.JOptionPane;
import tugas.MenuUtama;
/**
*
* @author herii purnama
*/
public class Login extends javax.swing.JFrame {
/**
* Creates new form Login
*/
public Login() {
initComponents();
}
/**
* 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() {
jLabel1 = new javax.swing.JLabel();
txtNama = new javax.swing.JTextField();
jKatakunci = new javax.swing.JPasswordField();
jLabel2 = new javax.swing.JLabel();
btnMasuk = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Form Log In");
setBackground(javax.swing.UIManager.getDefaults().getColor("Button.light"));
setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage("a.png"));
jLabel1.setText("Nama Penguna");
jKatakunci.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jKatakunciActionPerformed(evt);
}
});
jLabel2.setText("Kata Kunci");
btnMasuk.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
btnMasuk.setMnemonic('M');
btnMasuk.setText("Masuk");
btnMasuk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnMasukActionPerformed(evt);
}
});
jButton2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jButton2.setMnemonic('B');
jButton2.setText("Batal");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
jLabel3.setText(" LOG IN");
jLabel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(64, 64, 64)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel1))
.addGap(65, 65, 65)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jKatakunci)
.addComponent(txtNama)))
.addGroup(layout.createSequentialGroup()
.addComponent(btnMasuk)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(30, 30, 30))
.addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(46, 46, 46)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(txtNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(25, 25, 25)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jKatakunci, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 57, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnMasuk)
.addComponent(jButton2))
.addGap(35, 35, 35))
);
pack();
}// </editor-fold>
private void jKatakunciActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void btnMasukActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String cUserBenar = "k1146";
String cPassBenar = "aku";
String cUser = txtNama.getText();
String cPass = String.valueOf(jKatakunci.getPassword());
if ((cUser.compareTo(cUserBenar)==0) && (cPass.compareTo(cPassBenar)==0))
{
new MenuUtama().setVisible(true);
dispose();
}
else
{
JOptionPane.showMessageDialog(this,"User atau password yang Anda masukkan salah");
txtNama.setText(" ");
jKatakunci.setText(" ");
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
/**
* @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(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Login.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 Login().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnMasuk;
private javax.swing.JButton jButton2;
private javax.swing.JPasswordField jKatakunci;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JTextField txtNama;
// End of variables declaration
}
koding menu utama
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tugas;
/**
*
* @author herii purnama
*/
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import static javax.swing.JOptionPane.showMessageDialog;
import tugas.Lap;
public class MenuUtama extends javax.swing.JFrame {
/**
* Creates new form menuUtama
*/
public MenuUtama() {
initComponents();
}
/**
* 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() {
jToolBar1 = new javax.swing.JToolBar();
jButton2 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
mnDaftar = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenu3 = new javax.swing.JMenu();
jMenuItem3 = new javax.swing.JMenuItem();
jMenu4 = new javax.swing.JMenu();
jMenuItem2 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Menu Utama");
setBackground(new java.awt.Color(0, 0, 0));
setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
jToolBar1.setRollover(true);
jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tugas/d.png"))); // NOI18N
jButton2.setText("Lap.detail jama'ah");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jToolBar1.add(jButton2);
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tugas/ICON-10kabah.png"))); // NOI18N
jMenu1.setText("Daftar");
mnDaftar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_K, java.awt.event.InputEvent.CTRL_MASK));
mnDaftar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tugas/g.png"))); // NOI18N
mnDaftar.setText("Daftar Jama'ah");
mnDaftar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnDaftarActionPerformed(evt);
}
});
jMenu1.add(mnDaftar);
jMenuBar1.add(jMenu1);
jMenu2.setText("Laporan");
jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tugas/e.png"))); // NOI18N
jMenuItem1.setText("Lap.Detail Jama'ah");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem1);
jMenuBar1.add(jMenu2);
jMenu3.setText("Tentang");
jMenu3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenu3ActionPerformed(evt);
}
});
jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tugas/c.png"))); // NOI18N
jMenuItem3.setText("Tentang");
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem3ActionPerformed(evt);
}
});
jMenu3.add(jMenuItem3);
jMenuBar1.add(jMenu3);
jMenu4.setText("Lain-lain");
jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tugas/f.png"))); // NOI18N
jMenuItem2.setText("keluar");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu4.add(jMenuItem2);
jMenuBar1.add(jMenu4);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 326, Short.MAX_VALUE)
.addGap(37, 37, 37))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE))
.addContainerGap())
);
pack();
}// </editor-fold>
private void mnDaftarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
new MenuDaftar(this,false).setVisible(true);
}
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
// TODO add your handling code here:
new Lap().setVisible(true);
} catch (SQLException ex) {
Logger.getLogger(MenuUtama.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void jMenu3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
showMessageDialog(this,"Herii Purnama.hpta");
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
// TODO add your handling code here:
new Lap().setVisible(true);
} catch (SQLException ex) {
Logger.getLogger(MenuUtama.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* @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(MenuUtama.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MenuUtama.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MenuUtama.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MenuUtama.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 MenuUtama().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JToolBar jToolBar1;
private javax.swing.JMenuItem mnDaftar;
// End of variables declaration
}
koding laporan
/*;
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tugas;
import java.awt.BorderLayout;
import java.awt.print.PrinterException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import net.sf.fjreport.tableprint.PageTablePrint;
/**
*
* @author herii purnama
*/
public class Lap extends javax.swing.JFrame {
String driver = "com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost/haji";
DefaultTableModel model;
JTable jTable1;
PageTablePrint pageTable = new PageTablePrint();
/**
* Creates new form Lap
*/
public Lap() throws SQLException {
initComponents();
browseData();
}
Lap(MenuUtama aThis) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
/**
* 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() {
JpanTampilan = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Laporan Pendaftaran Jama'ah");
setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage("a.png"));
javax.swing.GroupLayout JpanTampilanLayout = new javax.swing.GroupLayout(JpanTampilan);
JpanTampilan.setLayout(JpanTampilanLayout);
JpanTampilanLayout.setHorizontalGroup(
JpanTampilanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);
JpanTampilanLayout.setVerticalGroup(
JpanTampilanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 402, Short.MAX_VALUE)
);
jButton1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jButton1.setMnemonic('K');
jButton1.setText("Kembali");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jButton2.setMnemonic('C');
jButton2.setText("Cetak");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jLabel1.setText("Laporan Pendaftaran Jama'ah");
jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tugas/a.png"))); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(JpanTampilan, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton2)
.addGap(18, 18, 18)
.addComponent(jButton1)
.addGap(0, 665, Short.MAX_VALUE))))
.addGroup(layout.createSequentialGroup()
.addGap(273, 273, 273)
.addComponent(jLabel1)
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addComponent(jLabel2)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(26, Short.MAX_VALUE)
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(JpanTampilan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton2)
.addComponent(jButton1))
.addContainerGap())
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
dispose();
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
jTable1.print();
}
catch (PrinterException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void browseData() throws SQLException {
JpanTampilan.setLayout(new BorderLayout());
String query = "Select ID, Nama, Umur, Alamat,JK,JenisKeberangkatan from peserta";
Object[] data = new Object[10];
model = new DefaultTableModel();
int jmlkolom;
try {
Class.forName(driver);
Connection con=DriverManager.getConnection(url,"root","");
Statement stat = con.createStatement();
ResultSet rs = stat.executeQuery(query);
ResultSetMetaData rmeta = rs.getMetaData();
jmlkolom = rmeta.getColumnCount();
for(int i=1;i<=jmlkolom;++i) {
if(i<=jmlkolom) {
model.addColumn(rmeta.getColumnName(i));
}
}
while(rs.next()) {
for(int i=1;i<=jmlkolom;++i) {
if(i<=jmlkolom) {
data[i-1] = rs.getString(i);
}
}
model.addRow(data);
}
} catch(ClassNotFoundException eclass) {
JOptionPane.showMessageDialog(null,"Driver tidak ada","Driver",JOptionPane.WARNING_MESSAGE);
} catch(SQLException esql) {
JOptionPane.showMessageDialog(null,"Pernyataan SQL salah","Konfirmasi",JOptionPane.WARNING_MESSAGE);
}
jTable1 = new JTable(model);
JpanTampilan.add(new JScrollPane(jTable1));
}
/**
* @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(Lap.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Lap.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Lap.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Lap.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() {
try{ new Lap().setVisible(true);
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage(),"Kesalahan...", JOptionPane.WARNING_MESSAGE);
}
}
});
}
// Variables declaration - do not modify
private javax.swing.JPanel JpanTampilan;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
// End of variables declaration
}
koding untuk kelas koneksinya
package tugas;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Koneksi{
public Connection conn;
public Statement st;
public ResultSet rs;
private String db;
public void konek (String server,String user,String pswd,String db) {
System.out.println("Keterangan");
try{
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e){
System.out.println("Driver JDBC tidak berhasil di load");
return;
}
System.out.println("Driver berhasil diload");
conn = null ;
try {
conn = DriverManager.getConnection
("jdbc:mysql://"+server+":3306/"+db,user,pswd);
}
catch (SQLException e){
System.out.println("Tidak bisa koneksi DB");
e.printStackTrace();
return;
}
if (conn != null)
System.out.println ("Berhasil Koneksi");
else
System.out.println ("Gagal Koneksi");
}
public void koneksiku(){
konek("localhost","root","","haji");
}
}
~ oiya jangan lupa simpan semua formnya dalam satu paket ya. . . . . . nanti ndak error oke.oke.oke :) ~
0 komentar:
Post a Comment
Thanks For Your Feedback.