I'm trying to make the person walk but for some reason when I switch icons the label returns to it's default location for a split second then updates to the where I set the bounds. Extremely annoying, any help is much appreciated. Thank You.
public class Main extends JFrame implements ActionListener{
JLabel x = new JLabel("");
ImageIcon player1 = new ImageIcon("C:\\Users\\Kyle\\Documents\\NetBeansProjects\\Testing52\\src\\testing52\\Player1.png");
ImageIcon player2 = new ImageIcon("C:\\Users\\Kyle\\Documents\\NetBeansProjects\\Testing52\\src\\testing52\\Player2.png");
static int count;
Timer timer;
Main(){
timer = new Timer(100,this);
setVisible(true);
setSize(500,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setFocusable(false);
add(x);
timer.start();
}
public static void main(String [] args){
Main main = new Main();
}
@Override
public void actionPerformed(ActionEvent e) {
count += 1;
if(count == 10){
x.setIcon(player1);
}
if(count == 20){
x.setIcon(player2);
}
if(count == 30){
count = 0;
}
x.setBounds(0, 0,60,60);
}
}