Little problem

Image (donut) doesnt drop normally… but if i press buttons it drops little bit in every press



     package org.me.hello;

     import java.applet.*;
     import java.awt.*;
     import java.awt.event.*;
          
     public class peli extends Applet implements KeyListener,Runnable {
          
     Font fontti = new Font("Helvetica", Font.BOLD,  20);    
     
     Image homer;
     Image homerv;      
     Image sydan;
     Image donut; 
     
     int aika=0;
     int aks;
     int x,y;
     int pisteet,livet;
    
     public boolean oikee;
     public boolean vasen;
     public boolean tippuu;
     public boolean focus;
          
     private Thread thread =new Thread(this);
             	  
     public void run(){             
                     
     while (true) {
         
     try{                     
     
     Thread.currentThread().sleep(20); 
     }catch(InterruptedException e){ 
     }     
     
     repaint();
         
     }    
     }
     
     public void init(){   
     this.aks=(int)(4*Math.random()*100+4);      
     addKeyListener(this);
     setBackground(Color.BLACK);
     donut = getImage(getDocumentBase(),"donutti.png");
     homer = getImage(getDocumentBase(),"homer.png");
     homerv = getImage(getDocumentBase(),"homerv.png");
     sydan = getImage(getDocumentBase(),"sydan.png");     
     resize(600,400);
     livet = 4;
     x=175;
     y=-70;
     }
             
     public void keyPressed(KeyEvent e) {
    
          if (e.getKeyCode() == KeyEvent.VK_ENTER) {
             tippuu = true;             
          }
         
          if (e.getKeyCode() == KeyEvent.VK_LEFT) {
             vasen = true;
          }
         
          
          if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
             oikee = true;
          }
          
     if(oikee == true){
     if(x<350)x = x+10;
     } 
              
          
     if(vasen == true){
     if(x>0)x = x-10;
     }
         
     if(tippuu==true)y = y +5;     
          
     repaint();
     }
     
     public void keyReleased(KeyEvent e) {
     
          if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
              oikee = false;
          }
          
          if (e.getKeyCode() == KeyEvent.VK_LEFT) {
              vasen = false;
          }                       
     }
           
    public void actionPerformed(ActionEvent e) {}
    
     public void alas(){
               
     }
     
     public void paint(Graphics g) {
     
     g.setColor(Color.red);
     g.drawRect(450,1,5,1000);
     g.setFont(fontti);
     g.drawString("Lives:",470,50);
     
     if(livet > 1){
     g.drawImage(sydan,470,65,30,30,this);
     }
     
     if(livet > 2){
     g.drawImage(sydan,500,65,30,30,this);
     }
     
     if(livet > 3){
     g.drawImage(sydan,530,65,30,30,this);
     }
     
     g.drawString("Points:"+pisteet+"",470,130);
         
     if(vasen==false){    
     g.drawImage(homer,x,313,83,100,this);
     }
    
     if(vasen==true){
     g.drawImage(homerv,x,313,83,100,this);               
     }
     
     g.drawImage(donut,aks,y,50,50,this);
     }
     
    public void keyTyped(KeyEvent e) {
    }
    }

ok, i suppose u want the donut to start moving down if u press down? I dont quiet get the meaning of “oikee”, “vasen” and “tippuu”, but the idea is this:


int speed=0,x,y;
...
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_DOWN)speed=5;
...
}
...
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_DOWN)speed=0;
...
}
public void run(){
while (true) {
y+=speed;
     try{                     
     Thread.currentThread().sleep(20); 
     }catch(InterruptedException e){ 
     }     
     repaint();
     }    
}
...
public void paint(Graphics g){
g.drawImage(donut,x,y,null,this);
...
}

Short introduction to the Finnish language:

sydan (sydän) = heart
aika = time
aks (akseli?) = axis
pisteet = points
livet (English word “live/life” in Finnish plural, the real Finnish word is “elämät”) = lives
oikee (slang for “oikea”) = right
vasen = left
tippuu = [it] falls
alas = down

PS: It’s better to write all code in English. Then more people can read the code and the code will look more consistent, because every library you will use is also written in English. And even though Java supports Unicode characters in variable and method names, that does not mean that you should use them there. (I once tried writing method names with Chinese characters just to see that it was possible. It might be good for obfuscation job security, though. ;))

Thanks jackal for that crarification…
ill try ty remember to use english in codes…