I’m a relatively new programmer, so bear with me. I created a JFrame with the image of the game’s main character. But I can’t figure out how to move it (by adding values to the x axis, like x++ or x–). Is there anyway to do this?
Adding the character:
final JLabel carl = new JLabel("");
carl.setIcon(new ImageIcon(gui.class.getResource("/main/carl.png")));
carl.setBounds(12, 90, 64, 69);
levelOne.add(carl);
Moving the character on button click (I have it set to move to specified coords at the moment):
JButton RightButtonLevelOne = new JButton("Move right");
RightButtonLevelOne.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
carl.setBounds(24, 90, 64, 69);
}
});
Thanks in advance.
1 Answer