It looks like you're new here. If you want to get involved, click one of these buttons!
tapi waktu di jalankan GUI yg saya buat malah hang [not responding] TAPI klo tombol [request, get, save] di tekan satu2 tanpa pake looping, data bisa ditampilkan/diambil dan kemudian di save ke database
<pre lang="java">
public static void bySeconds(long Pengali) {
try {
Thread.sleep(Pengali * 1000);
} catch (InterruptedException e) {
//
}
}
public void SBInterval_1Sec() throws InterruptedException {
System.out.println("Wait");
SB_Request();
SBand_Communicator.bySeconds(3);
System.out.println("Done");
SB_GetData();
SBand_Communicator.bySeconds(3);
System.out.println("Wait");
SB_Save();
SBand_Communicator.bySeconds(3);
SBInterval_1Sec();
}
public void SBInterval_3Sec() throws InterruptedException {
System.out.println("Wait");
SB_Request();
SBand_Communicator.bySeconds(3);
System.out.println("Done");
SB_GetData();
SBand_Communicator.bySeconds(3);
System.out.println("Wait");
SB_Save();
SBand_Communicator.bySeconds(3);
SBInterval_3Sec();
}< /pre>
Comments
itu yg langsung bikin kagak respon itu gara-gara sleep nya
sepenangkapan gw dari yg elo mau, itu harusnya bukan pake sleep, tapi timer
http://docs.oracle.com/javase/6/docs/api/javax/swing/Timer.html
http://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html
NB : TAPI, waktu coding diatas dijalankan GUI-nya emang gak respon TAPI output di netbeans jalan mas [gak ada error], per 3 detik hasil println wait > done > wait > done > dst. muncul
saya msh belajar soal EDT [The Event Dispatch Thread]
contohnya bukan source lengkap, tapi setidaknya kamu jadi ada bayangan untuk melepas proses yang membutuhkan waktu dari thread EDT, karena bila tidak dipisah akan membuat GUI freeze.
CASE CLOSE