alexa-tracking

Main Content

1024
1024
KASKUS
51
244
https://www.kaskus.co.id/thread/53bc4721529a454b6b8b45e8/tolong-bantuanya-para-master-java
Tolong Bantuanya Para Master Java
seperti ini:
Code:

public FrmWaktuTidakBersedia() throws SQLException {
initComponents();
formCenter();
cmbDosen.removeAllItems();
int rowCount = util.getCount("SELECT * FROM dosen ORDER BY nama", "nama");
kodeDosen = new int[rowCount];
ResultSet dosen_dt = MysqlConnect.getDbCon().query("SELECT * FROM dosen ORDER BY nama");
int i = 0;
while (dosen_dt.next()) {
cmbDosen.addItem(dosen_dt.getString("nama"));
kodeDosen[i] = Integer.parseInt(dosen_dt.getString("kode"));
i++;
}
loadData(kodeDosen[0]);
MyItemListener actionListener = new MyItemListener();

cmbDosen.addItemListener(actionListener);
cek.addItemListener(actionListener);
}
public boolean getVisible() {
return visible;
}
private void loadData(int kode_dosen) throws SQLException {
int hari_row = util.getCount("SELECT * FROM hari", "kode");
int jam_row = util.getCount("SELECT * FROM jam", "kode");
int waktu_tidak_bersedia = util.getCount(
"SELECT * FROM waktu_tidak_bersedia "
+ "WHERE kode_dosen=" + kode_dosen, "kode_hari");

ResultSet dtHari = MysqlConnect.getDbCon().query("SELECT nama,kode FROM hari");
ResultSet dtJam = MysqlConnect.getDbCon().query("SELECT range_jam,kode FROM jam");

ResultSet dt = MysqlConnect.getDbCon().query(
"SELECT kode_hari,kode_jam "
+ "FROM waktu_tidak_bersedia "
+ "WHERE kode_dosen =" + kode_dosen);

tabelTidakBersedia.removeAll();

String column_names[] = {"Hari", "Jam", "Tidak Bersedia","kodehari","kodejam"};
DefaultTableModel model = new DefaultTableModel(column_names, 0);
Object[][] rowData = {};
while (dtHari.next()) {
dtJam.beforeFirst();
while (dtJam.next()) {
String rowHari = dtHari.getString("nama");
String rowKodeHari = dtHari.getString("kode");
String rowJam = dtJam.getString("range_jam");
String rowKodeJam = dtJam.getString("kode");
dt.beforeFirst();
[color=red] boolean checked = false;[/color]
while(dt.next()){
String hariTidakBersedia = dt.getString("kode_hari");
String jamTidakBersedia = dt.getString("kode_jam");

if(rowKodeHari.equals(hariTidakBersedia) && rowKodeJam.equals(jamTidakBersedia)){
[color=red] checked = true;[/color]
}
}

model.addRow(new Object[]{rowHari, rowJam, checked,rowKodeHari,rowKodeJam});

}
}

DefaultTableCellRenderer r;
tabelTidakBersedia.setModel(model);
tabelTidakBersedia.removeColumn(tabelTidakBersedia.getColumnModel().getColumn(3));
tabelTidakBersedia.removeColumn(tabelTidakBersedia.getColumnModel().getColumn(3));

class MyItemListener implements ItemListener {

// This method is called only if a new item has been selected.
public void itemStateChanged(ItemEvent evt) {
JComboBox cb = (JComboBox) evt.getSource();

Object item = evt.getItem();

if (evt.getStateChange() == ItemEvent.SELECTED) {
try {
// Item was just selected
loadData(kodeDosen[cb.getSelectedIndex()]);


//JOptionPane.showMessageDialog(null, kodeDosen[cb.getSelectedIndex()]);
} catch (SQLException ex) {
Logger.getLogger(FrmWaktuTidakBersedia.class.getName()).log(Level.SEVERE, null, ex);
}
} else if (evt.getStateChange() == ItemEvent.DESELECTED) {

}
}
}

tampilan formnya seperti ini:
Tolong Bantuanya Para Master Java
yang ane inginkan adalah jika memilih item di jComboBox "Select all" maka boolean checked akan bernilai true,..
mohon bantuanya dari para master...
thanks..
emoticon-I Love Indonesia (S) emoticon-I Love Kaskus (S)
Quote:Original Posted By dotpixel24
seperti ini:
Code:

public FrmWaktuTidakBersedia() throws SQLException {
initComponents();
formCenter();
cmbDosen.removeAllItems();
int rowCount = util.getCount("SELECT * FROM dosen ORDER BY nama", "nama");
kodeDosen = new int[rowCount];
ResultSet dosen_dt = MysqlConnect.getDbCon().query("SELECT * FROM dosen ORDER BY nama");
int i = 0;
while (dosen_dt.next()) {
cmbDosen.addItem(dosen_dt.getString("nama"));
kodeDosen[i] = Integer.parseInt(dosen_dt.getString("kode"));
i++;
}
loadData(kodeDosen[0]);
MyItemListener actionListener = new MyItemListener();

cmbDosen.addItemListener(actionListener);
cek.addItemListener(actionListener);
}
public boolean getVisible() {
return visible;
}
private void loadData(int kode_dosen) throws SQLException {
int hari_row = util.getCount("SELECT * FROM hari", "kode");
int jam_row = util.getCount("SELECT * FROM jam", "kode");
int waktu_tidak_bersedia = util.getCount(
"SELECT * FROM waktu_tidak_bersedia "
+ "WHERE kode_dosen=" + kode_dosen, "kode_hari");

ResultSet dtHari = MysqlConnect.getDbCon().query("SELECT nama,kode FROM hari");
ResultSet dtJam = MysqlConnect.getDbCon().query("SELECT range_jam,kode FROM jam");

ResultSet dt = MysqlConnect.getDbCon().query(
"SELECT kode_hari,kode_jam "
+ "FROM waktu_tidak_bersedia "
+ "WHERE kode_dosen =" + kode_dosen);

tabelTidakBersedia.removeAll();

String column_names[] = {"Hari", "Jam", "Tidak Bersedia","kodehari","kodejam"};
DefaultTableModel model = new DefaultTableModel(column_names, 0);
Object[][] rowData = {};
while (dtHari.next()) {
dtJam.beforeFirst();
while (dtJam.next()) {
String rowHari = dtHari.getString("nama");
String rowKodeHari = dtHari.getString("kode");
String rowJam = dtJam.getString("range_jam");
String rowKodeJam = dtJam.getString("kode");
dt.beforeFirst();
[color=red] boolean checked = false;[/color]
while(dt.next()){
String hariTidakBersedia = dt.getString("kode_hari");
String jamTidakBersedia = dt.getString("kode_jam");

if(rowKodeHari.equals(hariTidakBersedia) && rowKodeJam.equals(jamTidakBersedia)){
[color=red] checked = true;[/color]
}
}

model.addRow(new Object[]{rowHari, rowJam, checked,rowKodeHari,rowKodeJam});

}
}

DefaultTableCellRenderer r;
tabelTidakBersedia.setModel(model);
tabelTidakBersedia.removeColumn(tabelTidakBersedia.getColumnModel().getColumn(3));
tabelTidakBersedia.removeColumn(tabelTidakBersedia.getColumnModel().getColumn(3));

class MyItemListener implements ItemListener {

// This method is called only if a new item has been selected.
public void itemStateChanged(ItemEvent evt) {
JComboBox cb = (JComboBox) evt.getSource();

Object item = evt.getItem();

if (evt.getStateChange() == ItemEvent.SELECTED) {
try {
// Item was just selected
loadData(kodeDosen[cb.getSelectedIndex()]);


//JOptionPane.showMessageDialog(null, kodeDosen[cb.getSelectedIndex()]);
} catch (SQLException ex) {
Logger.getLogger(FrmWaktuTidakBersedia.class.getName()).log(Level.SEVERE, null, ex);
}
} else if (evt.getStateChange() == ItemEvent.DESELECTED) {

}
}
}

tampilan formnya seperti ini:
Tolong Bantuanya Para Master Java
yang ane inginkan adalah jika memilih item di jComboBox "Select all" maka boolean checked akan bernilai true,..
mohon bantuanya dari para master...
thanks..
emoticon-I Love Indonesia (S) emoticon-I Love Kaskus (S)


gw kasih permisalan saja yah
misalkan JCombobox adalah dosen
Code:

JComboBox combodosen=new JComboBox();
combodosen.addItem(....) //input sendiri

//terus pake actionlistener
ActionListner actiondosen=new ActionListener(
{
//nanti isinya

if(combodosen.getSelectedIndex()==0)
//disini kita misalkan index 0 adalah select ALL
{
checked=true;
}
else
{
checked=false;
}
});


terus jangan lupa combodosen.addActionListener(actiondosen);


harusnya udah working
jadi nanti kamu ganti itu itemlistner di code kamu jadi actionlistener

note: gambarnya kekecilan, ga bisa dilihat om emoticon-Bingung (S)