java - How to get Position(x,y Coordinates) of an image on JPanel -


how position (x,y coordinates)of image in jpanel

actually i'm making pacman game. pacman(image) moves in maze in jpanel.i want know xy coordinates of pacman(image) check position of image.

public class pacman extends jpanel{  public image pacleft  ; int x = 0; int y = 0; int xa = 0; int ya = 0; private board board;  pacman(board board){     this.board = board;     pacleft = new imageicon("pac.png").getimage(); } public void move(){     if(x + xa > 0 && x + xa < board.getwidth()-pacleft.getwidth(board))         x = x+xa;     if(y + ya > 0 && y+ya < board.getheight()-pacleft.getheight(board))         y = y+ya;  }   @override public void paint(graphics g) {    g.drawimage(pacleft,x,y,this); }   public void keypressed(keyevent e){     if(e.getkeycode() == keyevent.vk_left){         xa = -1;      }      if(e.getkeycode() == keyevent.vk_right)         xa = 1;     if(e.getkeycode() == keyevent.vk_up)         ya = -1;     if(e.getkeycode() == keyevent.vk_down)         ya = 1;  } public void keyreleased(keyevent e){     xa = 0;     ya = 0; }   } 


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -