Implementasi Kelas HalamanUtama Implementasi Kelas

5.3 Implementasi Kelas

Pada bagian ini terdapat beberapa listing program dari kelas-kelas utama yang digunakan dalam sistem ini. Method-method yang ditampilkan dari setiap kelas hanya method yang memuat fungsi utama sistem yang berkaitan dengan algoritma Block-based Nested-Loop.

5.3.1 Implementasi Kelas HalamanUtama

Pada kelas HalamanUtama terdapat beberapa method yang berkaitan dengan fungsi utama antara lain pilihFile, pilihXLS, pilihCSV, tampilTabelBasisdata, cekAtribut, cekAtribut2, hapusAtribut, distribusiAtribut, submitData, prosesData dan simpanHasil. public void setSisaint sisa { this.sisa = sisa; } public boolean isFirstArray { return firstArray; } public void setFirstArrayboolean firstArray { this.firstArray = firstArray; } public ListInteger getIsi_blok { return isi_blok; } public void setIsi_blokListInteger isi_blok { this.isi_blok = isi_blok;}} CheckBoxTableModel cb_table = new CheckBoxTableModel; SeleksiAtribut fm; DatabaseConnection con; public HalamanUtamaDatabaseConnection db, String namaTabel { initComponents; tampilTabelBasisdatadb, namaTabel; } public void pilihFile { JFileChooser chooser = new JFileChooser; int returnVal = chooser.showOpenDialognull; if returnVal == JFileChooser.APPROVE_OPTION { String nama_file = chooser.getSelectedFile.getPath; String[] potong = nama_file.split\\.; String pola = [0-9.]; String pola2 = [.]; if potong[1].equalsxls { FILE EXCEL pilihXLSchooser, nama_file, pola, pola2; } else if potong[1].equalscsv { FILE CSV pilihCSVchooser, nama_file, pola, pola2; } else { JOptionPane.showMessageDialognull, File yang dipilih harus berformat .xls atau .csv; } } } public void pilihXLSJFileChooser chooser, String nama_file, String pola, String pola2 { cb_table.removeRow2; File excelFile = chooser.getSelectedFile; pathField.setTextnama_file; Vector columnNames = new Vector; Vector data = new Vector; try { Workbook workbook = Workbook.getWorkbookexcelFile; Sheet sheet = workbook.getSheets[0]; for int row = 0; row sheet.getRows; row++ { Vector rows = new Vector; for int column = 0; column sheet.getColumns; column++ { if row == 0 { columnNames.addElementsheet.getCellcolumn, row.getContents; } else { rows.addElementsheet.getCellcolumn, row.getContents; } } if row = 0 { data.addElementrows; } } hasilOutlierTextArea.setTextnull; DefaultTableModel model = new DefaultTableModeldata, columnNames; preprocessTabel.setAutoResizeModeJTable.AUTO_RESIZE_OFF; preprocessTabel.setModelmodel; updateCellWidthpreprocessTabel; jumlahDataField.setText + data.size; distAtributButton.setEnabledtrue; for int i = 0; i model.getColumnCount; i++ { for int j = 0; j model.getRowCount; j++ { if i == 0 { if model.getValueAtj, 0.toString.isEmpty { JOptionPane.showMessageDialognull, Label data Anda tidak lengkap. Silahkan lengkapi label data + pada file asli Anda.; i = model.getColumnCount - 1; break; } } else { if model.getValueAtj, i.toString.isEmpty || model.getValueAtj, i.toString.matchespola || model.getValueAtj, i.toString.matchespola2 { HalamanMissingValues m = new HalamanMissingValuesmodel; m.setVisibletrue; i = model.getColumnCount - 1; break; } } } } AbstractTableModel dengan JCheckBox for int i = 0; i model.getColumnCount; i++ { fm = new SeleksiAtribut; fm.setAtribut2model.getColumnNamei; fm.setPilihfalse; cb_table.addi, fm; } deteksiOutlierTabel.setAutoResizeModeJTable.AUTO_RESIZE_OFF; deteksiOutlierTabel.setModelmodel; updateCellWidthdeteksiOutlierTabel; jumDataField.setTextjumlahDataField.getText; hapusAtributTable.setModelcb_table; hapusAtributButton.setEnabledtrue; checkAllButton.setEnabledtrue; uncheckAllButton.setEnabledtrue; submitDataButton.setEnabledtrue; } catch Exception e { } } public void pilihCSVJFileChooser chooser, String nama_file, String pola, String pola2 { File csvFile = chooser.getSelectedFile; pathField.setTextnama_file; Vector columnNames = new Vector; Vector data = new Vector; String line; try { BufferedReader br = new BufferedReadernew FileReadercsvFile; StringTokenizer st = new StringTokenizerbr.readLine, ,; while st.hasMoreTokens { columnNames.addElementst.nextToken; } while line = br.readLine = null { StringTokenizer st2 = new StringTokenizerline, ,; Vector row = new Vector; while st2.hasMoreTokens { row.addElementst2.nextToken; } data.addElementrow; } br.close; DefaultTableModel model = new DefaultTableModeldata, columnNames; preprocessTabel.setAutoResizeModeJTable.AUTO_RESIZE_OFF; preprocessTabel.setModelmodel; updateCellWidthpreprocessTabel; pathField.setTextcsvFile.getPath; jumlahDataField.setText + data.size; distAtributButton.setEnabledtrue; for int i = 0; i model.getColumnCount; i++ { for int j = 0; j model.getRowCount; j++ { if model.getValueAtj, i.toString.isEmpty || model.getValueAtj, i.toString.matchespola || model.getValueAtj, i.toString.matchespola2 { JOptionPane.showMessageDialognull, Data Anda belum lengkap. + Silahkan lengkapi data Anda pada file asli.; i = model.getColumnCount - 1; break; } } } AbstractTableModel dengan JCheckBox ListString isiData = new ArrayListString; for int i = 0; i model.getColumnCount; i++ { fm = new SeleksiAtribut; fm.setAtribut2model.getColumnNamei; fm.setPilihfalse; cb_table.addi, fm; } deteksiOutlierTabel.setAutoResizeModeJTable.AUTO_RESIZE_OF F; deteksiOutlierTabel.setModelmodel; updateCellWidthdeteksiOutlierTabel; jumDataField.setTextjumlahDataField.getText; hapusAtributTable.setModelcb_table; hapusAtributButton.setEnabledtrue; checkAllButton.setEnabledtrue; uncheckAllButton.setEnabledtrue; submitDataButton.setEnabledtrue; } catch Exception e1 { } } public void tampilTabelBasisdataDatabaseConnection db, String namaTabel { try { Database con = new Database; ResultSet rs; rs = con.displayTabledb.getConnection, namaTabel; java.sql.ResultSetMetaData meta = rs.getMetaData; int coloumCount = meta.getColumnCount; Vector columnName = new Vector; Vector data = new Vector; columnName.clear; for int i = 1; i = coloumCount; i++ { columnName.addmeta.getColumnNamei; } data.clear; while rs.next { Vector data2 = new Vector; for int i = 1; i = coloumCount; i++ { data2.addrs.getStringi; } data2.add\n; data.adddata2; } DefaultTableModel model = new DefaultTableModeldata, columnName; preprocessTabel.setAutoResizeModeJTable.AUTO_RESIZE_OFF; preprocessTabel.setModelmodel; updateCellWidthpreprocessTabel; jumlahDataField.setText + data.size; pathField.setTextTABEL : + namaTabel; cb_table.removeRow2; String pola = [0-9.]; String pola2 = [.]; for int i = 0; i model.getColumnCount; i++ { for int j = 0; j model.getRowCount; j++ { if i == 0 { if model.getValueAtj, 0 == null { JOptionPane.showMessageDialognull, Label data Anda tidak lengkap. Silahkan lengkapi label data pada file asli Anda.; i = model.getColumnCount - 1; break; } } else { if model.getValueAtj, i == null || model.getValueAtj, i.toString.matchespola || model.getValueAtj, i.toString.matchespola2 { JOptionPane.showMessageDialognull, Data Anda belum lengkap. + Silahkan lengkapi data Anda pada file asli.; i = model.getColumnCount - 1; break; } } } } ListString isiData = new ArrayListString; for int i = 0; i model.getColumnCount; i++ { fm = new SeleksiAtribut; fm.setAtribut2model.getColumnNamei; fm.setPilihfalse; cb_table.addi, fm; } deteksiOutlierTabel.setAutoResizeModeJTable.AUTO_RESIZE_OFF; deteksiOutlierTabel.setModelmodel; updateCellWidthdeteksiOutlierTabel; jumDataField.setTextjumlahDataField.getText; hapusAtributTable.setModelcb_table; hapusAtributButton.setEnabledtrue; checkAllButton.setEnabledtrue; uncheckAllButton.setEnabledtrue; submitDataButton.setEnabledtrue; } catch Exception e { } } public boolean cekAtributString x, ListString hapus { boolean y = false; for int i = 0; i hapus.size; i++ { if hapus.geti.equalsx { y = true; } } return y; } public boolean cekAtribut2String x, Vector kolom { boolean y = false; for int i = 0; i kolom.size; i++ { if kolom.geti.equalsx { y = true; } } return y; } http:stackoverflow.comquestions13013989how-to-adjust-jtable-columns-to- fit-the-longest-content-in-column-cells private void updateCellWidthJTable t { adjustRowSizest; for int i = 0; i t.getColumnCount; i++ { adjustColumnSizest, i, 2; } } http:stackoverflow.comquestions13013989how-to-adjust-jtable-columns-to- fit-the-longest-content-in-column-cells private void adjustRowSizesJTable jTable { for int row = 0; row jTable.getRowCount; row++ { int maxHeight = 0; for int column = 0; column jTable.getColumnCount; column++ { TableCellRenderer cellRenderer = jTable.getCellRendererrow, column; Object valueAt = jTable.getValueAtrow, column; Component tableCellRendererComponent = cellRenderer.getTableCellRendererComponentjTable, valueAt, false, false, row, column; int heightPreferable = tableCellRendererComponent.getPreferredSize.height; maxHeight = Math.maxheightPreferable, maxHeight; } jTable.setRowHeightrow, maxHeight; } } http:stackoverflow.comquestions13013989how-to-adjust-jtable-columns-to- fit-the-longest-content-in-column-cells public void adjustColumnSizesJTable table, int column, int margin { DefaultTableColumnModel colModel = DefaultTableColumnModel table.getColumnModel; TableColumn col = colModel.getColumncolumn; int width; TableCellRenderer renderer = col.getHeaderRenderer; if renderer == null { renderer = table.getTableHeader.getDefaultRenderer; } Component comp = renderer.getTableCellRendererComponenttable, col.getHeaderValue, false, false, 0, 0; width = comp.getPreferredSize.width; for int r = 0; r table.getRowCount; r++ { renderer = table.getCellRendererr, column; comp = renderer.getTableCellRendererComponenttable, table.getValueAtr, column, false, false, r, column; int currentWidth = comp.getPreferredSize.width; width = Math.maxwidth, currentWidth; } width += 2 margin; col.setPreferredWidthwidth; col.setWidthwidth; } private void tandaiSemua { for int i = 0; i cb_table.getRowCount; i++ { cb_table.setValueAttrue, i, 1; } } private void batalTandai { for int i = 0; i cb_table.getRowCount; i++ { cb_table.setValueAtfalse, i, 1; } } private void hapusAtribut { ListString hapus_atribut = new ArrayListString; for int i = 0; i cb_table.getRowCount; i++ { if cb_table.getValueAti, 1.equalstrue { hapus_atribut.addcb_table.getValueAti, 0.toString; } } TableModel model = preprocessTabel.getModel; int column = model.getColumnCount; int row = model.getRowCount; Vector columnNames = new Vector; Vector data = new Vector; for int i = 0; i cb_table.getRowCount; i++ { if cekAtributcb_table.getValueAti, 0.toString, hapus_atribut { columnNames.addElementcb_table.getValueAti, 0; } } for int i = 0; i row; i++ { Vector rows = new Vector; for int j = 0; j column; j++ { if cekAtribut2model.getColumnNamej.toString, columnNames { rows.addElementmodel.getValueAti, j; } } data.addElementrows; } DefaultTableModel new_model = new DefaultTableModeldata, columnNames; preprocessTabel.setModelnew_model; if data.isEmpty columnNames.isEmpty { updateCellWidthpreprocessTabel; } if columnNames.isEmpty { jumlahDataField.setTextnull; submitDataButton.setEnabledfalse; checkAllButton.setEnabledfalse; uncheckAllButton.setEnabledfalse; hapusAtributButton.setEnabledfalse; distAtributButton.setEnabledfalse; pathField.setTextnull; jTabbedPane1.setSelectedComponentpanelPreprocess; jTabbedPane1.setEnabledAt1, false; } cb_table.removeRow; } private void distribusiAtribut { ListString daftarAtribut = new ArrayListString; int jumlahAtribut = preprocessTabel.getColumnCount - 1; for int i = 1; i = jumlahAtribut; i++ { daftarAtribut.addpreprocessTabel.getColumnNamei; } HalamanDistribusiAtribut distribusiDialog = new HalamanDistribusiAtributthis, daftarAtribut, preprocessTabel; distribusiDialog.setVisibletrue; } private void submitData { TableModel model = preprocessTabel.getModel; deteksiOutlierTabel.setAutoResizeModeJTable.AUTO_RESIZE_OFF; deteksiOutlierTabel.setModelmodel; updateCellWidthdeteksiOutlierTabel; jumDataField.setTextjumlahDataField.getText; jTabbedPane1.setSelectedComponentpanelDeteksiOutlier; jTabbedPane1.setEnabledAt1, true; } deteksi outlier private void prosesData { String pola = [0-9.]; String pola2 = [.]; if jumDataField.getText.equals { JOptionPane.showMessageDialognull, Anda belum memasukkan data; atributDField.setTextnull; atributMField.setTextnull; jTabbedPane1.setSelectedComponentpanelPreprocess; prosesButton.setEnabledfalse; } else if atributDField.getText.length 0 atributMField.getText.length 0 atributDField.getText.matchespola || atributDField.getText.matchespola2 || atributMField.getText.matchespola || atributMField.getText.matchespola2 { JOptionPane.showMessageDialognull, Nilai M dan D harus berupa bilangan bulat atau desimal; atributDField.setTextnull; atributMField.setTextnull; prosesButton.setEnabledfalse; } else if atributDField.getText.equals || atributMField.getText.equals { JOptionPane.showMessageDialognull, Nilai M dan D harus diisi; prosesButton.setEnabledfalse; } else { double m = Integer.parseIntatributMField.getText; double d = Double.parseDoubleatributDField.getText; GraphController g = new GraphController; g.deteksiOutlierdeteksiOutlierTabel.getRowCount; hasilOutlierTextArea.setTextg.tampilHasildeteksiOutlierTabel, m, d, jumDataField.getText, pathField.getText; prosesButton.setEnabledfalse; atributDField.setTextnull; atributMField.setTextnull; simpanButton.setEnabledtrue; } } private void simpanHasil { JFileChooser fileChooser = new JFileChoosernew FileD:; fileChooser.setFileFilternew FileNameExtensionFilterMicrosoft Word .doc, doc; fileChooser.setFileFilternew FileNameExtensionFilterText Documents .txt, txt; FileOutputStream file_output_stream; int returnValue = fileChooser.showSaveDialogthis; if returnValue == JFileChooser.APPROVE_OPTION { String filename = fileChooser.getSelectedFile.getPath; String extension = fileChooser.getFileFilter.getDescription; File ff = new Filefilename; buat file output stream if extension.equalsMicrosoft Word .doc { ff = new Filefilename + .doc; } else if extension.equalsText Documents .txt { ff = new Filefilename + .txt; } try { file_output_stream = new FileOutputStreamff; } catch FileNotFoundException fe { JOptionPane.showMessageDialogthis, Penyimpanan Hasil Deteksi Outlier Gagal + Periksa kembali lokasi Anda akan menyimpan file; fe.printStackTrace; return; } try { ambil teks dari JTextArea String hasil_text_area = hasilOutlierTextArea.getText; String[] baca = hasil_text_area.split\\n; FileWriter outFile = new FileWriterff; PrintWriter out = new PrintWriteroutFile, true; for int i = 0; i baca.length; i++ { out.println + baca[i].toString; } file_output_stream.close; } catch IOException ie { JOptionPane.showMessageDialogthis, Penyimpanan Hasil Deteksi Outlier Gagal ; atributMField.setTextnull; simpanButton.setEnabledtrue; } } private void simpanHasil { JFileChooser fileChooser = new JFileChoosernew FileD:; fileChooser.setFileFilternew FileNameExtensionFilterMicrosoft Word .doc, doc; fileChooser.setFileFilternew FileNameExtensionFilterText Documents .txt, txt; FileOutputStream file_output_stream; int returnValue = fileChooser.showSaveDialogthis; if returnValue == JFileChooser.APPROVE_OPTION { String filename = fileChooser.getSelectedFile.getPath; String extension = fileChooser.getFileFilter.getDescription; File ff = new Filefilename; buat file output stream if extension.equalsMicrosoft Word .doc { ff = new Filefilename + .doc; } else if extension.equalsText Documents .txt { ff = new Filefilename + .txt; } try { file_output_stream = new FileOutputStreamff; } catch FileNotFoundException fe { JOptionPane.showMessageDialogthis, Penyimpanan Hasil Deteksi Outlier Gagal + Periksa kembali lokasi Anda akan menyimpan file; fe.printStackTrace; return; } try { ambil teks dari JTextArea String hasil_text_area = hasilOutlierTextArea.getText; String[] baca = hasil_text_area.split\\n; FileWriter outFile = new FileWriterff; PrintWriter out = new PrintWriteroutFile, true; for int i = 0; i baca.length; i++ { out.println + baca[i].toString; } file_output_stream.close; } catch IOException ie { JOptionPane.showMessageDialogthis, Penyimpanan Hasil Deteksi Outlier Gagal ; } JOptionPane.showMessageDialogthis, Hasil Deteksi Outlier Telah Berhasil Disimpan di + filename; } simpanButton.setEnabledfalse; }

5.3.2 Implementasi Kelas HalamanPilihDB

Dokumen yang terkait

Deteksi outlier menggunakan Algoritma Local Correlation Integral (LOCI) : studi kasus data akademik mahasiswa Teknik Informatika Universitas Sanata Dharma.

0 0 258

Deteksi outlier menggunakan Algoritma Local Outlier Probability : studi kasus data akademik mahasiswa Program Studi Teknik Informatika Universitas Sanata Dharma.

0 5 265

Deteksi outlier menggunakan Algoritma Connectivity Based Outlier Factor : studi kasus data akademik mahasiswa Teknik Informatika Universitas Sanata Dharma.

0 4 252

Deteksi Outlier menggunakan algoritma Naive Nested Loop : studi kasus data akademik mahasiswa Program Studi Teknik Informatika, Universitas Sanata Dharma, Yogyakarta.

2 3 236

Deteksi outlier menggunakan Algoritma Connectivity Based Outlier Factor studi kasus data akademik mahasiswa Teknik Informatika Universitas Sanata Dharma

1 8 250

Deteksi outlier menggunakan Algoritma Local Outlier Probability studi kasus data akademik mahasiswa Program Studi Teknik Informatika Universitas Sanata Dharma

1 9 263

Deteksi Outlier menggunakan algoritma Block Based Nested Loop studi kasus data akademik mahasiswa Program Studi Teknik Informatika Universitas Sanata Dharma

0 1 200

Deteksi outlier menggunakan Algoritma Local Correlation Integral (LOCI) studi kasus data akademik mahasiswa Teknik Informatika Universitas Sanata Dharma

0 4 256

Deteksi outlier menggunakan algoritma local outlier factor : studi kasus data akademik mahasiswa TI Universitas Sanata Dharma - USD Repository

0 0 241

Deteksi Outlier menggunakan algoritma Naive Nested Loop : studi kasus data akademik mahasiswa Program Studi Teknik Informatika, Universitas Sanata Dharma, Yogyakarta - USD Repository

0 0 234