다음 코드가 작동하지 않는 이유는 무엇입니까? 기본적으로 이것은 좀 더 어려운 프로그램의 단순화 된 버전으로 다른 실행 파일에 링크 된 버튼이있는 선택 항목으로 실행 가능한 초기 화면을 만들려고 시도하지만 예상대로 실행되지 않습니다.다른 Runnable 내부에서 Runnable을 실행하는 Java가 작동하지 않음
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Runnables {
static Runnable runone;
static Runnable runtwo;
static JFrame frame = new JFrame();
static JButton button1 = new JButton("Initial screen");
static JButton button2 = new JButton("After button click screen");
public static void main(String[] args) {
runone = new Runnable() {
@Override
public void run() {
frame.removeAll();
frame.revalidate();
frame.repaint();
frame.add(button2);
}
};
runtwo = new Runnable() {
@Override
public void run() {
frame.setSize(800, 600);
frame.setVisible(true);
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
runone.run();
System.out
.println("This is performed, but the button doesnt change");
}
});
frame.add(button1);
}
};
runtwo.run();
}
}
당신은 당신의 Runnable를 처음으로 확인하는에 디버그 문을 추가 시도? 서면으로, 그것은 곧바로 함수 호출, 그것에 대해 특별한 아무것도 아니에요 ... – Krease