Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: What is wrong with my code

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    1
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default What is wrong with my code

    I was following a tutorial exactly, i made sure everything looked the same but it still doesnt work.
    I am using the latest version of NetBeans 7.3.1
    package javagame;
     
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.event.KeyAdapter; 
    import java.awt.event.KeyEvent;
    import javax.swing.JFrame;
     
    public class JavaGame extends JFrame {
     
        int x, y;
        private Image dbImage;
        private Graphics dbg;
     
        public class AL extends KeyAdapter {
            public void KeyPressed(KeyEvent e){
               int KeyCode = e.getKeyCode();        
               if(KeyCode == e.VK_LEFT) {
                  x--;
               }
               if(KeyCode == e.VK_RIGHT) {
                   x++;
               }
                if(KeyCode == e.VK_UP) {
                   y--;
               }
                 if(KeyCode == e.VK_DOWN) {
                   y++;
     
               }
        }
        public void KeyReleased (KeyEvent e) {
     
        }   
      }
      public JavaGame (){
        addKeyListener(new JavaGame.AL());    
        setTitle("Java Game");
        setSize(500, 500);
        setResizable(true);
        setVisible(true);
        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.fillOval(x, y, 15, 15);
          repaint(); 
      }
     
      public static void main(String[] args){
          new JavaGame(); 
      }
     
    }
    Last edited by pbrockway2; June 17th, 2013 at 03:28 PM. Reason: code tags added


  2. #2
    Member angstrem's Avatar
    Join Date
    Mar 2013
    Location
    Ukraine
    Posts
    200
    My Mood
    Happy
    Thanks
    9
    Thanked 31 Times in 29 Posts

    Default Re: What is wrong with my code

    What is the desired behaviour, what is the observed behaviour, what are the ideas about possible reasons?

Similar Threads

  1. What's wrong with my code?
    By Rara in forum What's Wrong With My Code?
    Replies: 8
    Last Post: April 8th, 2013, 01:02 PM
  2. can someone tell me what's wrong with my code
    By Nate08 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 23rd, 2012, 05:07 PM
  3. What is wrong in the code
    By Rajiv in forum JavaServer Pages: JSP & JSTL
    Replies: 4
    Last Post: July 29th, 2011, 12:09 PM
  4. what's wrong with this code
    By gcsekhar in forum Java Networking
    Replies: 5
    Last Post: July 21st, 2011, 06:01 AM
  5. What's wrong with my code
    By javapenguin in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 10th, 2010, 03:24 PM