日期:2014-05-20 浏览次数:20592 次
import java.awt.*;
import java.awt.event.*;
public class XN extends Frame
{
int x=50;
int y=50;
public void Kuang(){
this.setTitle("NN");
this.setSize(600,400);
this.setVisible(true);
this.setResizable(true);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
int k = e.getKeyCode();
if(k == KeyEvent.VK_UP)
{ y-=10;
} else if(k == KeyEvent.VK_DOWN)
{
y+=10;
} else if(k == KeyEvent.VK_LEFT)
{
x-=10;
} else if(k == KeyEvent.VK_RIGHT)
{
x+=10;
}
repaint();
}
});
}
public void paint(Graphics g) {
g.setColor(Color.RED);
g.fillOval(x,y,30,30);
}
public static void main(String[] args){
XN x1=new XN();
x1.Kuang();
}
}