我覆盖了JFrame中的setVisible()函数.它所做的只是不断增长框架或缩小框架,直到它达到我想要的尺寸.这使得一个简单的动画.我的问题是,它是不稳定的,不平滑的,如果移动框架不能很好地工作.有没有办法可以做到更干净,更流畅,更光滑?
/**
* Sets this window visible and also displays an effect when the window becomes
* visible
* @param visible True if the window should be visible, false otherwise
*/
@Override
public void setVisible(final boolean visible)
{
final int effectSpeed = 5;
if(effect == false)
{
super.setVisible(visible);
}
if(effect && visible)
{
super.setVisible(visible);
//run the window opening effect
new Thread(new Runnable()
{
public void run()
{
for (int i = 0; i <= parent.getHeight(); i = i + effectSpeed)
{
setSize(getPreferredSize().width, i);
try
{
Thread.sleep(1);
}
catch (Exception e)
{
}
}
}
}).start();
}
else if(effect && visible == false)
{
//run the window closing effect
new Thread(new Runnable()
{
public void run()
{
for (int i = parent.getHeight(); i >= 0; i = i - effectSpeed)
{
setSize(getPreferredSize().width, i);
try
{
Thread.sleep(1);
}
catch (Exception e)
{
}
}
DataWindow.super.setVisible(visible);
}
}).start();
}
}