Created
December 19, 2014 06:21
-
-
Save anugrahbsoe/4f14aa8e8103ab4bb3e2 to your computer and use it in GitHub Desktop.
Menampilkan arahan di posisi E
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//===============Cari method tampilTabel(); kemudian ganti kodennya jadi ini | |
public void tampilTabel() { | |
if(lblId.getText().contains("E")){ | |
try { | |
hapusIsiTabel(); | |
Connection con = (Connection) Koneksi.getKoneksi(); | |
Statement state = (Statement) con.createStatement(); | |
String query = "select distinct Target.IdKerusakan,Kerusakan.NmKerusakan from Target,Kerusakan where Kerusakan.IdKerusakan = Target.IdKerusakan and Target.IdGejala='"+lblId.getText()+"'"; | |
ResultSet rs = (ResultSet) state.executeQuery(query); | |
while (rs.next()) { | |
//tambahan | |
Object obj[] = new Object[2]; | |
obj[0] = rs.getString(1); | |
obj[1] = rs.getString(2); | |
tabelModel.addRow(obj); | |
sesuaikanKolom(); | |
} | |
rs.close(); | |
state.close(); | |
} catch (Exception ex) { | |
System.out.println(ex); | |
} | |
} | |
else if(lblId.getText().contains("D") || lblId.getText().contains("C") || lblId.getText().contains("B") || lblId.getText().contains("A")){ | |
try { | |
hapusIsiTabelkedua(); | |
Connection con = (Connection) Koneksi.getKoneksi(); | |
Statement state = (Statement) con.createStatement(); | |
String query = "select distinct Target.IdKerusakan,Kerusakan.NmKerusakan from Target,Kerusakan where Kerusakan.IdKerusakan = Target.IdKerusakan and Target.IdGejala='"+lblId.getText()+"'"; | |
ResultSet rs = (ResultSet) state.executeQuery(query); | |
while (rs.next()) { | |
// Query didalam query; untuk menampilkan gejala | |
Statement state1 = (Statement) con.createStatement(); | |
String jalary = "select distinct Kerusakan.IdKerusakan,Kerusakan.NmKerusakan,Gejala.IdGejala ,Gejala.NmGejala from Target,Gejala,Kerusakan where Target.IdKerusakan = '"+ rs.getString(1) +"' and Gejala.IdGejala > '"+ lblId.getText() +"' and Gejala.IdGejala = Target.IdGejala and Target.IdKerusakan = Kerusakan.IdKerusakan"; | |
ResultSet rs1 = (ResultSet) state1.executeQuery(jalary); | |
while(rs1.next()){ | |
Object obj1[] = new Object[4]; | |
obj1[0] = rs1.getString(1); | |
obj1[1] = rs1.getString(2); | |
obj1[2] = rs1.getString(3); | |
obj1[3] = rs1.getString(4); | |
tabelModel.addRow(obj1); | |
sesuaikanKolom(); | |
} | |
rs1.close(); | |
state1.close(); | |
} | |
rs.close(); | |
state.close(); | |
} catch (Exception ex) { | |
System.out.println(ex); | |
} | |
} | |
} | |
void sesuaikanKolomkedua() { | |
// cara untuk menyesuaikan kolom dari tabel adalah mengambil | |
// lebar kolom yang ada kemudian sesuaikan | |
TableColumnModel modelKolom = table.getColumnModel(); | |
for (int kol = 0; kol < modelKolom.getColumnCount(); kol++) { | |
int lebarKolomMax = 0; | |
for (int baris = 0; baris < table.getRowCount(); baris++) { | |
TableCellRenderer rend = table.getCellRenderer(baris, kol); | |
Object nilaiTablel = table.getValueAt(baris, kol); | |
Component comp = rend.getTableCellRendererComponent(table, | |
nilaiTablel, false, false, baris, kol); | |
lebarKolomMax = Math.max(comp.getPreferredSize().width, | |
lebarKolomMax); | |
}// akhir for baris | |
TableColumn kolom = modelKolom.getColumn(kol); | |
kolom.setPreferredWidth(lebarKolomMax); | |
}// akhir for kolom | |
} | |
public void hapusIsiTabelkedua() { | |
int a = table.getRowCount(); | |
int brs; | |
for (brs = 0; brs < a; brs++) { | |
tabelModel.removeRow(0); | |
} | |
} | |
void sesuaikanKolom() { | |
// cara untuk menyesuaikan kolom dari tabel adalah mengambil | |
// lebar kolom yang ada kemudian sesuaikan | |
TableColumnModel modelKolom = table.getColumnModel(); | |
for (int kol = 0; kol < modelKolom.getColumnCount(); kol++) { | |
int lebarKolomMax = 0; | |
for (int baris = 0; baris < table.getRowCount(); baris++) { | |
TableCellRenderer rend = table.getCellRenderer(baris, kol); | |
Object nilaiTablel = table.getValueAt(baris, kol); | |
Component comp = rend.getTableCellRendererComponent(table, | |
nilaiTablel, false, false, baris, kol); | |
lebarKolomMax = Math.max(comp.getPreferredSize().width, | |
lebarKolomMax); | |
}// akhir for baris | |
TableColumn kolom = modelKolom.getColumn(kol); | |
kolom.setPreferredWidth(lebarKolomMax); | |
}// akhir for kolom | |
} | |
public void hapusIsiTabel() { | |
int a = table.getRowCount(); | |
int brs; | |
for (brs = 0; brs < a; brs++) { | |
tabelModel.removeRow(0); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment