JFrameと2つのJRadioButtonを作成し、それらにActionListenersを追加する関数graphics()があります。このグラフィックはmain()から呼び出され、グラフィック自体はgame()を呼び出します。
public void game() throws Exception
{
jTextArea1.setLineWrap(true);
jTextArea1.setWrapStyleWord(true);
jTextArea1.setText("This is private information.");
jRadioButton1.setVisible(true);
jRadioButton2.setVisible(true);
try {
t.sleep(40000);
repaint();
} catch (InterruptedException e) {
// We've been interrupted: no more messages.
return;
}
「これは個人情報です」と表示した後。テキストエリアで、プログラムの実行を40秒間、またはユーザーがJRadioButtonを押すまでのいずれか早い方で一時停止します。そこで、ActionListenerを追加し、その中にt.interrupt()を呼び出しました。
private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
t.interrupt();
jRadioButton1.setVisible(false);
jRadioButton2.setVisible(false);
//System.out.println(t.interrupted());
jTextArea1.setText("Please wait...");
}
ただし、割り込みをトリガーするJRadioButtonを選択した後でも、それは発生せず、t.interruptedはfalseを返します。
どんな助けでもいただければ幸いです。