“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Instead of constants such as "left", "right", "up", "down"; you might want to consider an enum for directions.
You have specified that Pong extends JPanel. Is that correct? Is Pong a JPanel that other people might want to put components in? Or should this be a "has-a" relationship: Pong has a JPanel that it puts it's own components into, but nobody else gets to see.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
Stephan van Hulst wrote:- Separate your game logic from your graphical interface. Use a simple class to keep track of where all the stuff is. The only thing the JPanel should do is draw the stuff, nothing more.
- Don't let your panel implement any listeners. Make separate listener classes, or use anonymous classes.
- Instead of MouseListener, you can use MouseAdapter.
- Use meaningful field names. "pl" means nothing. In a few months, you will have forgotten what it stands for. The same is true for your other fields, to a lesser or greater extent.
- Why are you using protected access? Don't use protected, unless you have a *really* good reason to use it.
- Why are you using the Boolean class, instead of boolean primitives?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
john price wrote:Could you give an example of an enum?
john price wrote:Could you explain the last paragraph? I don't understand. I know what the "has-a" relationship but I don't get what you are saying.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
john price wrote:
Stephan van Hulst wrote:- Use meaningful field names. "pl" means nothing. In a few months, you will have forgotten what it stands for. The same is true for your other fields, to a lesser or greater extent.
pl means player length, etc. originally had comments for saying p = player etc...will add them back
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
john price wrote:If my things are private, then no one can use them outside of my Application. So it would be pointless to extend Pong.
Stephan van Hulst wrote:MouseListener is AWT as well. It doesn't matter. Swing and AWT play nice together. MouseAdapter is a class that implements MouseListener and MouseMotionListener with empty methods. This way, you won't have to implement them yourself, if you don't use them.
You should have a JPanel subclass that has a Pong field. Pong keeps track of the location of everything. Your JPanel subclass looks at the Pong to determine where it should draw things.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
john price wrote:So what do I need to do to fix it?
john price wrote:For Java GUI's, I have only used Swing. It is useful and works for me. Should I be using a canvas (AWT) or something else.
john price wrote:If my things are private, then no one can use them outside of my Application. So it would be pointless to extend Pong.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Andrew Monkhouse wrote:Perhaps we misunderstood. Your original request was for suggestions on how to make the code better. Were you looking for something other than what we are providing? Performance suggestions perhaps?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
Arcade : Alien Swarm
Board : Chess - Checkers - Connect 4 - Othello
John wrote:I want the ball to look like it's bouncing off of walls and paddles normally but be semi-random (not the same pattern every time; otherwise boring game because it's the same every time).
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Emmanuel F. Borges wrote:For example, the game Pong has one ball and two paddles, so you could create a Ball class and a Paddle class. This way, all the logic concerning these two entities would be encapsulated within their classes.
Don't get me started about those stupid light bulbs. |