54186382 sistem-pakar

436 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
436
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

54186382 sistem-pakar

  1. 1. TAMPILAN FORM DAN LISTING PROGRAM1. Form Pilihan Pengguna Sistempackage 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.ActionEventevt) {new LoginForm(new javax.swing.JFrame(), true).setVisible(true);this.dispose();
  2. 2. }private voidbtnPenggunaActionPerformed(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(newjava.awt.event.WindowAdapter() {public void windowClosing(java.awt.event.WindowEvente) {System.exit(0);}});dialog.setVisible(true);}});}// Variables declaration - do not modifyprivate javax.swing.JButton btnPakar;private javax.swing.JButton btnPengguna;private javax.swing.JLabel jLabel1;// End of variables declaration}
  3. 3. 2. Form Login Pakarpackage 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");
  4. 4. db.setDriver(SistemPakarApp.getDriver());db.setActive(true);}private void btnLoginActionPerformed(java.awt.event.ActionEventevt) {Login();}private void btnCancelActionPerformed(java.awt.event.ActionEventevt) {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(newjavax.swing.JFrame(), true);dialog.addWindowListener(newjava.awt.event.WindowAdapter() {public void windowClosing(java.awt.event.WindowEvente) {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 = (" +
  5. 5. 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 modifyprivate 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}
  6. 6. 3. Menu Utama Pakarpackage 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 applications main frame.*/public class SistemPakarView extends FrameView {public SistemPakarView(SingleFrameApplication app) {super(app);initComponents();// status bar initialization - message timeout, idle icon and busyanimation, etcResourceMap resourceMap = getResourceMap();int messageTimeout =resourceMap.getInteger("StatusBar.messageTimeout");
  7. 7. messageTimer = new Timer(messageTimeout, newActionListener() {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, newActionListener() {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 TaskMonitorTaskMonitor taskMonitor = newTaskMonitor(getApplication().getContext());taskMonitor.addPropertyChangeListener(newjava.beans.PropertyChangeListener() {public void propertyChange(java.beans.PropertyChangeEventevt) {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);
  8. 8. 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);}}});}@Actionpublic void showAboutBox() {if (aboutBox == null) {JFrame mainFrame =SistemPakarApp.getApplication().getMainFrame();aboutBox = new SistemPakarAboutBox(mainFrame);aboutBox.setLocationRelativeTo(mainFrame);}SistemPakarApp.getApplication().show(aboutBox);}private voidlogoutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {setAuthentication(false);}private voidloginMenuItemActionPerformed(java.awt.event.ActionEvent evt) {logoutMenuItemActionPerformed(evt);new LoginForm(new javax.swing.JFrame(),true).setVisible(true);}private voidkomponenMenuItemActionPerformed(java.awt.event.ActionEventevt) {Komponen komponen = new Komponen();jDesktopPane1.add(komponen,javax.swing.JLayeredPane.DEFAULT_LAYER);
  9. 9. komponen.show();}private voidsolusiMenuItemActionPerformed(java.awt.event.ActionEvent evt) {Solusi solusi = new Solusi();jDesktopPane1.add(solusi,javax.swing.JLayeredPane.DEFAULT_LAYER);solusi.show();}private voidpengetahuanMenuItemActionPerformed(java.awt.event.ActionEvent evt) {Pengetahuan pengetahuan = new Pengetahuan();jDesktopPane1.add(pengetahuan,javax.swing.JLayeredPane.DEFAULT_LAYER);pengetahuan.show();}private voidregisterMenuItemActionPerformed(java.awt.event.ActionEvent evt){Register register = new Register();jDesktopPane1.add(register,javax.swing.JLayeredPane.DEFAULT_LAYER);register.show();}private void btnHistoryActionPerformed(java.awt.event.ActionEventevt) {Register register = new Register();jDesktopPane1.add(register,javax.swing.JLayeredPane.DEFAULT_LAYER);register.show();}private voidbtnKomponenActionPerformed(java.awt.event.ActionEvent evt) {
  10. 10. Komponen komponen = new Komponen();jDesktopPane1.add(komponen,javax.swing.JLayeredPane.DEFAULT_LAYER);komponen.show();}private voidbtnDiagnosaActionPerformed(java.awt.event.ActionEvent evt) {Solusi solusi = new Solusi();jDesktopPane1.add(solusi,javax.swing.JLayeredPane.DEFAULT_LAYER);solusi.show();}private voidbtnPertanyaanActionPerformed(java.awt.event.ActionEvent evt) {Pengetahuan pengetahuan = new Pengetahuan();jDesktopPane1.add(pengetahuan,javax.swing.JLayeredPane.DEFAULT_LAYER);pengetahuan.show();}// Variables declaration - do not modifyprivate 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;
  11. 11. private javax.swing.JPanel statusPanel;private javax.swing.JToolBar toolBar;// End of variables declarationprivate 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);}}}
  12. 12. 4. Form Data Komponenpackage 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();
  13. 13. initForm();}private void btnAddActionPerformed(java.awt.event.ActionEventevt) {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.ActionEventevt) {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 mauAnda edit.", "Perhatian");}}
  14. 14. private void btnSaveActionPerformed(java.awt.event.ActionEventevt) {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.ActionEventevt) {clearForm();disableInput(true);btnAdd.setEnabled(true);btnSave.setEnabled(false);btnCancel.setEnabled(false);btnDelete.setEnabled(false);btnBrowse.setEnabled(false);}private void btnBrowseActionPerformed(java.awt.event.ActionEventevt) {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.ActionEventevt) {try{int row=myTable.getRowSelected();if(row<1){Utils.showMessage(this, "Pilih data yang mau dihapus.","Perhatian");return;}
  15. 15. 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 karenaterrdapat relasi ke tabel pengetahuan.", "Informasi");}}catch(SQLException sqle){System.out.println(sqle);}}private voidjMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {btnEditActionPerformed(evt);btnEdit.setEnabled(false);}// Variables declaration - do not modifyprivate 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;
  16. 16. 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 declarationprivate void enterTable(java.awt.event.FocusEvent evt){btnEdit.setEnabled(true);btnDelete.setEnabled(true);}private void myTableMouseClicked(java.awt.event.MouseEventevt){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(""))||(txtKeterangan.getText().equals(""))){Utils.showMessage(this, "Data tidak valid","Informasi");txtNama.requestFocus();
  17. 17. 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);}}
  18. 18. 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 = newFileNameExtensionFilter("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();//1tbl.addMouseListener(new java.awt.event.MouseAdapter(){@Override public void
  19. 19. mouseClicked(java.awt.event.MouseEventevt){myTableMouseClicked(evt);}});//2tbl.addFocusListener(new java.awt.event.FocusAdapter(){@Override public voidfocusGained(java.awt.event.FocusEventevt){enterTable(evt);}});//3tbl.addKeyListener(new java.awt.event.KeyAdapter(){@Override public void keyReleased(java.awt.event.KeyEventevt){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
  20. 20. 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.ActionEventevt) {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.ActionEventevt) {if(isInputValid()==true){save();myTable.refresh();Utils.showMessage(this, "Data tersimpan", "Informasi");
  21. 21. clearForm();disableInput(true);btnSave.setEnabled(false);btnCancel.setEnabled(false);btnAdd.setEnabled(true);}}private void btnCancelActionPerformed(java.awt.event.ActionEventevt) {clearForm();disableInput(true);btnAdd.setEnabled(true);btnSave.setEnabled(false);btnCancel.setEnabled(false);btnDelete.setEnabled(false);}private void btnEditActionPerformed(java.awt.event.ActionEventevt) {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 mauAnda edit.", "Perhatian");}}private voidjMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {btnEditActionPerformed(evt);btnEdit.setEnabled(false);
  22. 22. }private void btnDeleteActionPerformed(java.awt.event.ActionEventevt) {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 modifyprivate 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;
  23. 23. 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 declarationprivate 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());
  24. 24. 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 instanceofString))||(txtPertanyaan.getText().equals(""))||(txtFaktaYa.getText().equals(""))||(txtFaktaTidak.getText().equals(""))||(txtJikaYa.getText().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);}}
  25. 25. 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("SELECTkode,nm_komponen,pertanyaan,faktaYa,faktaTidak,Ya,TidakFROM tblpengetahuan p LEFT JOIN tblkomponen k ONp.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");
  26. 26. myTable.setColumnWidth(new int[] {5,20,100,15,15,15,15});myTable.setShow(true);cboKomponen.setDriver(SistemPakarApp.getDriver());cboKomponen.setQueryList("SELECTkd_komponen,nm_komponen FROM tblkomponen ORDERBY kd_komponen");cboKomponen.setColumnList(2);cboKomponen.iniCombo();JTable tbl;tbl=(JTable) MyTable.getJTableObject();tbl.addMouseListener(new java.awt.event.MouseAdapter(){@Override public voidmouseClicked(java.awt.event.MouseEventevt){myTableMouseClick(evt);}});tbl.addFocusListener(new java.awt.event.FocusAdapter(){@Override public voidfocusGained(java.awt.event.FocusEventevt){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);}}
  27. 27. 6. Form Data Diagnosa dan Solusipackage 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();}
  28. 28. private void btnAddActionPerformed(java.awt.event.ActionEventevt) {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.ActionEventevt) {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 dahulurecord yang akan diedit", "Perhatian");}}private void btnSaveActionPerformed(java.awt.event.ActionEventevt) {if(isInputValid()==true){save();myTable.refresh();Utils.showMessage(this, "Data telah tersimpan", "Informasi");clearForm();
  29. 29. disableInput(true);btnSave.setEnabled(false);btnCancel.setEnabled(false);btnAdd.setEnabled(true);}}private void btnCancelActionPerformed(java.awt.event.ActionEventevt) {clearForm();disableInput(true);btnAdd.setEnabled(true);btnSave.setEnabled(false);btnCancel.setEnabled(false);btnEdit.setEnabled(false);btnDelete.setEnabled(false);}private void btnDeleteActionPerformed(java.awt.event.ActionEventevt) {boolean isSelected=true;try{int row=myTable.getRowSelected();if(row<1){isSelected=false;Utils.showMessage(this, "Pilih dulu record yang akandihapus.", "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");}
  30. 30. }catch(SQLException sqle){System.err.println(sqle);}}private voidjMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {btnEditActionPerformed(evt);btnEdit.setEnabled(false);}// Variables declaration - do not modifyprivate 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 declarationprivate 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);}}
  31. 31. private boolean isInputValid(){boolean result;if((txtKode.getText().equals(""))||(txtDiagnosa.getText().equals(""))||(txtDiagnosa.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);}
  32. 32. 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 voidmouseClicked(java.awt.event.MouseEventevt){myTableMouseClick(evt);}});tbl.addFocusListener(new java.awt.event.FocusAdapter(){@Override public voidfocusGained(java.awt.event.FocusEventevt){enterTable(evt);}});}catch(SQLException sqle){
  33. 33. 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 Penggunapackage 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;}
  34. 34. 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 voidbtnKonsultasiActionPerformed(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 modifyprivate javax.swing.JButton btnInfo;private javax.swing.JButton btnKonsultasi;private javax.swing.JLabel jLabel1;// End of variables declaration}
  35. 35. 8. Form Informasi Komponenpackage 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){
  36. 36. 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 voidcboKomponenActionPerformed(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.ActionEventevt) {/*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);
  37. 37. 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 modifyprivate 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 declarationprivate 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();}
  38. 38. 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
  39. 39. 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;}
  40. 40. 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.ActionEventevt) {if(isInputValid()==false){Utils.showMessage(this, "Mohon dilengkapi terlebih dahuluIdentitas Pengguna.", "Perhatian");} elseif(cboKomponen.getSelectedKey().equals("")){Utils.showMessage(this, "Tentukan dahulu komponen yangdiduga 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 voidcboKomponenItemStateChanged(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());
  41. 41. 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("SELECTpertanyaan,ya,tidak,faktaYa,faktaTidak,kode FROMtblpengetahuan 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 FROMtbldiagnosa 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);}}}
  42. 42. private void btnTidakActionPerformed(java.awt.event.ActionEventevt) {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("SELECTpertanyaan,ya,tidak,faktaYa,faktaTidak,kode FROMtblpengetahuan 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 FROMtbldiagnosa 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);
  43. 43. } 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.ActionEventevt) {save();clearForm();clearDump();nonAktif();strKode="";strNoReg=tPengguna.getAutoNumberInt();lblImage.setIcon(new ImageIcon(""));txtNama.requestFocus();append = true;}private voidcboKomponenActionPerformed(java.awt.event.ActionEvent evt) {actionCombo();}private void btnCancelActionPerformed(java.awt.event.ActionEventevt) {clearForm();clearDump();nonAktif();
  44. 44. btnMulai.setEnabled(true);strKode="";strNoReg=tPengguna.getAutoNumberInt();lblImage.setIcon(new ImageIcon(""));txtNama.requestFocus();}private void btnAlasanActionPerformed(java.awt.event.ActionEventevt) {Penjelasan penjelasan = new Penjelasan();penjelasan.setVisible(true);}private void btnPrintActionPerformed(java.awt.event.ActionEventevt) {//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);}});
  45. 45. }// Variables declaration - do not modifyprivate 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 declarationprivate 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");
  46. 46. StringstrFile=cboKomponen.getResultSet().getString("gambar");komponen=cboKomponen.getResultSet().getString("nm_komponen");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);}}
  47. 47. private void displayQuestion(){try {qPertanyaan = new DBQuery();qPertanyaan.setDriver(SistemPakarApp.getDriver());qPertanyaan.setStrSql("SELECTpertanyaan,ya,tidak,faktaYa,faktaTidak FROM tblpengetahuanWHERE 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();}
  48. 48. } catch (SQLException ex) {Logger.getLogger(Konsultasi.class.getName()).log(Level.SEVERE, null, ex);}}private void clearForm(){strNoReg="";txtNama.setText("");txtAlamat.setText("");cboKomponen.setSelectedIndex(-1);}private void initForm(){append=true;Date current = new Date();SimpleDateFormat frmt1 = newSimpleDateFormat("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);}}
  49. 49. 10. Form Penjelasanpackage 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);}
  50. 50. /*** @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 modifyprivate javax.swing.JPanel pGrid;// End of variables declarationprivate void initForm(){try {qPenjelasan = new DBQuery();qPenjelasan.setDriver(SistemPakarApp.getDriver());qPenjelasan.setStrSql("SELECT fakta FROM temp ORDERBY id");qPenjelasan.makeActive(true);myTable = new MyTable();myTable.setParent(pGrid);myTable.setDB(qPenjelasan);myTable.RenameCol(0, "Diagnosa dihasilkan dari fakta berikutini :");myTable.setColumnWidth(new int[]{30});myTable.setShow(true);} catch (SQLException ex) {System.err.println(ex);}}}
  51. 51. 11. Form Tentang Programpackage 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 modifyprivate javax.swing.JButton closeButton;// End of variables declaration}

×