Results 1 to 7 of 7
  1. #1
    KCalderon is offline Member
    Join Date
    Nov 2013
    Posts
    5
    Rep Power
    0

    Default This KeyEvent is kicking my butt here

    This isn't a finished code but I'm having a constant issue. This is ment to be a testing program for a game I'm building and I can't seem to get the KeyEvent to work. I keep getting a ';' expected error. I've gone about this every which way and see no need nor reason why I would need a ';'. I can't even think of a way to write it with one in it.

    Java Code:
    package dodge;
    
    import javax.swing.*;
    
    import java.awt.*;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.event.KeyAdapter;
    import java.util.EventListener;
    
    
    
    public class Dodge extends JPanel implements KeyListener {
        private final Dimension setSize;
    
        private int x = 5, y = 5;
        
        @SuppressWarnings("LeakingThisInConstructor")
        public Dodge(){
          setSize = (new Dimension(700, 800));
          setPreferredSize(new Dimension(400, 500));
          setFocusable(true);
          addKeyListener(this);
        }
    //Sets up my test ball
        @Override
           public void paint(Graphics g) {
            g.setColor(Color.black);
            g.fillRect(0, 0, getWidth(), getHeight());
            
            g.setColor(Color.BLUE);
            g.fillOval(x, y, 50, 50);
            repaint();
            
           }
         //My move commands
    
          @Override
    public void keyPressed(KeyEvent e) {
        
        int c = e.getKeyCode();
        
        for(c == KeyEvent.VK_W){
        
            y-=5;
        }
        for(c == KeyEvent.VK_S){
        
            y+=5;
        }
        for(c == KeyEvent.VK_D){
        
            x-=5;
            
         }
        for(c == KeyEvent.VK_A){
        
            x+=5;
            
        } 
    
    }
    @Override
    public void keyReleased(KeyEvent e) {
    
    }
    @Override
    public void keyTyped(KeyEvent e) {
    
            }
    } //Ends movment
    
    
        /**
         *
         * @param args
         */
          
    
        //@Override
        public void keyTyped(KeyEvent e) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    
        //@Override
        public void keyReleased(KeyEvent e) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    }//Ends class

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default Re: This KeyEvent is kicking my butt here

    Your for-loops in your keyPressed( ... ) method don't make sense; check a text book for the correct syntax.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,686
    Rep Power
    5

    Default Re: This KeyEvent is kicking my butt here

    Seems to me like those were intended to be if statements :s
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default Re: This KeyEvent is kicking my butt here

    Quote Originally Posted by gimbal2 View Post
    Seems to me like those were intended to be if statements :s
    It's funny actually, isn't it: people who don't understand the syntax or semantics of a language (yet), start to make up a syntax and the semantics for that language and hope for the best; the same happens for natural languaages ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,686
    Rep Power
    5

    Default Re: This KeyEvent is kicking my butt here

    Funny? No, it makes me cry in both situations (programming and natural). Although in the case of a natural language I would find it funny if it is an act of creativity in stead of laziness.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default Re: This KeyEvent is kicking my butt here

    Quote Originally Posted by gimbal2 View Post
    Funny? No, it makes me cry in both situations (programming and natural). Although in the case of a natural language I would find it funny if it is an act of creativity in stead of laziness.
    I meant 'funny' in a sad way indeed; especially for a programming language with well defined syntax and semantics ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    KCalderon is offline Member
    Join Date
    Nov 2013
    Posts
    5
    Rep Power
    0

    Default Re: This KeyEvent is kicking my butt here

    Thanks man, it was an "if" statement. The finished version works perfectly.

Similar Threads

  1. JAVA is kickin my butt - Arraylist issue
    By 2rr2nv in forum New To Java
    Replies: 1
    Last Post: 11-20-2011, 04:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •