Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication9;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.event.KeyAdapter;
- import java.awt.event.KeyEvent;
- import javax.swing.ImageIcon;
- import javax.swing.JFrame;
- public class JavaApplication9 extends JFrame {
- int x, y;
- private Image dbImage;
- private Graphics dbg;
- Image face;
- Font font = new Font("Arial", Font.BOLD, 30);
- public class AL extends KeyAdapter{
- public void keyPressed(KeyEvent e){
- int keyCode = e.getKeyCode();
- if(keyCode == e.VK_LEFT){
- x += -10;
- }
- if(keyCode == e.VK_RIGHT){
- x += +10;
- }
- if(keyCode == e.VK_UP){
- y += -10;
- }
- if(keyCode == e.VK_DOWN){
- y += +10;
- }
- }
- }
- public JavaApplication9(){
- //Loading Images
- ImageIcon i = new ImageIcon("C:/Documents and Settings/studio/My Documents/NetBeansProjects/JavaApplication9/src/javaapplication9/reddevilhead.gif");
- face = i.getImage();
- //Game Properties
- addKeyListener(new AL());
- setTitle("Battle Fortess 8 Alpha _.1");
- setSize(250, 250);
- setResizable(true);
- setVisible(true);
- setBackground(Color.green);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- x = 150;
- y = 150;
- }
- public void paint (Graphics g){
- dbImage = createImage(getWidth(), getHeight());
- dbg = dbImage.getGraphics();
- paintComponent(dbg);
- g.drawImage(dbImage, 0, 0, this);
- }
- public void paintComponent(Graphics g){
- g.drawImage(face, x, y, this);
- }
- public static void main(String[] args){
- new JavaApplication9();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement