Skip to main content
gamedev.net
🔒 Locked

[java] Moving images in Java

Started by CRACK123 2 replies 1.1k views
Original Post
CRACK123
CRACK123
Hi, I am using ImageIcon to load images in Java but I am trying to move it. I tried call the move function in actionPerformed function oof the main class - but this does not seem to work. This is what I am doing

public Game extends JPanel implements ActionListener
{
   public void actionPerformed(ActionEvent e)
   {
      player.Move();
      repaint();
   }
}

This seems to be wrong. Any ideas on how this is to be implemented in Java. Thanks
The more applications I write, more I find out how less I know
CRACK123
CRACK123
Hi,

The player code to move is quite simple. I am not doing any drawing in player
at all. I am getting the position for the player in Game using a getter function and the using the position to draw to in paintComponent() function.

This is the code in player.Move()
public void Move(){   pos.y -= 32;}

The more applications I write, more I find out how less I know
harveypekar
harveypekar
Could you post some more code? It's not quite clear where you're actually painting the image, since you also mention paintCompenents... Do you paint manually to the jpanel? or do you add components to it?


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.