別のクラスから通知スレッドを呼び出そうとしていますが、すべて間違っていると思います。同様のことを試みている人々の例を数多く読んだことがありますが、それを自分のコードに適用できないようです。私の問題は同期されたオブジェクトだと思いますが、よくわかりません。私はスレッドに不慣れなので、屈辱を与えないでください。これが私のコードの例です:
public class SendTextOffEdt implements Runnable {
private static final long SLEEP_TIME = 3000;
public static String TEXT = "Sent off of EDT\n";
private TextBox myTextBox;
//public boolean waitBoolean = false;
public SendTextOffEdt(TextBox myTextBox) {
this.myTextBox = myTextBox;
}
@Override
public void run() {
synchronized(this){
//while (true) {
try {
myTextBox.appendTextOffEdt(TEXT);
wait();
} catch (InterruptedException e) { //******** i changed this from another exception!!
System.out.println("*----------thread interrupted!");
myTextBox.appendTextOffEdt(TEXT);
}
}
}
}
public class Combat extends JPanel {
private SendTextOffEdt sendTextOffEdt = new SendTextOffEdt(textbox); //just added this object
public Combat(){
TestNotify();
}
public void TestNotify(){
synchronized(sendTextOffEdt){ //added the sendTextOffEdt object here
sendTextOffEdt.notifyAll();
System.out.println("has been notified");
}
}
}