import java.awt.event.*;
import javax.swing.*;
class WinKey extends JFrame 
{   
    int x,y;
    JButton jButton1;
    Key key;
    public WinKey()
    {   
        setTitle("¼");
        setLayout(null);
        key=new Key(this);
        jButton1 = new JButton("ƶť");
        jButton1.setBounds(44, 45, 101, 39);
        add(jButton1);
        jButton1.addKeyListener(key);
        setBounds(200, 300, 250, 170);
        validate();
        setVisible(true);
    }
}
class Key extends KeyAdapter
{
WinKey win;
Key(WinKey win)
{
this.win=win;
}
public void keyPressed(KeyEvent e)
    {
        win.x = win.jButton1.getBounds().x;
        win.y = win.jButton1.getBounds().y;
        if (e.getKeyCode() == KeyEvent.VK_UP)
        {
             win.y = win.y - 2;
             if (win.y <= 0)
             {
             	win.y = 0;
             }
             win.jButton1.setLocation(win.x ,win.y);
        }
        else if (e.getKeyCode() == KeyEvent.VK_DOWN)
        {
             win.y = win.y + 2;
             if (win.y >= 300)
             {
             	win.y = 300;
             }
             win.jButton1.setLocation(win.x ,win.y);
        }
        else if (e.getKeyCode() == KeyEvent.VK_LEFT)
        {
             win.x = win.x - 2;
             if (win.x <= 0)
             {
                win.x = 0;
             }
             win.jButton1.setLocation(win.x,win.y);
        }
        else if (e.getKeyCode() == KeyEvent.VK_RIGHT)
        {
             win.x = win.x + 2;
             if (win.x >= 300)
             {
                win.x = 300;
             }
             win.jButton1.setLocation(win.x ,win.y);
        }
    }
}
class KeyEvent_Test
{
	public static void main(String args[])
    {
        WinKey ta = new WinKey();
    }
}
