Swing , 多画面 , 控制转移

2022-01-24 00:00:00 java swing jframe

我正在开发一个摇摆应用程序.我正在使用两个屏幕

I am developing a swing application. I am using two screens

1.屏幕 1 中的按钮将启动屏幕 2.

1.A button from screen1 will launch screen 2.

伪代码:

ScreenA extends JFrame{

    onButtonClick(){
        Screen2.setVisible(true);
    }
    System.out.println("Hai");
}

Screen2 extends JFrame{
    onButtonClick{
         Hide this screen;
    }
}

现在的输出是:

  1. 将显示屏幕 22.Hai会被打印出来.

我的目标:我只想在单击屏幕 2 中的按钮并且屏幕 2 消失时才显示 hai.

My Objective : I want to display hai only when a button from screen 2 is clicked and screen 2 dissppears.

我如何实现它?

我尝试在屏幕二中为按钮点击设置一个标志.但程序只是通过条件并继续下一行.我如何保持控制?

I tried setting a flag for buttonclicked in screen two. But the program just passes through the condition and goes on to the next line . How do i keep the control ?

推荐答案

使用模式对话框.有关详细信息,请参阅如何制作对话框.

Use a modal dialog. See How to Make Dialogs for more details.

相关文章