I can't figure out this problem that I'm having in my Pong game. It's compiling fine, except when I run it, it gives me an overflow error.
Here's my code: PONG IN JAVA (CLASS/HOME) - Pastebin.com
I learned a bit in my school (about Graphics) that's helped me and over the internet but other then that, I'm doing this by myself.
Here's the code:
// Pong import javax.swing.JFrame; import java.awt.Color; import java.awt.Graphics; public class Pong extends JFrame { private static final int WIDTH = 400; private static final int HEIGHT = 400; Ball b = new Ball(); Paddle p1 = new Paddle(); Paddle p2 = new Paddle(); protected int x; protected int y; public Pong() { b.setSize(30, 30); b.setColor(Color.BLUE); b.setX(20); b.setY(20); p1.setSize(40, 40); p1.setColor(Color.RED); p1.setX(50); p1.setY(50); p2.setSize(40, 40); p2.setColor(Color.RED); p2.setX(100); p2.setY(100); add(b); add(p1); add(p2); getContentPane().repaint(); } public void paint(Graphics g) { } public void setColor(Color c) { } public boolean collides(boolean a) { return a; } public void setSize(int width, int height) { } /*public void setX(int i) { x = i; } public void setY(int i) { y = i; } public int getX() { return x; } public int getY() { return y; }*/ public static void main(String args[]) { Pong frame = new Pong(); frame.setSize(WIDTH, HEIGHT); frame.setTitle("Pong"); frame.setResizable(false); frame.setVisible(true); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }// Ball import java.awt.Color; import java.awt.Graphics; public class Ball extends Pong { public Ball() { /* b.setSize(30, 30); b.setColor(Color.BLUE); b.setX(20); b.setY(20); */ } public void paint(Graphics g) { } public void setColor(Color c) { } public void setSize(int width, int height) { } public void setX(int i) { x = i; } public void setY(int i) { y = i; } public int getX() { return x; } public int getY() { return y; } }Here's the error:// Paddle import java.awt.Color; import java.awt.Graphics; import java.awt.event.*; public class Paddle extends Pong implements KeyListener { public Paddle() { /* p1.setColor(Color.RED); p1.setX(50); p1.setY(50); p2.setSize(40, 40); p2.setColor(Color.RED); p2.setX(100); p2.setY(100); */ } public void paint(Graphics g) { } public void setColor(Color c) { } public void setSize(int width, int height) { } public void setX(int i) { x = i; } public void setY(int i) { y = i; } public int getX() { return x; } public int getY() { return y; } public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } }
java.lang.StackOverflowError
at sun.awt.AppContext.get(AppContext.java:604)
at com.sun.java.swing.SwingUtilities3.getDelegateRepa intManager(SwingUtilities3.java:120)
at javax.swing.RepaintManager.getDelegate(RepaintMana ger.java:1625)
at javax.swing.RepaintManager.addDirtyRegion(RepaintM anager.java:445)
at javax.swing.JComponent.repaint(JComponent.java:479 5)
at java.awt.Component.repaint(Component.java:3286)
at javax.swing.JComponent.setBackground(JComponent.ja va:2733)
at javax.swing.LookAndFeel.installColors(LookAndFeel. java:175)
at javax.swing.LookAndFeel.installColorsAndFont(LookA ndFeel.java:211)
at javax.swing.plaf.basic.BasicPanelUI.installDefault s(BasicPanelUI.java:66)
at javax.swing.plaf.basic.BasicPanelUI.installUI(Basi cPanelUI.java:56)
at javax.swing.JComponent.setUI(JComponent.java:664)
at javax.swing.JPanel.setUI(JPanel.java:153)
at javax.swing.JPanel.updateUI(JPanel.java:126)
at javax.swing.JPanel.<init>(JPanel.java:86)
at javax.swing.JPanel.<init>(JPanel.java:109)
at javax.swing.JPanel.<init>(JPanel.java:117)
at javax.swing.JRootPane.createGlassPane(JRootPane.ja va:545)
at javax.swing.JRootPane.<init>(JRootPane.java:365)
at javax.swing.JFrame.createRootPane(JFrame.java:277)
at javax.swing.JFrame.frameInit(JFrame.java:258)
at javax.swing.JFrame.<init>(JFrame.java:181)
at Pong.<init>(Pong.java:19)
at Ball.<init>(Ball.java:7)
at Pong.<init>(Pong.java:10)
at Ball.<init>(Ball.java:7)
at Pong.<init>(Pong.java:10)
at Ball.<init>(Ball.java:7)
at Pong.<init>(Pong.java:10)
at Ball.<init>(Ball.java:7)
at Pong.<init>(Pong.java:10)
at Ball.<init>(Ball.java:7)
at Pong.<init>(Pong.java:10)
at Ball.<init>(Ball.java:7)
at Pong.<init>(Pong.java:10)
at Ball.<init>(Ball.java:7)
at Pong.<init>(Pong.java:10)
at Ball.<init>(Ball.java:7)
at Pong.<init>(Pong.java:10)
------------------------------------------------------------------------------------------------------------
The error keeps going for a lot of more lines.
The line that gets highlighted is the first bracket of the Pong constructor.