I tried create simple class which can slide a JPanel like this:
+----------+ +------+---+ +----------+ | | | | | | | | JPanel1 | => | JPane| JP| => | JPanel2 | | | | | | | | +----------+ +------+---+ +----------+
I created javax.swing.Timer and added in class
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);
}
}
This is work, but very slowly. I have only 2-3 fps and don’t know how to speed up this method. May you help me?
Perhaps change the Timer’s interval from 50 to some smaller number.
i.e., from this:
to this:
Note: you should avoid use of magic numbers here.
Heck, something like…