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: java game errors

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java game errors

    I am receiving two errors that I'm not sure how to fix. The first is illegal start of expression at line "public void actionPerformed(ActionEvent e)" and no suitable method found for intersect JButton at line "if(blocker01.getBounds().intersects(r_wall))" . Any help would be appreciated.

     
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
     
    public class gamePanel01 extends JPanel implements KeyListener
    {
        character ch1 = new character("Hero");
        int w,l;
     
        JButton blocker01;
        JButton blocker02;
        JButton blocker03;
        JButton blocker04;
        JButton blocker05;
        JButton r_wall;
        int limit2=0;
        int delay=0;
        Timer tim;
            int x=100;
        int y=100;
     
     
        ClassLoader cl = this.getClass().getClassLoader();    
        Image gamePanelBG = new ImageIcon(cl.getResource("images/gamePanel01.jpg")).getImage();
        ImageIcon PSUBlocker = new ImageIcon(cl.getResource("images/PSU_Helmet_Blocker.gif"));
        ImageIcon PSULionRight = new ImageIcon(cl.getResource("images/NittanyLion_Mini_Right.png"));
        ImageIcon PSULionLeft = new ImageIcon(cl.getResource("images/NittanyLion_Mini_Left.png"));
     
        public gamePanel01()
        {
        super();
        setLayout(null);
     
        add(ch1);    
        ch1.setIcon(PSULionRight);
        ch1.setBounds(new Rectangle(x,y,45,45));
        ch1.addKeyListener(this);
     
        ch1.setFocusPainted(false);
        ch1.setContentAreaFilled(false);
        ch1.setBorderPainted(false);
     
     
        blocker01 = new JButton();
        blocker02 = new JButton();
        blocker03 = new JButton();
        blocker04 = new JButton();
        blocker05 = new JButton();
       r_wall= new JButton();
        add(blocker01);
        add(blocker02);
        add(blocker03);
        add(blocker04);
        add(blocker05);
          blocker01.setBounds(new Rectangle(250,150,45,45));
        blocker02.setBounds(new Rectangle(250,195,45,45));
        blocker03.setBounds(new Rectangle(400,240,45,45));
        blocker04.setBounds(new Rectangle(400,285,45,45));
        blocker05.setBounds(new Rectangle(400,330,45,45));
        r_wall.setBounds(new Rectangle (250,150,45,45));
     
         blocker01.setIcon(PSUBlocker);
        blocker01.setFocusPainted(false);
        blocker01.setContentAreaFilled(false);
        blocker01.setBorderPainted(false);
     
        blocker02.setIcon(PSUBlocker);
        blocker02.setFocusPainted(false);
        blocker02.setContentAreaFilled(false);
        blocker02.setBorderPainted(false);
     
        blocker03.setIcon(PSUBlocker);
        blocker03.setFocusPainted(false);
        blocker03.setContentAreaFilled(false);
        blocker03.setBorderPainted(false);
     
        blocker04.setIcon(PSUBlocker);
        blocker04.setFocusPainted(false);
        blocker04.setContentAreaFilled(false);
        blocker04.setBorderPainted(false);
     
        blocker05.setIcon(PSUBlocker);
        blocker05.setFocusPainted(false);
        blocker05.setContentAreaFilled(false);
        blocker05.setBorderPainted(false);
     
     
        }
        @Override
       public void paintComponent(Graphics g)
       {
       super.paintComponent(g);
       g.drawImage(gamePanelBG, 0, 0, this);
        }
     
       public void keyPressed(KeyEvent ev)
      {
          int k= ev.getKeyCode();      
          if (k==KeyEvent.VK_LEFT)
          {
              x=x-5;
              ch1.setIcon(PSULionLeft);
          }
          if(k==KeyEvent.VK_RIGHT)
          {
              x=x+5;
              ch1.setIcon(PSULionRight);
          }
          if(k==KeyEvent.VK_UP) {y=y-5;}
          if(k==KeyEvent.VK_DOWN) {y=y+5;}
          ch1.setBounds(new Rectangle(x,y,45,45));
          //Rectangle r1=new Rectangle(x,y,45,45);
          //setBounds(r1);
          tim=new Timer(delay, (ActionListener) this);
         tim.start();
         {
        public void actionPerformed(ActionEvent e)//error
            {
                Object obj = e.getSource();
     
                if (obj == tim)
    		{
    		blocker01.setBounds(x,y,w,l);
    		}
                if (obj==tim)
                {
                    if(blocker01.getBounds().intersects(r_wall))//error
                    {
     
                    }
                    else 
                        blocker01.setBounds(x,y,w,l);
                }
     
     
      }
       public void keyReleased(KeyEvent evt) {  }
     
       public void keyTyped(KeyEvent evt) {  }
     
     
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: java game errors

    By convention in Java, class names begin with capital letters.

    I believe your open and close curly braces do not match up. You have methods inside other methods which is not allowed in Java.

Similar Threads

  1. Errors In Java
    By SecTech in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 27th, 2013, 04:28 AM
  2. Replies: 3
    Last Post: April 27th, 2013, 07:19 AM
  3. Help with Snake Game Java Code: It's Impossible to Lose the Game
    By haruspex_icis in forum What's Wrong With My Code?
    Replies: 20
    Last Post: December 17th, 2012, 12:21 PM
  4. Couple compile errors for dice game
    By smithmar in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 8th, 2012, 01:16 PM
  5. Random Errors Occurring When Running Game in Eclipse
    By WhenThCome4Me in forum Java IDEs
    Replies: 22
    Last Post: September 1st, 2011, 06:29 AM