P. 1
Sistem Pakar

Sistem Pakar

|Views: 571|Likes:
Dipublikasikan oleh Eko Sugiharto
Sistem Pakar Untuk Mendiagnosa Kerusakan Komputer Menggunakan Java.
Status : Ready to use.
Sistem Pakar Untuk Mendiagnosa Kerusakan Komputer Menggunakan Java.
Status : Ready to use.

More info:

Published by: Eko Sugiharto on Apr 29, 2011
Hak Cipta:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

06/04/2013

pdf

text

original

Sections

TAMPILAN FORM DAN LISTING PROGRAM 1.

Form Pilihan Pengguna Sistem

package sistempakar; import java.awt.Dimension; import java.awt.Toolkit; /** * * @author Nabila Zahra Yulia */ public class formAwal extends javax.swing.JDialog { /** Creates new form formAwal */ public formAwal(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = this.getSize(); if (frameSize.height > screenSize.height){ frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width){ frameSize.width=screenSize.width; } this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height)/2); } private void btnPakarActionPerformed(java.awt.event.ActionEvent evt) { new LoginForm(new javax.swing.JFrame(), true).setVisible(true); this.dispose();

} private void btnPenggunaActionPerformed(java.awt.event.ActionEvent evt) { frmPengguna pengguna = new frmPengguna(); pengguna.setVisible(true); this.setVisible(false); } private void formWindowClosing(java.awt.event.WindowEvent evt) { System.exit(0); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { formAwal dialog = new formAwal(new javax.swing.JFrame(), true); dialog.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); dialog.setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton btnPakar; private javax.swing.JButton btnPengguna; private javax.swing.JLabel jLabel1; // End of variables declaration }

2.

Form Login Pakar

package sistempakar; import com.miftah.db.DBQuery; import com.miftah.db.DBTable; import java.awt.Dimension; import java.awt.Toolkit; import java.sql.SQLException; import javax.swing.JOptionPane; /** * * @author Nabila Zahra Yulia */ public class LoginForm extends javax.swing.JDialog { /** Creates new form LoginForm */ public LoginForm(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = this.getSize(); if (frameSize.height > screenSize.height){ frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width){ frameSize.width=screenSize.width; } this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height)/2); DBTable db = new DBTable(); db.setTableName("admin");

db.setDriver(SistemPakarApp.getDriver()); db.setActive(true); } private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) { Login(); } private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) { System.exit(0); } private void formWindowClosing(java.awt.event.WindowEvent evt) { System.exit(0); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { LoginForm dialog = new LoginForm(new javax.swing.JFrame(), true); dialog.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); dialog.setVisible(true); } }); } private void Login(){ try{ DBQuery q1 = new DBQuery(); q1.setDriver(SistemPakarApp.getDriver()); String strSql = "select * from admin where username= '" + txtUser.getText() + "' AND password = ('" +

String.copyValueOf(txtPassword.getPassword(),0,txtPassword .getPassword().length) + "')"; q1.setStrSql(strSql); q1.makeActive(true); if (q1.getRowCount() > 0){ SistemPakarApp.getInstanceMainMenu().setAuthentication(true); SistemPakarApp.getApplication().ShowMainMenu(); this.dispose(); }else{ JOptionPane.showMessageDialog(LoginForm.this, "Incorrect Username or Password", "Error", JOptionPane.ERROR_MESSAGE); } }catch (SQLException ex){ System.out.println(ex); } } // Variables declaration - do not modify private javax.swing.JButton btnCancel; private javax.swing.JButton btnLogin; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JPasswordField txtPassword; private javax.swing.JTextField txtUser; // End of variables declaration }

3.

Menu Utama Pakar

package sistempakar; import org.jdesktop.application.Action; import org.jdesktop.application.ResourceMap; import org.jdesktop.application.SingleFrameApplication; import org.jdesktop.application.FrameView; import org.jdesktop.application.TaskMonitor; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Timer; import javax.swing.Icon; import javax.swing.JDialog; import javax.swing.JFrame; /** * The application's main frame. */ public class SistemPakarView extends FrameView { public SistemPakarView(SingleFrameApplication app) { super(app); initComponents(); // status bar initialization - message timeout, idle icon and busy animation, etc ResourceMap resourceMap = getResourceMap(); int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");

messageTimer = new Timer(messageTimeout, new ActionListener() { public void actionPerformed(ActionEvent e) { statusMessageLabel.setText(""); } }); messageTimer.setRepeats(false); int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate"); for (int i = 0; i < busyIcons.length; i++) { busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]"); } busyIconTimer = new Timer(busyAnimationRate, new ActionListener() { public void actionPerformed(ActionEvent e) { busyIconIndex = (busyIconIndex + 1) % busyIcons.length; statusAnimationLabel.setIcon(busyIcons[busyIconIndex]); } }); idleIcon = resourceMap.getIcon("StatusBar.idleIcon"); statusAnimationLabel.setIcon(idleIcon); progressBar.setVisible(false); // connecting action tasks to status bar via TaskMonitor TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext()); taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() { public void propertyChange(java.beans.PropertyChangeEvent evt) { String propertyName = evt.getPropertyName(); if ("started".equals(propertyName)) { if (!busyIconTimer.isRunning()) { statusAnimationLabel.setIcon(busyIcons[0]); busyIconIndex = 0; busyIconTimer.start(); } progressBar.setVisible(true); progressBar.setIndeterminate(true); } else if ("done".equals(propertyName)) { busyIconTimer.stop(); statusAnimationLabel.setIcon(idleIcon); progressBar.setVisible(false);

progressBar.setValue(0); } else if ("message".equals(propertyName)) { String text = (String)(evt.getNewValue()); statusMessageLabel.setText((text == null) ? "" : text); messageTimer.restart(); } else if ("progress".equals(propertyName)) { int value = (Integer)(evt.getNewValue()); progressBar.setVisible(true); progressBar.setIndeterminate(false); progressBar.setValue(value); } } }); } @Action public void showAboutBox() { if (aboutBox == null) { JFrame mainFrame = SistemPakarApp.getApplication().getMainFrame(); aboutBox = new SistemPakarAboutBox(mainFrame); aboutBox.setLocationRelativeTo(mainFrame); } SistemPakarApp.getApplication().show(aboutBox); } private void logoutMenuItemActionPerformed(java.awt.event.ActionEvent evt) { setAuthentication(false); } private void loginMenuItemActionPerformed(java.awt.event.ActionEvent evt) { logoutMenuItemActionPerformed(evt); new LoginForm(new javax.swing.JFrame(),true).setVisible(true); } private void komponenMenuItemActionPerformed(java.awt.event.ActionEvent evt) { Komponen komponen = new Komponen(); jDesktopPane1.add(komponen,javax.swing.JLayeredPane.DEFA ULT_LAYER);

komponen.show(); } private void solusiMenuItemActionPerformed(java.awt.event.ActionEvent evt) { Solusi solusi = new Solusi(); jDesktopPane1.add(solusi,javax.swing.JLayeredPane.DEFAULT_ LAYER); solusi.show(); } private void pengetahuanMenuItemActionPerformed(java.awt.event.ActionEven t evt) { Pengetahuan pengetahuan = new Pengetahuan(); jDesktopPane1.add(pengetahuan,javax.swing.JLayeredPane.DE FAULT_LAYER); pengetahuan.show(); } private void registerMenuItemActionPerformed(java.awt.event.ActionEvent evt) { Register register = new Register(); jDesktopPane1.add(register,javax.swing.JLayeredPane.DEFAUL T_LAYER); register.show(); } private void btnHistoryActionPerformed(java.awt.event.ActionEvent evt) { Register register = new Register(); jDesktopPane1.add(register,javax.swing.JLayeredPane.DEFAUL T_LAYER); register.show(); } private void btnKomponenActionPerformed(java.awt.event.ActionEvent evt) {

Komponen komponen = new Komponen(); jDesktopPane1.add(komponen,javax.swing.JLayeredPane.DEFA ULT_LAYER); komponen.show(); } private void btnDiagnosaActionPerformed(java.awt.event.ActionEvent evt) { Solusi solusi = new Solusi(); jDesktopPane1.add(solusi,javax.swing.JLayeredPane.DEFAULT_ LAYER); solusi.show(); } private void btnPertanyaanActionPerformed(java.awt.event.ActionEvent evt) { Pengetahuan pengetahuan = new Pengetahuan(); jDesktopPane1.add(pengetahuan,javax.swing.JLayeredPane.DE FAULT_LAYER); pengetahuan.show(); } // Variables declaration - do not modify private javax.swing.JButton btnDiagnosa; private javax.swing.JButton btnHistory; private javax.swing.JButton btnKomponen; private javax.swing.JButton btnPertanyaan; private javax.swing.JDesktopPane jDesktopPane1; private javax.swing.JSeparator jSeparator1; private javax.swing.JToolBar.Separator jSeparator2; private javax.swing.JMenu knowledgeMenu; private javax.swing.JMenuItem komponenMenuItem; private javax.swing.JMenuItem loginMenuItem; private javax.swing.JMenuItem logoutMenuItem; private javax.swing.JPanel mainPanel; private javax.swing.JMenuBar menuBar; private javax.swing.JMenuItem pengetahuanMenuItem; private javax.swing.JProgressBar progressBar; private javax.swing.JMenuItem registerMenuItem; private javax.swing.JMenuItem solusiMenuItem; private javax.swing.JLabel statusAnimationLabel; private javax.swing.JLabel statusMessageLabel;

private javax.swing.JPanel statusPanel; private javax.swing.JToolBar toolBar; // End of variables declaration private final Timer messageTimer; private final Timer busyIconTimer; private final Icon idleIcon; private final Icon[] busyIcons = new Icon[15]; private int busyIconIndex = 0; private JDialog aboutBox; public void setAuthentication(boolean value){ knowledgeMenu.setEnabled(value); if (value==true){ loginMenuItem.setEnabled(false); logoutMenuItem.setEnabled(true); registerMenuItem.setEnabled(true); btnHistory.setEnabled(true); btnKomponen.setEnabled(true); btnPertanyaan.setEnabled(true); btnDiagnosa.setEnabled(true); }else{ loginMenuItem.setEnabled(true); logoutMenuItem.setEnabled(false); registerMenuItem.setEnabled(false); btnHistory.setEnabled(false); btnKomponen.setEnabled(false); btnPertanyaan.setEnabled(false); btnDiagnosa.setEnabled(false); } } }

4.

Form Data Komponen

package sistempakar; import com.miftah.db.*; import java.awt.Event; import java.sql.SQLException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JFileChooser; import javax.swing.JTable; import javax.swing.ImageIcon; import javax.swing.filechooser.FileNameExtensionFilter; /** * * @author Nabila Zahra Yulia */ public class Komponen extends javax.swing.JInternalFrame { boolean append; private DBTable tKomponen; private MyTable myTable; private JFileChooser fc = new JFileChooser(); private String imgSource=""; /** Creates new form Komponen */ public Komponen() { initComponents();

initForm(); } private void btnAddActionPerformed(java.awt.event.ActionEvent evt) { append=true; clearForm(); disableInput(false); String kode=tKomponen.getAutoNumberInt(); txtKode.setText("K"+kode.substring(2)); btnSave.setEnabled(true); btnCancel.setEnabled(true); btnAdd.setEnabled(false); btnEdit.setEnabled(false); btnDelete.setEnabled(false); btnBrowse.setEnabled(true); txtNama.requestFocus(); } private void btnEditActionPerformed(java.awt.event.ActionEvent evt) { int row=myTable.getRowSelected(); if(row>0){ append=false; clearForm(); disableInput(false); displayData(); imgSource=tKomponen.getString("Gambar"); jlblImage.setIcon(new ImageIcon(imgSource)); btnAdd.setEnabled(false); btnEdit.setEnabled(false); btnSave.setEnabled(true); btnCancel.setEnabled(true); btnDelete.setEnabled(true); btnBrowse.setEnabled(true); txtKode.setEnabled(false); txtNama.requestFocus(); }else{ Utils.showMessage(this, "Silakan memilih record yang mau Anda edit.", "Perhatian"); } }

private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) { if(isInputValid()==true){ save(); myTable.refresh(); Utils.showMessage(this, "Data tersimpan", "Informasi"); clearForm(); disableInput(true); btnSave.setEnabled(false); btnCancel.setEnabled(false); btnAdd.setEnabled(true); } } private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) { clearForm(); disableInput(true); btnAdd.setEnabled(true); btnSave.setEnabled(false); btnCancel.setEnabled(false); btnDelete.setEnabled(false); btnBrowse.setEnabled(false); } private void btnBrowseActionPerformed(java.awt.event.ActionEvent evt) { fc.setCurrentDirectory(new java.io.File("Image/")); int returnVal=fc.showOpenDialog(this); if(returnVal == JFileChooser.APPROVE_OPTION){ imgSource=fc.getSelectedFile().getPath(); jlblImage.setIcon(new ImageIcon(imgSource)); } } private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) { try{ int row=myTable.getRowSelected(); if(row<1){ Utils.showMessage(this, "Pilih data yang mau dihapus.", "Perhatian"); return; }

tKomponen.absolute(row); if(tKomponen.delete()){ myTable.refresh(); Utils.showMessage(this, "Data telah terhapus", "Informasi"); clearForm(); disableInput(true); btnAdd.setEnabled(true); btnSave.setEnabled(false); btnCancel.setEnabled(false); btnEdit.setEnabled(false); btnDelete.setEnabled(false); }else{ Utils.showMessage(this, "Data tidak bisa dihapus karena terrdapat relasi ke tabel pengetahuan.", "Informasi"); } }catch(SQLException sqle){ System.out.println(sqle); } } private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) { btnEditActionPerformed(evt); btnEdit.setEnabled(false); } // Variables declaration - do not modify private javax.swing.JButton btnAdd; private javax.swing.JButton btnBrowse; private javax.swing.JButton btnCancel; private javax.swing.JButton btnDelete; private javax.swing.JButton btnEdit; private javax.swing.JButton btnSave; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JPopupMenu jPopupMenu1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JLabel jlblImage; private javax.swing.JPanel pGambar; private javax.swing.JPanel pGrid;

private javax.swing.JPanel pIsian; private javax.swing.JPanel pTop; private javax.swing.JTextArea txtKeterangan; private javax.swing.JTextField txtKode; private javax.swing.JTextField txtNama; private javax.swing.JTextField txtPertanyaan; // End of variables declaration private void enterTable(java.awt.event.FocusEvent evt){ btnEdit.setEnabled(true); btnDelete.setEnabled(true); } private void myTableMouseClicked(java.awt.event.MouseEvent evt){ if(evt.getModifiers()==Event.META_MASK){ jPopupMenu1.show(myTable,evt.getX(),evt.getY()+15); } displayImage(); } private void scrollTable(java.awt.event.KeyEvent evt) { displayImage(); } private void displayImage(){ int row=myTable.getRowSelected(); if(row>0){ try{ tKomponen.absolute(row); imgSource=tKomponen.getString("Gambar"); jlblImage.setIcon(new ImageIcon(imgSource)); }catch(SQLException ex){ System.out.println("Error=" + ex.toString()); } } } private boolean isInputValid(){ boolean result; if((txtKode.getText().equals(""))||(txtNama.getText().equals(""))||(txtKet erangan.getText().equals(""))){ Utils.showMessage(this, "Data tidak valid","Informasi"); txtNama.requestFocus();

result=false; } else result=true; return result; } private void save(){ try { if(append==true){ tKomponen.append(); tKomponen.updateString("kd_komponen", txtKode.getText()); }else{ tKomponen.edit(); } tKomponen.updateString("nm_komponen", txtNama.getText()); tKomponen.updateString("keterangan", txtKeterangan.getText()); tKomponen.updateString("gambar", imgSource); tKomponen.updateString("id_tanya", txtPertanyaan.getText().toUpperCase()); tKomponen.post(); }catch(SQLException sqle){ System.err.println(sqle); } } private void displayData(){ try{ int row=myTable.getRowSelected(); if(row>0){ tKomponen.absolute(row); txtKode.setText(tKomponen.getString(1)); txtNama.setText(tKomponen.getString(2)); txtKeterangan.setText(tKomponen.getString(4)); txtPertanyaan.setText(tKomponen.getString(5)); jlblImage.setIcon(new ImageIcon(imgSource)); append=false; } }catch(SQLException sqle){ System.err.println(sqle); } }

private void clearForm(){ append=true; txtKode.setText(""); txtNama.setText(""); txtKeterangan.setText(""); txtPertanyaan.setText(""); imgSource=""; jlblImage.setIcon(null); } private void disableInput(boolean value){ txtKode.setEnabled(! value); txtNama.setEnabled(! value); txtKeterangan.setEnabled(! value); txtPertanyaan.setEnabled(! value); } private void initForm(){ try { FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG, Bitmap, PNG & GIF Images", "jpg","jpeg","bmp","png", "gif"); fc.setFileFilter(filter); tKomponen = new DBTable(); tKomponen.setDriver(SistemPakarApp.getDriver()); tKomponen.setTableName("tblkomponen"); tKomponen.setActive(true); myTable = new MyTable(); myTable.setParent(pGrid); myTable.setDB(tKomponen); myTable.RenameCol(0, "Kode"); myTable.RenameCol(1, "Nama Komponen"); myTable.RenameCol(2, "File Gambar"); myTable.RenameCol(3, "Keterangan"); myTable.RenameCol(4, "Id. Pertanyaan"); myTable.setColumnWidth(new int[] {10,80,80,15,15}); myTable.setShow(true); JTable tbl; tbl=MyTable.getJTableObject(); //1 tbl.addMouseListener(new java.awt.event.MouseAdapter() {@Override public void

mouseClicked(java.awt.event.MouseEvent evt){myTableMouseClicked(evt);}}); //2 tbl.addFocusListener(new java.awt.event.FocusAdapter() {@Override public void focusGained(java.awt.event.FocusEvent evt){enterTable(evt);}}); //3 tbl.addKeyListener(new java.awt.event.KeyAdapter() {@Override public void keyReleased(java.awt.event.KeyEvent evt){scrollTable(evt);}}); } catch (SQLException sqle) { System.err.println(sqle); } setDefaultCloseOperation(DISPOSE_ON_CLOSE); btnEdit.setEnabled(false); btnSave.setEnabled(false); btnCancel.setEnabled(false); btnDelete.setEnabled(false); btnBrowse.setEnabled(false); disableInput(true); } } 5. Form Data Pertanyaan dan Aturan

package sistempakar; import com.miftah.db.*; import java.sql.*; import javax.swing.*; import java.awt.*; /** * * @author Nabila Zahra Yulia */ public class Pengetahuan extends javax.swing.JInternalFrame { boolean append; private DBTable tPengetahuan; private DBQuery qPengetahuan; private MyTable myTable; /** Creates new form Pengetahuan */ public Pengetahuan() { initComponents(); initForm(); } private void btnAddActionPerformed(java.awt.event.ActionEvent evt) { append=true; clearForm(); disableInput(false); String kode=tPengetahuan.getAutoNumberInt(); txtKode.setText("P"+kode.substring(2)); btnAdd.setEnabled(false); btnSave.setEnabled(true); btnCancel.setEnabled(true); btnEdit.setEnabled(false); btnDelete.setEnabled(false); cboKomponen.requestFocus(); } private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) { if(isInputValid()==true){ save(); myTable.refresh(); Utils.showMessage(this, "Data tersimpan", "Informasi");

clearForm(); disableInput(true); btnSave.setEnabled(false); btnCancel.setEnabled(false); btnAdd.setEnabled(true); } } private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) { clearForm(); disableInput(true); btnAdd.setEnabled(true); btnSave.setEnabled(false); btnCancel.setEnabled(false); btnDelete.setEnabled(false); } private void btnEditActionPerformed(java.awt.event.ActionEvent evt) { int row=myTable.getRowSelected(); if(row>0){ append=false; clearForm(); disableInput(false); displayData(); btnAdd.setEnabled(false); btnEdit.setEnabled(false); btnSave.setEnabled(true); btnCancel.setEnabled(true); btnDelete.setEnabled(true); txtKode.setEnabled(false); txtPertanyaan.requestFocus(); }else{ Utils.showMessage(this, "Silakan memilih record yang mau Anda edit.", "Perhatian"); } } private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) { btnEditActionPerformed(evt); btnEdit.setEnabled(false);

} private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) { try{ int row=myTable.getRowSelected(); if(row<1){ Utils.showMessage(this, "Pilih data yang mau dihapus.", "Perhatian"); return; } tPengetahuan.absolute(row); if(tPengetahuan.delete()){ myTable.refresh(); Utils.showMessage(this, "Data telah terhapus", "Informasi"); clearForm(); disableInput(true); btnAdd.setEnabled(true); btnSave.setEnabled(false); btnCancel.setEnabled(false); btnEdit.setEnabled(false); btnDelete.setEnabled(false); }else{ Utils.showMessage(this, "Data gagal dihapus.", "Informasi"); } }catch(SQLException sqle){ System.out.println(sqle); } }

// Variables declaration - do not modify private javax.swing.JButton btnAdd; private javax.swing.JButton btnCancel; private javax.swing.JButton btnDelete; private javax.swing.JButton btnEdit; private javax.swing.JButton btnSave; private ui.ComboUI cboKomponen; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6;

private javax.swing.JLabel jLabel7; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JPopupMenu jPopupMenu1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JPanel pGrid; private javax.swing.JPanel pTop; private javax.swing.JTextField txtFaktaTidak; private javax.swing.JTextField txtFaktaYa; private javax.swing.JTextField txtJikaTidak; private javax.swing.JTextField txtJikaYa; private javax.swing.JTextField txtKode; private javax.swing.JTextArea txtPertanyaan; // End of variables declaration private void enterTable(java.awt.event.FocusEvent evt){ btnEdit.setEnabled(true); btnDelete.setEnabled(true); } private void myTableMouseClick(java.awt.event.MouseEvent evt){ if(evt.getModifiers()==Event.META_MASK){ jPopupMenu1.show(myTable, evt.getX(), evt.getY()+15); } } private void save(){ try{ if(append==true){ tPengetahuan.append(); tPengetahuan.updateString("kode", txtKode.getText().toString().toUpperCase()); }else{ tPengetahuan.locate(qPengetahuan.getString(1)); tPengetahuan.edit(); } tPengetahuan.updateString("pertanyaan", txtPertanyaan.getText().toString()); tPengetahuan.updateString("faktaYa", txtFaktaYa.getText().toString()); tPengetahuan.updateString("faktaTidak", txtFaktaTidak.getText().toString()); tPengetahuan.updateString("Ya", txtJikaYa.getText().toString().toUpperCase());

tPengetahuan.updateString("Tidak", txtJikaTidak.getText().toString().toUpperCase()); tPengetahuan.updateString("kd_komponen", cboKomponen.getSelectedKey()); tPengetahuan.post(); }catch(SQLException sqle){ System.err.println(sqle); } } private boolean isInputValid(){ String nmKomponen=null; try{ nmKomponen=cboKomponen.getSelectedItem().toString(); }catch(Exception e){ } boolean result; if((txtKode.getText().equals(""))||(!(nmKomponen instanceof String))||(txtPertanyaan.getText().equals(""))||(txtFaktaYa.getTex t().equals(""))||(txtFaktaTidak.getText().equals(""))||(txtJikaYa.ge tText().equals(""))||(txtJikaTidak.getText().equals(""))){ Utils.showMessage(this, "Data tidak valid", "Informasi"); txtKode.requestFocus(); result=false; }else result=true; return result; } private void displayData(){ try{ int row = myTable.getRowSelected(); if(row>0){ qPengetahuan.absolute(row); txtKode.setText(qPengetahuan.getString(1)); txtPertanyaan.setText(qPengetahuan.getString(3)); txtFaktaYa.setText(qPengetahuan.getString(4)); txtFaktaTidak.setText(qPengetahuan.getString(5)); txtJikaYa.setText(qPengetahuan.getString(6)); txtJikaTidak.setText(qPengetahuan.getString(7)); cboKomponen.setSelectedItem(qPengetahuan.getString(2)); append=false; } }catch(SQLException sqle){ System.err.println(sqle); } }

private void clearForm(){ append=true; txtKode.setText(""); txtPertanyaan.setText(""); txtFaktaYa.setText(""); txtFaktaTidak.setText(""); txtJikaYa.setText(""); txtJikaTidak.setText(""); cboKomponen.setSelectedIndex(-1); } private void disableInput(boolean value){ txtKode.setEnabled(! value); txtPertanyaan.setEnabled(! value); txtFaktaYa.setEnabled(! value); txtFaktaTidak.setEnabled(! value); txtJikaYa.setEnabled(! value); txtJikaTidak.setEnabled(! value); cboKomponen.setEnabled(! value); } private void initForm(){ try{ tPengetahuan = new DBTable(); tPengetahuan.setDriver(SistemPakarApp.getDriver()); tPengetahuan.setTableName("tblpengetahuan"); tPengetahuan.setActive(true); qPengetahuan = new DBQuery(); qPengetahuan.setDriver(SistemPakarApp.getDriver()); qPengetahuan.setStrSql("SELECT kode,nm_komponen,pertanyaan,faktaYa,faktaTidak,Ya,Tidak FROM tblpengetahuan p LEFT JOIN tblkomponen k ON p.kd_komponen=k.kd_komponen"); qPengetahuan.makeActive(true); myTable=new MyTable(); myTable.setParent(pGrid); myTable.setDB(qPengetahuan); myTable.RenameCol(0, "Kode"); myTable.RenameCol(1, "Komponen"); myTable.RenameCol(2, "Pertanyaan"); myTable.RenameCol(3, "Fakta Ya"); myTable.RenameCol(4, "Fakta Tidak"); myTable.RenameCol(5, "Ya"); myTable.RenameCol(6, "Tidak");

myTable.setColumnWidth(new int[] {5,20,100,15,15,15,15}); myTable.setShow(true); cboKomponen.setDriver(SistemPakarApp.getDriver()); cboKomponen.setQueryList("SELECT kd_komponen,nm_komponen FROM tblkomponen ORDER BY kd_komponen"); cboKomponen.setColumnList(2); cboKomponen.iniCombo(); JTable tbl; tbl=(JTable) MyTable.getJTableObject(); tbl.addMouseListener(new java.awt.event.MouseAdapter() {@Override public void mouseClicked(java.awt.event.MouseEvent evt){myTableMouseClick(evt);}}); tbl.addFocusListener(new java.awt.event.FocusAdapter() {@Override public void focusGained(java.awt.event.FocusEvent evt){enterTable(evt);}}); pGrid.add(myTable,java.awt.BorderLayout.CENTER); }catch(SQLException sqle){ System.err.println(sqle); } setDefaultCloseOperation(DISPOSE_ON_CLOSE); btnSave.setEnabled(false); btnCancel.setEnabled(false); btnEdit.setEnabled(false); btnDelete.setEnabled(false); clearForm(); disableInput(true); } }

6.

Form Data Diagnosa dan Solusi

package sistempakar; import com.miftah.db.*; import java.sql.SQLException; import javax.swing.JTable; import java.awt.*; /** * * @author Nabila Zahra Yulia */ public class Solusi extends javax.swing.JInternalFrame { boolean append; private DBTable tDiagnosa; private MyTable myTable; /** Creates new form Solusi */ public Solusi() { initComponents(); initForm(); }

private void btnAddActionPerformed(java.awt.event.ActionEvent evt) { append=true; clearForm(); disableInput(false); String kode=tDiagnosa.getAutoNumberInt(); txtKode.setText("S"+kode.substring(2)); btnSave.setEnabled(true); btnCancel.setEnabled(true); btnAdd.setEnabled(false); btnEdit.setEnabled(false); btnDelete.setEnabled(false); txtDiagnosa.requestFocus(); } private void btnEditActionPerformed(java.awt.event.ActionEvent evt) { int row=myTable.getRowSelected(); if(row>0){ append=false; clearForm(); disableInput(false); displayData(); btnAdd.setEnabled(false); btnEdit.setEnabled(false); btnSave.setEnabled(true); btnCancel.setEnabled(true); btnDelete.setEnabled(true); txtKode.setEnabled(false); txtDiagnosa.requestFocus(); }else{ Utils.showMessage(this, "SIlakan tentukan terlebih dahulu record yang akan diedit", "Perhatian"); } } private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) { if(isInputValid()==true){ save(); myTable.refresh(); Utils.showMessage(this, "Data telah tersimpan", "Informasi"); clearForm();

disableInput(true); btnSave.setEnabled(false); btnCancel.setEnabled(false); btnAdd.setEnabled(true); } } private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) { clearForm(); disableInput(true); btnAdd.setEnabled(true); btnSave.setEnabled(false); btnCancel.setEnabled(false); btnEdit.setEnabled(false); btnDelete.setEnabled(false); } private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) { boolean isSelected=true; try{ int row=myTable.getRowSelected(); if(row<1){ isSelected=false; Utils.showMessage(this, "Pilih dulu record yang akan dihapus.", "Perhatian"); return; } tDiagnosa.absolute(row); if(tDiagnosa.delete()==true){ myTable.refresh(); Utils.showMessage(this, "Data telah terhapus", "Informasi"); clearForm(); disableInput(true); btnAdd.setEnabled(true); btnSave.setEnabled(false); btnCancel.setEnabled(false); btnEdit.setEnabled(false); btnDelete.setEnabled(false); }else{ Utils.showMessage(this, "Data gagal dihapus", "Informasi"); }

}catch(SQLException sqle){ System.err.println(sqle); } } private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) { btnEditActionPerformed(evt); btnEdit.setEnabled(false); }

// Variables declaration - do not modify private javax.swing.JButton btnAdd; private javax.swing.JButton btnCancel; private javax.swing.JButton btnDelete; private javax.swing.JButton btnEdit; private javax.swing.JButton btnSave; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JPopupMenu jPopupMenu1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JPanel pGrid; private javax.swing.JPanel pTop; private javax.swing.JTextField txtDiagnosa; private javax.swing.JTextField txtKode; private javax.swing.JTextArea txtSolusi; // End of variables declaration private void enterTable(java.awt.event.FocusEvent evt){ btnEdit.setEnabled(true); btnDelete.setEnabled(true); } private void myTableMouseClick(java.awt.event.MouseEvent evt){ if(evt.getModifiers()==Event.META_MASK){ jPopupMenu1.show(myTable,evt.getX(),evt.getY()+15); } }

private boolean isInputValid(){ boolean result; if((txtKode.getText().equals(""))||(txtDiagnosa.getText().equals(""))||(txt Diagnosa.getText().equals(""))){ Utils.showMessage(this, "Data tidak valid", "Informasi"); txtKode.requestFocus(); result=false; } else result=true; return result; } private void save(){ try{ if(append==true){ tDiagnosa.append(); tDiagnosa.updateString("kode", txtKode.getText().toUpperCase()); }else{ tDiagnosa.edit(); } tDiagnosa.updateString("diagnosa", txtDiagnosa.getText()); tDiagnosa.updateString("solusi", txtSolusi.getText()); tDiagnosa.post(); }catch(SQLException sqle){ System.err.println(sqle); } } private void clearForm(){ append=true; txtKode.setText(""); txtDiagnosa.setText(""); txtSolusi.setText(""); } private void disableInput(boolean value){ txtKode.setEnabled(! value); txtDiagnosa.setEnabled(! value); txtSolusi.setEnabled(! value); }

private void displayData(){ try{ int row=myTable.getRowSelected(); if(row>0){ tDiagnosa.absolute(row); txtKode.setText(tDiagnosa.getString(1)); txtDiagnosa.setText(tDiagnosa.getString(2)); txtSolusi.setText(tDiagnosa.getString(3)); append=false; } }catch(SQLException sqle){ System.err.println(sqle); } } private void initForm(){ try{ clearForm(); tDiagnosa=new DBTable(); tDiagnosa.setDriver(SistemPakarApp.getDriver()); tDiagnosa.setTableName("tbldiagnosa"); tDiagnosa.setActive(true); myTable=new MyTable(); myTable.setParent(pGrid); myTable.setDB(tDiagnosa); myTable.RenameCol(0, "Kode"); myTable.RenameCol(1, "Diagnosa"); myTable.RenameCol(2, "Solusi"); myTable.setColumnWidth(new int[]{10,50,140}); myTable.setShow(true); JTable tbl; tbl = MyTable.getJTableObject(); tbl.addMouseListener(new java.awt.event.MouseAdapter() {@Override public void mouseClicked(java.awt.event.MouseEvent evt){myTableMouseClick(evt);}}); tbl.addFocusListener(new java.awt.event.FocusAdapter() {@Override public void focusGained(java.awt.event.FocusEvent evt){enterTable(evt);}}); }catch(SQLException sqle){

System.err.println(sqle); } setDefaultCloseOperation(DISPOSE_ON_CLOSE); btnSave.setEnabled(false); btnEdit.setEnabled(false); btnDelete.setEnabled(false); btnCancel.setEnabled(false); disableInput(true); } } 7. Form Menu Pengguna

package sistempakar; import java.awt.Dimension; import java.awt.Toolkit; /** * * @author Nabila Zahra Yulia */ public class frmPengguna extends javax.swing.JFrame { /** Creates new form frmPengguna */ public frmPengguna() { initComponents(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = this.getSize(); if (frameSize.height > screenSize.height){ frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width){ frameSize.width=screenSize.width; }

this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height)/2); } private void btnInfoActionPerformed(java.awt.event.ActionEvent evt) { InfoKomponen info = new InfoKomponen(); info.setVisible(true); this.dispose(); } private void btnKonsultasiActionPerformed(java.awt.event.ActionEvent evt) { Konsultasi konsultasi = new Konsultasi(); konsultasi.setVisible(true); this.dispose(); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new frmPengguna().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton btnInfo; private javax.swing.JButton btnKonsultasi; private javax.swing.JLabel jLabel1; // End of variables declaration }

8.

Form Informasi Komponen

package sistempakar; import java.awt.Dimension; import java.awt.Toolkit; import java.sql.SQLException; import javax.swing.ImageIcon; import java.util.HashMap; import java.util.Map; import net.sf.jasperreports.engine.*; import net.sf.jasperreports.engine.design.JasperDesign; import net.sf.jasperreports.engine.xml.JRXmlLoader; import net.sf.jasperreports.view.JasperViewer; /** * * @author Nabila Zahra Yulia */ public class InfoKomponen extends javax.swing.JFrame { private String strFile; /** Creates new form InfoKomponen */ public InfoKomponen() { initComponents(); createCombo(); empty(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = this.getSize(); if (frameSize.height > screenSize.height){

frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width){ frameSize.width=screenSize.width; } this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height)/2); } private void cboKomponenActionPerformed(java.awt.event.ActionEvent evt) { actionCombo(); } private void formWindowClosing(java.awt.event.WindowEvent evt) { frmPengguna pengguna = new frmPengguna(); pengguna.setVisible(true); } private void btnPrintActionPerformed(java.awt.event.ActionEvent evt) { /*Map map = new HashMap(); try { JasperDesign jasperDesign = JRXmlLoader.load("InfoKomponen.jrxml"); JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, map, SistemPakarApp.getDriver().getConnection()); JasperViewer jasperViewer = new JasperViewer(jasperPrint, false); jasperViewer.setTitle("Informasi Komponen"); jasperViewer.setVisible(true); } catch (Exception e) { e.printStackTrace(); }*/ Map<String, Object> params = new HashMap<String, Object>(); params.put("kode", cboKomponen.getSelectedKey()); try { JasperDesign jasperDesign = JRXmlLoader.load("InfoKomponen.jrxml"); JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, SistemPakarApp.getDriver().getConnection()); JasperViewer jasperViewer = new JasperViewer(jasperPrint, false); jasperViewer.setTitle("Informasi Komponen"); jasperViewer.setVisible(true); } catch (JRException ex) { ex.printStackTrace();} } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new InfoKomponen().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton btnPrint; private ui.ComboUI cboKomponen; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JLabel lblImage; private javax.swing.JTextArea txtKeterangan; // End of variables declaration private void empty(){ cboKomponen.setSelectedIndex(-1); lblImage.setIcon(null); txtKeterangan.setText(""); btnPrint.setEnabled(false); } private void createCombo(){ cboKomponen.setDriver(SistemPakarApp.getDriver()); cboKomponen.setQueryList("SELECT * FROM tblkomponen"); cboKomponen.setColumnList(2); cboKomponen.iniCombo(); }

private void actionCombo(){ if(cboKomponen.getSelectedIndex()<0){ return; } try { cboKomponen.getSelectedKey(); txtKeterangan.setText(cboKomponen.getResultSet().getString ("keterangan")); strFile=cboKomponen.getResultSet().getString("gambar"); lblImage.setIcon(new ImageIcon(strFile)); btnPrint.setEnabled(true); } catch (SQLException ex) { System.err.println(ex); } } } 9. Form Konsultasi Kerusakan

package sistempakar; import com.miftah.db.*; import java.awt.Dimension; import java.awt.Toolkit; import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.ImageIcon; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JasperCompileManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperReport; import net.sf.jasperreports.engine.design.JasperDesign; import net.sf.jasperreports.engine.xml.JRXmlLoader; import net.sf.jasperreports.view.JasperViewer; /** * * @author Nabila Zahra Yulia */ public class Konsultasi extends javax.swing.JFrame { private boolean append; private DBTable tPengetahuan,tPengguna,tTemp; private DBQuery qPertanyaan,qSolusi; private String strNoReg,strKode,strFaktaYa,strFaktaTidak,strA; private String strYa,strTidak,idTemp,tgl,komponen; /** Creates new form Konsultasi */ public Konsultasi() { initComponents(); initForm(); createCombo(); nonAktif(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = this.getSize(); if (frameSize.height > screenSize.height){ frameSize.height = screenSize.height; }

if (frameSize.width > screenSize.width){ frameSize.width=screenSize.width; } this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height)/2); strKode=""; lblImage.setIcon(new ImageIcon("")); strNoReg=tPengguna.getAutoNumberInt(); } private void btnMulaiActionPerformed(java.awt.event.ActionEvent evt) { if(isInputValid()==false){ Utils.showMessage(this, "Mohon dilengkapi terlebih dahulu Identitas Pengguna.", "Perhatian"); } else if(cboKomponen.getSelectedKey().equals("")){ Utils.showMessage(this, "Tentukan dahulu komponen yang diduga mengalami kerusakan.", "Perhatian"); cboKomponen.requestFocus(); } else { btnMulai.setEnabled(false); btnCancel.setEnabled(true); displayQuestion(); btnYa.setEnabled(true); btnTidak.setEnabled(true); } strA=""; txtDiagnosa.setText(""); txtSolusi.setText(""); } private void cboKomponenItemStateChanged(java.awt.event.ItemEvent evt) { //actionCombo(); } private void btnYaActionPerformed(java.awt.event.ActionEvent evt) { try{ tTemp.append(); tTemp.updateString("id", idTemp.toString()); tTemp.updateString("fakta", strFaktaYa.toString());

tTemp.post(); }catch (SQLException ex){} strA=strYa.substring(0, 1); if(strA.equalsIgnoreCase("P")){ try { txtSolusi.setText(""); qPertanyaan = new DBQuery(); qPertanyaan.setDriver(SistemPakarApp.getDriver()); qPertanyaan.setStrSql("SELECT pertanyaan,ya,tidak,faktaYa,faktaTidak,kode FROM tblpengetahuan WHERE kode='" + strYa + "'"); qPertanyaan.makeActive(true); int row=qPertanyaan.getRowCount(); qPertanyaan.absolute(row); lblPertanyaan.setText(qPertanyaan.getString(1)); strYa=qPertanyaan.getString(2); strTidak=qPertanyaan.getString(3); strFaktaYa=qPertanyaan.getString(4); strFaktaTidak=qPertanyaan.getString(5); idTemp=qPertanyaan.getString(6).toString(); } catch (SQLException ex) {} }else{ try { qSolusi = new DBQuery(); qSolusi.setDriver(SistemPakarApp.getDriver()); qSolusi.setStrSql("SELECT diagnosa,solusi FROM tbldiagnosa WHERE kode='" + strYa + "'"); qSolusi.makeActive(true); qSolusi.absolute(1); txtDiagnosa.setText(qSolusi.getString(1)); txtSolusi.setText(qSolusi.getString(2)); btnMulai.setEnabled(false); btnYa.setEnabled(false); btnTidak.setEnabled(false); btnAlasan.setEnabled(true); btnCancel.setEnabled(false); btnUlang.setEnabled(true); btnPrint.setEnabled(true); } catch (SQLException ex) { System.err.println(ex); } } }

private void btnTidakActionPerformed(java.awt.event.ActionEvent evt) { try{ tTemp.append(); tTemp.updateString("id", idTemp.toString()); tTemp.updateString("fakta", strFaktaTidak.toString()); tTemp.post(); }catch (SQLException ex){} strA=strTidak.substring(0, 1); if(strA.equalsIgnoreCase("P")){ try { txtSolusi.setText(""); qPertanyaan = new DBQuery(); qPertanyaan.setDriver(SistemPakarApp.getDriver()); qPertanyaan.setStrSql("SELECT pertanyaan,ya,tidak,faktaYa,faktaTidak,kode FROM tblpengetahuan WHERE kode='" + strTidak + "'"); qPertanyaan.makeActive(true); int row=qPertanyaan.getRowCount(); qPertanyaan.absolute(row); lblPertanyaan.setText(qPertanyaan.getString(1)); strYa=qPertanyaan.getString(2); strTidak=qPertanyaan.getString(3); strFaktaYa=qPertanyaan.getString(4); strFaktaTidak=qPertanyaan.getString(5); idTemp=qPertanyaan.getString(6).toString(); } catch (SQLException ex) {} }else{ try { qSolusi = new DBQuery(); qSolusi.setDriver(SistemPakarApp.getDriver()); qSolusi.setStrSql("SELECT diagnosa,solusi FROM tbldiagnosa WHERE kode='" + strTidak + "'"); qSolusi.makeActive(true); qSolusi.absolute(1); txtDiagnosa.setText(qSolusi.getString(1)); txtSolusi.setText(qSolusi.getString(2)); btnMulai.setEnabled(false); btnYa.setEnabled(false); btnTidak.setEnabled(false); btnAlasan.setEnabled(true); btnCancel.setEnabled(false); btnUlang.setEnabled(true); btnPrint.setEnabled(true);

} catch (SQLException ex) { System.err.println(ex); } } } private void formWindowClosing(java.awt.event.WindowEvent evt) { if((txtDiagnosa.getText().equals("")) && (txtSolusi.getText().equals(""))){ //Do Nothing } else if(isInputValid()){ append=true; save(); clearDump(); } frmPengguna pengguna = new frmPengguna(); pengguna.setVisible(true); } private void btnUlangActionPerformed(java.awt.event.ActionEvent evt) { save(); clearForm(); clearDump(); nonAktif(); strKode=""; strNoReg=tPengguna.getAutoNumberInt(); lblImage.setIcon(new ImageIcon("")); txtNama.requestFocus(); append = true; } private void cboKomponenActionPerformed(java.awt.event.ActionEvent evt) { actionCombo(); } private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) { clearForm(); clearDump(); nonAktif();

btnMulai.setEnabled(true); strKode=""; strNoReg=tPengguna.getAutoNumberInt(); lblImage.setIcon(new ImageIcon("")); txtNama.requestFocus(); } private void btnAlasanActionPerformed(java.awt.event.ActionEvent evt) { Penjelasan penjelasan = new Penjelasan(); penjelasan.setVisible(true); } private void btnPrintActionPerformed(java.awt.event.ActionEvent evt) { //append=true; save(); Map<String, Object> params = new HashMap<String, Object>(); params.put("nomor", strNoReg); try { JasperDesign jasperDesign = JRXmlLoader.load("Diagnosa.jrxml"); JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, SistemPakarApp.getDriver().getConnection()); JasperViewer jasperViewer = new JasperViewer(jasperPrint, false); jasperViewer.setTitle("Hasil Diagnosa"); jasperViewer.setVisible(true); append=false; } catch (JRException ex) { ex.printStackTrace();} } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Konsultasi().setVisible(true); } });

} // Variables declaration - do not modify private javax.swing.JButton btnAlasan; private javax.swing.JButton btnCancel; private javax.swing.JButton btnMulai; private javax.swing.JButton btnPrint; private javax.swing.JButton btnTidak; private javax.swing.JButton btnUlang; private javax.swing.JButton btnYa; private ui.ComboUI cboKomponen; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel7; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JLabel kode; private javax.swing.JLabel lblImage; private javax.swing.JLabel lblPertanyaan; private javax.swing.JPanel pDiagnosa; private javax.swing.JPanel pPengguna; private javax.swing.JPanel pPertanyaan; private javax.swing.JTextArea txtAlamat; private javax.swing.JTextField txtDiagnosa; private javax.swing.JTextField txtNama; private javax.swing.JTextArea txtSolusi; // End of variables declaration private void createCombo(){ cboKomponen.setDriver(SistemPakarApp.getDriver()); cboKomponen.setQueryList("SELECT * FROM tblkomponen"); cboKomponen.setColumnList(2); cboKomponen.iniCombo(); } private void actionCombo(){ if(cboKomponen.getSelectedIndex()<0){ return; } try { cboKomponen.getSelectedKey(); strKode=cboKomponen.getResultSet().getString("id_tanya");

String strFile=cboKomponen.getResultSet().getString("gambar"); komponen=cboKomponen.getResultSet().getString("nm_komp onen"); lblImage.setIcon(new ImageIcon(strFile)); idTemp=strKode.toString(); lblPertanyaan.setText(""); clearDump(); nonAktif(); btnMulai.setEnabled(true); } catch (SQLException ex) { System.err.println(ex); } } private boolean isInputValid(){ boolean result; if(txtNama.getText().equals("")||txtAlamat.getText().equals("")){ result=false; } else result=true; return result; } private void save(){ try{ if(append==true){ tPengguna.append(); tPengguna.updateString("no_reg", strNoReg.toString()); }else{ tPengguna.edit(); } tPengguna.updateString("nama", txtNama.getText()); tPengguna.updateString("alamat", txtAlamat.getText()); tPengguna.updateString("nm_komponen", komponen); tPengguna.updateString("diagnosa", txtDiagnosa.getText()); tPengguna.updateString("solusi", txtSolusi.getText()); tPengguna.updateString("tanggal", tgl); tPengguna.post(); }catch(SQLException sqle){ System.err.println(sqle); } }

private void displayQuestion(){ try { qPertanyaan = new DBQuery(); qPertanyaan.setDriver(SistemPakarApp.getDriver()); qPertanyaan.setStrSql("SELECT pertanyaan,ya,tidak,faktaYa,faktaTidak FROM tblpengetahuan WHERE kode='" + strKode + "'"); qPertanyaan.makeActive(true); qPertanyaan.absolute(1); lblPertanyaan.setText(qPertanyaan.getString(1)); strYa=qPertanyaan.getString(2); strTidak=qPertanyaan.getString(3); strFaktaYa=qPertanyaan.getString(4); strFaktaTidak=qPertanyaan.getString(5); } catch (SQLException ex) { } } private void nonAktif(){ btnYa.setEnabled(false); btnTidak.setEnabled(false); btnAlasan.setEnabled(false); btnCancel.setEnabled(false); btnUlang.setEnabled(false); btnPrint.setEnabled(false); } private void clearDump(){ try { strYa = ""; strTidak = ""; strA = ""; lblPertanyaan.setText(""); txtDiagnosa.setText(""); txtSolusi.setText(""); btnYa.setEnabled(true); btnTidak.setEnabled(true); int row = tTemp.getRowCount(); if(row>0) { DBQuery qDelete = new DBQuery(); qDelete.setDriver(SistemPakarApp.getDriver()); qDelete.setStrSql("DELETE FROM temp"); qDelete.doQuery(); }

} catch (SQLException ex) { Logger.getLogger(Konsultasi.class.getName()).log(Level.SEVER E, null, ex); } } private void clearForm(){ strNoReg=""; txtNama.setText(""); txtAlamat.setText(""); cboKomponen.setSelectedIndex(-1); } private void initForm(){ append=true; Date current = new Date(); SimpleDateFormat frmt1 = new SimpleDateFormat("dd/MM/yyyy"); tgl = frmt1.format(current); tPengetahuan = new DBTable(); tPengetahuan.setDriver(SistemPakarApp.getDriver()); tPengetahuan.setTableName("tblpengetahuan"); tPengetahuan.setActive(true); tPengguna = new DBTable(); tPengguna.setDriver(SistemPakarApp.getDriver()); tPengguna.setTableName("pengguna"); tPengguna.setActive(true); txtNama.requestFocus(); tTemp = new DBTable(); tTemp.setDriver(SistemPakarApp.getDriver()); tTemp.setTableName("temp"); tTemp.setActive(true); } }

10. Form Penjelasan

package sistempakar; import com.miftah.db.*; import java.awt.Dimension; import java.awt.Toolkit; import java.sql.SQLException; /** * * @author Nabila Zahra Yulia */ public class Penjelasan extends javax.swing.JFrame { private DBQuery qPenjelasan; private MyTable myTable; /** Creates new form Penjelasan */ public Penjelasan() { initComponents(); initForm(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = this.getSize(); if (frameSize.height > screenSize.height){ frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width){ frameSize.width=screenSize.width; } this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height)/2); }

/** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Penjelasan().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JPanel pGrid; // End of variables declaration private void initForm(){ try { qPenjelasan = new DBQuery(); qPenjelasan.setDriver(SistemPakarApp.getDriver()); qPenjelasan.setStrSql("SELECT fakta FROM temp ORDER BY id"); qPenjelasan.makeActive(true); myTable = new MyTable(); myTable.setParent(pGrid); myTable.setDB(qPenjelasan); myTable.RenameCol(0, "Diagnosa dihasilkan dari fakta berikut ini :"); myTable.setColumnWidth(new int[]{30}); myTable.setShow(true); } catch (SQLException ex) { System.err.println(ex); } } }

11. Form Tentang Program

package sistempakar; import org.jdesktop.application.Action; public class SistemPakarAboutBox extends javax.swing.JDialog { public SistemPakarAboutBox(java.awt.Frame parent) { super(parent); initComponents(); getRootPane().setDefaultButton(closeButton); } @Action public void closeAboutBox() { dispose(); } // Variables declaration - do not modify private javax.swing.JButton closeButton; // End of variables declaration }

You're Reading a Free Preview

Mengunduh
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->