开发者

Repaint Main frame

Imagine this situation. I have main JFrame window and another one which pop开发者_StackOverflows out from the main window, by button click. What should I do if I want to repaint graph in main window by clicking the button on the popped up window?


The popped up window needs a reference to the main window. So in the constructor of the popped up window you will accept a reference to the main window and keep it until needed.

In the main window you can write a method update() that can be called from the popped up window and cause the main window to repaint itself accordingly. For example:

PoppedUpWindow win = new PoppedUpWindow(this);//this is the main window

and in the popped up window:

MainWindow mainWin;
JButton btn;

public PoppedUpWindow(MainWindow mwin){
    mainWin = mwin;
    btn = new JButton("Click to Update");
    btn.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
              mainWin.update();
        }
    });
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜