hvorfor vil java ikke flytte min firkant??
kan ikek lige se hvorfor min firkant ikke bliver flyttet med piltasterne. Den står bare oppe i det ene hjørne uden at reagerer.KODE:
------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class Firkant
{
private int x;
private int y;
private int b;
private int h;
public Firkant(int x, int y, int b, int h)
{this.x=x;this.y=y;this.b=b;this.h=h;}
public void tegnFirkant(Graphics g,int hor, int ver)
{
g.setColor(Color.lightGray);
g.drawRect(hor,ver,b,h);
}
public int hentX(int hor)
{return hor;}
public int hentY(int ver)
{return ver;}
}
public class falcon extends Frame implements KeyListener
{
int horisontalt;
int vertikalt;
Firkant f = new Firkant(320,240,50,50);
public falcon()
{
super(\"Fighting Falcon\");
setSize(640, 480);
addWindowListener(new CloseCatcher ());
show();
}
public void paint(Graphics g)
{
f.tegnFirkant(g,horisontalt,vertikalt);
}
public static void main(String args[])
{
new falcon();
}
public void keyPressed(KeyEvent ke)
{
if(ke.getKeyCode()==ke.VK_UP)
{
++horisontalt;
repaint();
System.out.println(horisontalt);
}
if(ke.getKeyCode()==ke.VK_DOWN)
{
--horisontalt;
repaint();
System.out.println(horisontalt);
}
if(ke.getKeyCode()==ke.VK_LEFT)
{
--vertikalt;
repaint();
System.out.println(vertikalt);
}
if(ke.getKeyCode()==ke.VK_RIGHT)
{
++vertikalt;
repaint();
System.out.println(vertikalt);
}
}
public void keyReleased(java.awt.event.KeyEvent keyEvent) {
}
public void keyTyped(java.awt.event.KeyEvent keyEvent) {
}
}
class CloseCatcher extends WindowAdapter
{public void windowClosing(WindowEvent e){System.exit(0);}}
------------------------------------------------------