Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2012
    Posts
    1
    Rep Power
    0

    Default stackoverflow error

    i am sending you the code. plz tell me why its giving stackoverflow error. Its a game sort of a thing which i am not able to rectify as to where it contains recursive calls. plzzz help me soon. i have to submit my project soon. the code consists of three classes in a package animation.
    package animation;
    Java Code:
    import javax.swing.*;
    
    public class Frame {
    
    	public Frame(){
    		JFrame frame = new JFrame();
    		frame.add(new Board());
    		frame.setTitle("2-D Test Game");
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setSize(700,365);
    		frame.setVisible(true);
    		frame.setLocationRelativeTo(null);
    	}
            
    	public static void main(String[] args){
    		new Frame();
    	}
    }
    
    package animation;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class Board extends JPanel implements ActionListener {
    	Dude p;
    	 Image img;
    	public Timer time;                     
            
            
    
    	public Board() {
    		p = new Dude();
    		addKeyListener(new AL());
    		setFocusable(true);
    		ImageIcon i = new ImageIcon("E:/db/mario/test/animation/testp.jpg");
    		img = i.getImage();
    		time = new Timer(5, this);
                    time.start();
    		
    	}
    
    	public void actionPerformed(ActionEvent e) {
    		p.move();
    		repaint();
    	}
    
    	public void paint(Graphics g) {
    		super.paint(g);
    		Graphics2D g2d = (Graphics2D) g;
    
    		g2d.drawImage(img, 0, 0, null);
    		g2d.drawImage(p.getImage1(), p.getX(), p.getY(), null);
    	}
    
    	private class AL extends KeyAdapter {
    		public void keyReleased(KeyEvent e) {
    			p.keyReleased(e);
    		}
    
    		public void keyPressed(KeyEvent e) {
    			p.keyPressed(e);
    		}
                    
    	}
    }
    
    package animation;
    import java.awt.*;
    //import java.awt.event.KeyEvent;
    import javax.swing.*;
    import javax.swing.ImageIcon;
    //import javax.swing.Icon;
    import java.awt.event.*;
    
    public class Dude extends JPanel implements ActionListener {
    	int x, dx=0,y;
            public Timer time1;
    	Image still,img1;
            ImageIcon i1,j;
           
            
            Board b=new Board();
            
    
    	public Dude() {
                   
    		 i1 = new ImageIcon("E:/db/mario/test/animation/dog_side_fc.PNG");
                    
                            
                        j = new ImageIcon("E:/db/mario/test/animation/testp.jpg");
                       
                    
    		    still = i1.getImage();
                        img1=j.getImage();
                        
                        time1 =new Timer(5,this);
    		    x = 10;
    		    y = 172;
                  
                   
                   
    	}
            public void actionPerformed(ActionEvent e)
            {
                repaint();
            }
            public void paint(Graphics g)
            {
               super.paint(g);
    		Graphics2D g2d = (Graphics2D) g;
    
    		g2d.drawImage(img1, 0, 0, null);
                                    
    		g2d.drawImage(still, x, y, null); 
            }
            
    
    	public void move() {
    		x = x + dx;
    	}
    
    	public int getX() {
    		return x;
    	}
    
    	public int getY() {
    		return y;
    	}
    
    	public Image getImage1() {
    		return still;
    	}
    
    	public void keyPressed(KeyEvent e) {
    		int key = e.getKeyCode();
    		if (key == KeyEvent.VK_LEFT)
    			dx = -1;
    
    		if (key == KeyEvent.VK_RIGHT)
    			dx = 1;
                    if(key==KeyEvent.VK_A)
                    {
                        b.time.stop();
                        time1.start();
                    }
                    if(key==KeyEvent.VK_1)
                    {
                        b.time.stop();
                        time1.stop();
                    }
    	}
    
    	public void keyReleased(KeyEvent e) {
    		int key = e.getKeyCode();
    
    		if (key == KeyEvent.VK_LEFT)
    			dx = 0;
    
    		if (key == KeyEvent.VK_RIGHT)
    			dx = 0;
                    if(key == KeyEvent.VK_A)
                    {
                         time1.stop();
                         b.time.start();
                       
                    }
    	}
            
    }
    Last edited by Norm; 07-01-2012 at 02:20 PM. Reason: added code tags

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default Re: stackoverflow error

    Please post the text of the error message that shows where the error is occurring. Post enough of it to show the locations.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 3
    Last Post: 05-08-2012, 05:26 PM
  2. StackOverFlow Error
    By ankiit in forum New To Java
    Replies: 12
    Last Post: 01-12-2012, 03:30 PM
  3. StackOverFlow
    By s0meb0dy in forum New To Java
    Replies: 1
    Last Post: 02-17-2011, 06:50 AM
  4. StackOverflow Exception with Regexes
    By masterrs.mind in forum Advanced Java
    Replies: 6
    Last Post: 03-12-2010, 04:32 PM
  5. Replies: 1
    Last Post: 12-05-2009, 07:28 AM

Posting Permissions

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