Hi everyone.
I'm trying to create a sliding effect for a jPanel. The idea is that the user clicks a button and it scrolls left or right within another jPanel , as if it's rotating.
The actual moving part is easy, however I want it to actually slide rather than just move.
I have tried sleeping the thread for 10ms, moving the JPanel left one pixel, then repainting the panel - looped 70 times. however it seems that it doesn't physically move the jPanel until the loop has finished.
Here's the code I have:
@Action
public void SlideLeft() {
if(jPanel1.getLocation().getX() < 0){
for(double i = 1; i <= 70.0; i++){
scroll(jPanel1, 1);
try{
Thread.sleep(10);
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
}
public void scroll(javax.swing.JPanel what, int amount){
Point temp = what.getLocation();
temp.setLocation(temp.getX() + amount, temp.getY());
what.setLocation(temp);
jPanel2.repaint();
}
jPanel1 is the panel I want to move within jPanel2 (which hides the contents of jPanel1 which aren't in the bounds of jPanel2).
How can I create a sliding effect for this?
(I'm quite new to Java, but not to programming in general).