Results 1 to 2 of 2
Thread: stackoverflow error
- 07-01-2012, 11:13 AM #1
Member
- Join Date
- Jul 2012
- Posts
- 1
- Rep Power
- 0
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
- 07-01-2012, 02:20 PM #2
Similar Threads
-
java.lang.NullpointerException error in tomcat 5.5 / http status 500 error
By rahil in forum Apache CommonsReplies: 3Last Post: 05-08-2012, 05:26 PM -
StackOverFlow Error
By ankiit in forum New To JavaReplies: 12Last Post: 01-12-2012, 03:30 PM -
StackOverFlow
By s0meb0dy in forum New To JavaReplies: 1Last Post: 02-17-2011, 06:50 AM -
StackOverflow Exception with Regexes
By masterrs.mind in forum Advanced JavaReplies: 6Last Post: 03-12-2010, 04:32 PM -
Thread: Error 500--Internal Server Error java.lang.NullPointerException
By jackdear44 in forum New To JavaReplies: 1Last Post: 12-05-2009, 07:28 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks