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 12 of 12

Thread: Fixing of bug for Pong game

  1. #1
    Junior Member
    Join Date
    Jul 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Fixing of bug for Pong game

    Hello everyone,
    I am new to this forum. I hope, i will contribute more as time passes.
    I attached the program below. Everything seems fine but the program doesn't start working.
    Any kind of contribution would be appreciated.
    Thanks in advance.
    Attached Files Attached Files
    Last edited by Deep_4; November 8th, 2012 at 01:20 PM.


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: The bug in the Pong game

    Hello phoenix. Welcome to the Java Programming Forums.

    How are you attempting to run this?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Junior Member
    Join Date
    Jul 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: The bug in the Pong game

    I build classes, then run pong.java and it doesnt show the frame.However, when you change 49.line to false in Pong class,
    it shows the frame but doesnt run.

  4. #4
    Junior Member
    Join Date
    Jul 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: The bug in the Pong game

    Isn't there anyone who can help me? It is kind of urgent.

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: The bug in the Pong game

    Quote Originally Posted by phoenix View Post
    I build classes, then run pong.java and it doesnt show the frame.However, when you change 49.line to false in Pong class,
    it shows the frame but doesnt run.
    OK yes i'm having the same problem. I'll have a play with it shortly and see if I can make it do something!
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  6. #6
    Junior Member
    Join Date
    Jul 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: The bug in the Pong game

    Thank you for your attention

  7. #7
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: The bug in the Pong game

    Hmm I'm having trouble getting this to run properly..
    I will continue to look at it but seeing as your in a rush, i'll let you know now that I don't have much time.

    If you need to see a working pong game, try these links:

    A Pong Game by Dino Scarcella

    Java Pong Game

    I have compiled the second one before and know it works.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  8. The Following User Says Thank You to JavaPF For This Useful Post:

    phoenix (July 14th, 2009)

  9. #8
    Junior Member
    Join Date
    Jul 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: The bug in the Pong game

    You are a lifesaver. Thank you billion times.

  10. #9
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: The bug in the Pong game

    You still need to get the original game you posted working?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  11. #10
    Junior Member
    Join Date
    Jul 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: The bug in the Pong game

    Unfortunately, yes.

  12. #11
    Junior Member
    Join Date
    Jul 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: The bug in the Pong game

    A man from another forum solved the problem.
    Here it is;
    "I moved the code in the main() method to the frame's constructor. It works now. Also, when extending components, be sure to call the super() constructor."
    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
     
    public class Pong extends JFrame implements Runnable
    {
    	//Variables
    	Thread pongThread; //Will be used to turn this runnable object into a working thread
    	PongArena arena = new PongArena(400, 600); //Make a pong arena
     
    	//Constructors
    	public Pong()
    	{
    		super();
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Tell it to close the program when the frame closes
    		//Setup the layout and how things will be displayed...
    		Container content = this.getContentPane();
    		content.setLayout(new BorderLayout());
    		content.add(arena, BorderLayout.CENTER);
    		this.setTitle("Pong - By: Chris Canik");
    		this.setResizable(false);
     
    		//This tells the JFrame that it should resize according
    		//to the component's (PongArena) prefered size
    		this.pack();
     
    		//The boundaries must be created here because getX and getY have no
    		//accurate values when the arena's constructor is originally called
    		arena.side1 = new PongArenaBoundary((int)(arena.getX() - 500),
    											(int)(arena.getY() + arena.topPaddle.getHeight() + 30),
    											(int)(500),
    											(int)(arena.getBounds().getHeight() - arena.topPaddle.getHeight() - arena.bottomPaddle.getHeight() - 60));
    		arena.side2 = new PongArenaBoundary((int)(arena.getX() + arena.getBounds().getWidth()),
    											(int)(arena.getY() + arena.topPaddle.getHeight() + 30),
    											(int)(arena.getX() + arena.getBounds().getWidth() + 500),
    											(int)(arena.getBounds().getHeight() - arena.topPaddle.getHeight() - arena.bottomPaddle.getHeight() - 60));
     
    		//Give the arena focus within the JPanel
    		arena.requestFocus();
     
    		setVisible(true); //Show the frame to the player
     
    		//Turn this Runnable JPanel into an actual thread
    		pongThread = new Thread(this);
    		pongThread.start();
    	}
     
    	//Methods
    	public void run()
    	{
    		boolean keepGoing = true; //Tracks whether there has not been an error
     
    		while (keepGoing)
    		{
    			try
    			{
    				//Find out what the ball needs to bounce off of and do it
    				arena.ball.bounce(arena.ball.needToBounce(arena));
     
    			}
    			catch (BallOffCourtException ex) //Point has been scored
    			{
    				//Make a new ball for a new round, and register it to
    				//the two AI's so they don't try to follow the old one
    				arena.topAI.registerBall(arena.newBall((arena.getWidth() / 2) - 10, (arena.getHeight() / 2) - 10, 20, 20));
    				arena.bottomAI.registerBall(arena.ball);
     
    			}
     
    			//Display FPS in JPanel title
    			this.setTitle("Pong (FPS: " + arena.fps.getFrames() + ") - By: Chris Canik");
     
    			try
    			{
    				//Redraw everything and wait a bit as math is handled
    				repaint();
    				Thread.sleep(10); //(1000/10) = 100FPS
    			}
    			catch (InterruptedException ex)
    			{
    				//Error...  Time to stop running!
    				System.out.println("Interrupted!");
    				keepGoing = false;
    			}
    	}
    	}
     
    	//Main Method
    	public static void main(String[] args)
    	{
    		Pong pongGame = new Pong(); //Lets make a game frame
    	}
     
    }

  13. #12
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: The bug in the Pong game

    Brilliant! Glad it was solved for you phoenix. Thanks for posting the solution.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Programmer for a Java based game project
    By Takkun in forum Project Collaboration
    Replies: 4
    Last Post: June 14th, 2010, 05:47 PM
  2. Job offers to program Hobo Wars
    By MooncakeZ in forum Paid Java Projects
    Replies: 7
    Last Post: September 17th, 2009, 09:41 PM
  3. [SOLVED] How to start writing java mobile application?
    By Koâk in forum Java ME (Mobile Edition)
    Replies: 15
    Last Post: July 30th, 2009, 01:52 AM
  4. Problem while programming a simple game of Car moving on a road
    By rojroj in forum Java Theory & Questions
    Replies: 3
    Last Post: April 2nd, 2009, 10:24 AM
  5. Replies: 1
    Last Post: March 28th, 2009, 07:21 AM

Tags for this Thread