다른 클래스 ABC에서 testView라는 클래스의 창을 표시하려고했습니다. 창에 버튼이 있습니다. 버튼 클릭으로 창을 닫고 싶습니다. 어떻게 닫을 수 있습니까?버튼 클릭시 컨테이너 닫기
public class testView extends JFrame {
protected JButton closeButton = new JButton("Close");
testView(){
this.setSize(1000,700);
this.setTitle("Test");
Container window = getContentPane();
window.setLayout(new FlowLayout());
this.setResizable(false);
window.add(closeButton);
}
}
public class ABC{
public static void main(String[] args) {
testView View = new testView();
View.setVisible(true);
}
}
창이 다른 클래스 ABC에서 표시됩니다. 어떻게하면 버튼 클릭시 창을 닫을 수 있습니까?
Dispose() 메소드를 사용하여 종료하십시오. –