Witam "programuje" w jawie dopiero od 2 dni i mam taki problem
robie aplet 600x400 w ktorym jest obrazek o polozeniu x=300, y=200
i po kliknieciu lewym y++; prawym y--;
i wszystko dziala ok tylko stara pozycja obrazka pozostaje i sie nakladaja na siebie
kod
public class operacje extends JPanel implements MouseListener{
Image ludzik;
int x=300,y=200;
public operacje(){
setBackground(new Color(255,255,255));
setPreferredSize(new Dimension(600,400));
try{
ludzik =new ImageIcon(this.getClass().getResource("gam/lud.png")).getImage();
}catch(Exception e){ System.out.println("Nie można wczytać obrazu");}
addMouseListener(this);
}
@Override
public void paintComponent(Graphics g){
Graphics2D g2=(Graphics2D)g;
g2.drawImage(ludzik,x,y,null);
}
public void mousePressed(MouseEvent me){
int xme=me.getX();
int yme=me.getY();
int butt=me.getButton();
// /*
if(butt == 1)y++;
else if(butt == 2){x--; y--;}
else if(butt == 3)y--;
/**/
repaint();
}
/*
public void mouseReleased(MouseEvent me){
int butt=me.getButton();
if(butt == 1){y+=10;}
else if(butt == 3){y-=10;}
repaint();
}
/**/
public void mouseEntered(MouseEvent me){}
public void mouseExited(MouseEvent me){}
//public void mousePressed(MouseEvent me){}
public void mouseReleased(MouseEvent me){}
public void mouseClicked(MouseEvent me) {}
}