1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| package EroQx;
import java.awt.Graphics;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
@SuppressWarnings("serial")
public class Class1 extends JFrame{
int x, y;
public class Al extends KeyAdapter{
public void KeyPressed(KeyEvent e){
int KeyCode = e.getKeyCode();
if (KeyCode == KeyEvent.VK_UP){
y++;
}
if (KeyCode == KeyEvent.VK_DOWN){
--y;
}
if (KeyCode == KeyEvent.VK_RIGHT){
x++;
}
if (KeyCode == KeyEvent.VK_LEFT){
--x;
}
}
public void KeyReleased(KeyEvent e){
}
}
public Class1(){
addKeyListener(new Al());
setTitle("EroQx");
setSize(250, 250);
setResizable(false);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
x = 25;
y = 25;
}
public void paint(Graphics g){
g.fillOval(x, y, 75, 75);
repaint();
}
public static void main(String[] args){
new Class1();
}
} |
Partager