【发布时间】:2012-07-02 06:28:53
【问题描述】:
我尝试创建可以像这样滑动 JPanel 的简单类:
+----------+ +------+---+ +----------+ | | | | | | | | JPanel1 | => |日语| JP| => | JPanel2 | | | | | | | | +----------+ +------+---+ +----------+
我创建了 javax.swing.Timer 并添加到类中
timer = new Timer(50, this);
timer.start();
static final int frames = 5;
int counter = 0;
actionPerformed(ActionEvent e) {
if (counter >= frames) {
timer.stop();
counter = 0;
} else {
counter++;
jPanel2.setBounds(800 - 800 * counter / frames, 0, 800, 600);
}
}
这是工作,但非常缓慢。我只有 2-3 fps,不知道如何加快这种方法。你能帮帮我吗?
【问题讨论】: