当我在程序中按一个按钮时,我想对JFrame进行动画处理,使其变为一半大小。我认为最简单的方法是将JFrame的当前边界放入一个定时器中,并在定时器运行时将其边界减小1。但是,当我在netbeans IDE中声明一个新的定时器时,它将看起来像这样。

      Timer t = new Timer(5,new ActionListener() {

        public void actionPerformed(ActionEvent e) {

          //inside this I want to get my Jframe's bounds like this
           //    int width = this.getWidth();---------here,"this" means the Jframe

           }

        }
    });

但是问题出在这里“this”不是指JFrame。而且我什至不能创建我的JFrame的新对象。因为它将给我另一个窗口。有人可以帮助我解决这个问题吗?

最佳答案

尝试

int width = Foo.this.getWidth();

其中Foo继承了JFrame

10-07 19:10
查看更多