Pong Game - Overflow Error
Jun 4, 2014
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 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;
[Code] .....
Here's the error:
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)
The error keeps going for a lot of more lines.
The line that gets highlighted is the first bracket of the Pong constructor.
View Replies
ADVERTISEMENT
Apr 19, 2014
I'm a beginner at java and am trying to code a basic pong game java applet. The code has no errors in it but when i run it the .png's do not come up in the window until its moved off screen. when the .png's are shown they do not update whatsoever. I thought the problem could be with the key-listener but even the ball (which moves independently of user input) does not move.
I've placed all the code from the 5 classes below. There's some unnecessary code in the background class but that's because I'm thinking of making the background scroll later on.
package main;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.net.URL;
[Code] ....
View Replies
View Related
Oct 22, 2014
I am getting a stack overflow error for my method that recursively gets the height of an AVL tree. The odd thing is that it returns the height of the tree the first time I call that method, but when I call it again later on, I get that error, which I does not make any sense to me. I have a base case, where it is supposed to stop when the node is null, but it never reaches that. Also, when I print out the values, it alternates b/w three values: 5, 4, and 24. Something else, which I think is important to state, is that if I put the print statement before my base case, the IF, I get a warning stating that my entire IF statement is dead code...but why?
is that everytime I insert/delete a value into the AVL tree I must make sure that it is height balanced (none of the siblings may have a difference in height from each other > 1); if its not height then I rotate certain nodes accordingly. The first 10 items that I input are: 100, 50, 24, 200, 190, 10, 5, 190, 100 and 4. The pre and in order prints of these, from the console are:
PRE ORDER: 100 10 5 4 24 50 200 190 100 190
IN ORDER: 4 5 10 24 50 100 100 190 190 200 .
private int rheight(AVLNode<E> node) {
//if i put the print statement here, my IF becomes "dead code"
if(node == null){
return 0;
}
else{
[code]....
View Replies
View Related
Jul 14, 2014
When I ran the methods "go1,go2,go3" separately without clicking on the menu , all of them worked well. by separately I mean, when I closed the program changed the source code from "go1;" to "go2" and go3. But when I click on the "change ball" and then "1 ball" or any thing, all I get is a new frame which is blank. And the old frame freezes.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author Administrator
*/
[code]...
View Replies
View Related
Jun 14, 2014
I am getting a stack overflow error. I know there's something off about the code but I can't get it....
// The "SplashScreen" class.
import java.awt.*;
import javax.swing.*;
public class SplashScreen extends JWindow
{
ImageIcon book;
public SplashScreen ()
[Code] ......
View Replies
View Related
Jan 28, 2014
I have made a "Pong" game and how to check if the ball has hit the top or the bottom of a paddle, however I do know how to check if it has hit the left or right side:
Java Code:
if((BALL.getX() >= LEFT_BAT.getX() && BALL.getX() <= LEFT_BAT.getX() + LEFT_BAT.getWidth()
&& BALL.getY() >= LEFT_BAT.getY() && BALL.getY() <= LEFT_BAT.getY() + LEFT_BAT.getHeight())
&& (BALL.getX() >= RIGHT_BAT.getX() && BALL.getX() <= RIGHT_BAT.getX() + RIGHT_BAT.getWidth()
&& BALL.getY() >= RIGHT_BAT.getY() && BALL.getY() <= RIGHT_BAT.getY() + RIGHT_BAT.getHeight())){
BALL.increaseDX();
BALL.setDX(-BALL.getDX());
} mh_sh_highlight_all('java');
It seems as though I would use the same code for checking the top or bottom.
View Replies
View Related
Dec 27, 2014
I don't know how to write a code to pong ball, when it touch red block.
public class bounc2 extends JPanel implements ActionListener,KeyListener{
double x = 0,y=0,velX=3,velY=3;
double x2 = 5,y2=145,velX2=0,velY2=0;
double x3= 473,y3=145,velX3=0,velY3=0;
Timer t = new Timer(5,this);
public bounc2(){
setBackground(Color.GREEN);
[Code] .....
View Replies
View Related
Jan 19, 2014
I have an error using quicksort and this is a project ... The error occurs for numbers such as 7500 and bigger ...
Exception in thread "main" java.lang.StackOverflowError
at QuickSort.QuickSort(QuickSort.java:45)
at QuickSort.QuickSort(QuickSort.java:46)
at QuickSort.QuickSort(QuickSort.java:46) ...
Java Code:
import javax.swing.JOptionPane;
public class QuickSort{
public static void main(String[] args){
int p=new Integer(JOptionPane.showInputDialog("Jepni numrin e kufizave: "));
int[] ListaNumrave= new int[p];
//QuickSort Zbrites
[Code] .....
View Replies
View Related
Feb 26, 2014
I have created this ping pong game but having problem with ball and paddle collusion. After first collusion it gives score 1 but later it never touch the paddle.
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.Random.*;
import javax.swing.ImageIcon;
public class Ball extends JFrame implements ActionListener, KeyListener{
int xSpeed=0;
[Code] ....
I think something is wrong here:
public void actionPerformed(ActionEvent e){
y=y+xSpeed;
repaint();
if(y> this.getWidth()){
y=25;
score -=1;
}
if(blockRect.intersects(ballRect)){
y=40;
score +=1;
x =200;
y = 300;
}
View Replies
View Related
Oct 15, 2014
I have wriiten a quick sort algorithm. I have used the last element as my pivot. The program is running for all sizes except for 100000 and 1000000 elements when they are sorted and unsorted list .
It shows me the error : Exception in thread "main" java.lang.StackOverflowError
I guess the memory gets out of space and we need to increase the stack size in eclipse. How do I increase the stack size in eclipse.? I tried increasing through run--run configurations-- program arguments and typed---- -Xmx4096m but this didn't work in any way.
View Replies
View Related
Jun 22, 2014
In the following program i have called the anonymous class of dev class.
interface emp {
void desig();
}
public class dev implements emp {
dev e = new dev() //this line is throwing error ...works fine if i use emp instead of dev {
[Code] .....
i am getting stack over flow error as :
Exception in thread "main" java.lang.StackOverflowError
at dev$1.<init>(dev.java:17)
at dev.<init>(dev.java:16)
at dev$1.<init>(dev.java:17)
[Code] .....
Is it because the jvm is not able to decide which of the 2 desigs() it has to load in the memory when its object is created in the main..??
View Replies
View Related
Jun 8, 2014
I'm trying to make a simple battleship game, but when I make a ship with the addShip method (it is suppoused to initialize the board with the numbers 1,2,3 or 4 depending on the ship type, at the given coordinates) it dosen't initialize the field with any numbers, although the method returns true. The place the ship is suppoused to be made stays initialized with ".",
package battleship;
public class Sea {
private int width;
private int height;
private String[][] field;
[code].....
View Replies
View Related
May 8, 2014
So I am creating a game in Java, the game works fine when I run it in Eclipse but when I export it it does not draw anything on the screen.
I added a try and catch for nullpointerexceptions but the game does not throw any nullpointerexceptions.
What is the problem?
The game seems to be finding all the images & resources since it does not throw any NullPointerExceptions...
View Replies
View Related
Jan 2, 2015
I'm trying to fix this logic error in my slot machine game where no matter what slot combo comes up, it says you have won $10 and proceeds to add that amount to the balance and subtract the bet amount to the balance, even though it is not a winning combo! I've been trying to solve that and when doing so, I commented out Slot1.randNum1 == 0, Slot2.randNum2 ==0, and Slot3.randNum3 ==0 and anything relating to see if that was the problem, and it seemed like it was, because after that, the logic error described above was gone, but in doing so, the loss/win counter didn't increment, nor did the program pick up on the winning combos. However, I do not know why commenting out anything relating to randNum ==0 would cause that.
Here is the code for the processing (as you can see, some parts are commented in attempt to fix the logic error, but right now the code below is for the logic error that keeps on telling that the user has won):
public void askData ()
{
title ();
int betAmount;
while (true)
{
try
{
c.setCursor (3, 1);
[code]....
View Replies
View Related
Dec 11, 2014
import java.util.Scanner;
import java.util.Arrays;
public class LotteryTester {
public static void main(String[] args) {
LotteryApplication lottery = new LotteryApplication();
int lotteryNumbersCount = lottery.getLotteryNumbers().length;
[Code] ....
Everything works fine but when I run it the matching numbers tends to be off. For example I will type Enter in 1,1,1,1,1 for my 5 numbers. The lottery numbers will be 5,3,4,5,8 and it will say 1 number matched.
View Replies
View Related
Nov 29, 2014
I'm having some difficulty getting this GUI dice game to compile. I'm using javac and notepad++ for this and I'm getting the following errors:
DiceGame.java:34: error: cannot find symbol
die2label = new JLabel();
^
symbol: variable die2label
location: class DiceGame
[Code] ....
4 errors
My code is as follows:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
public class DiceGame extends JFrame
[Code] ....
I'm sure the problem is something trivial, but I guess that's all part of the learning process that I have to go through.
View Replies
View Related
Apr 23, 2015
I wrote a program that would play a game of Hangman. It plays the game but it keeps on bringing up a exception error. This is my class code
import java.util.ArrayList;
class Assignment2Q4
{
private final ArrayList<Character> guessList = new ArrayList<>();
private final char[] charArray;
private final String secretWord;
private int guesses;
[Code] ....
This is the output that is given:
Enter the secret word:
pizza
Guess a letter:
d
?????
Guess a letter:
[Code] .....
Also when I guess the first letter of the word correctly it stops the program without going further on with the guessing.
Like for ex. P????
View Replies
View Related
Jul 28, 2014
I am trying to make a game of pong and am having trouble adding my ball class to a JPanel. Here is what I have so far.
package pong;
import java.awt.*;
public class Ball{
private int xPos,yPos;
public int dx = 5, dy = -5;
public Ball()
[code].....
I want to be able to add this to a JPanel but it is not allowing me to add the ball. Here is my JPanel
package pong;
import java.awt.*;
import javax.swing.JPanel;
public class BallTestPanel
[Code] ....
It reads panel.add(ball); as an error. I says that I need to change the type ball to component.
View Replies
View Related
Apr 11, 2013
I was making a pong game, part copied code off the internet, part my own code, part my friends code. It works well enough, but the ball starts at one speed, and stays the same. I would like to know how to make the ball slowly increase.
It is a java applet, which shouldn't casue any harm right?
My code:
Pong Applet
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Pong extends Applet implements MouseMotionListener, KeyListener {
[Code] .....
View Replies
View Related
Apr 23, 2014
I wrote a code from our text book for Pong. Im trying to figure out how to fill the ball with color. Im also wondering how to speed the ball up once there is contact with the paddle. The initial speed is ok but once contact is made with the paddle, it slows down. Makes it too easy to play. Here is my code so far. As far as the game goes, it works and is good. Just wanted to add a couple customizations.
Java Code:
package pong;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
[Code] .....
View Replies
View Related
May 9, 2014
I need to make a scoreboard that can count how many times a ball hits a moving platform in pong and have no clue how to approach this.
View Replies
View Related
Mar 12, 2015
Opoly works this way: The board is a circular track of variable length (the user determines the length when the game app runs). There is only one player, who begins the game at position 0.
Thus, if the board length is 20, then the board locations start at position 0 and end at position 19. The player starts with a reward of 100, and the goal of the game is to reach or exceed reward value 1000. When this reward value is reached or exceeded, the game is over. When the game ends, your program should report the number of turns the player has taken, and the final reward amount attained.
In Opoly the game piece advances via a spinner - a device that takes on one of the values 1, 2, 3, 4, 5 at random, with each of the five spin values equally likely.
Although the board is circular, you should draw the state of the board as a single "line", using an 'o' to represent the current player position, and * represent all other positions. Thus if the board size is 10, then this board drawing:
**o******
means that the player is at location 2 on the board.
Here are the other Opoly game rules:
If your board piece lands on a board cell that is evenly divisible by 7, your reward doubles.
If you land on the final board cell, you must go back 3 spaces. Thus if the board size is 20, the last position is position 19, and if you land there, you should go back to position 16. (If the position of the last cell is evenly divisible by 7, no extra points are added, but if the new piece location, 3 places back, IS evenly divisible by 7, then extra points ARE added).
If you make it all the way around the board, you get 100 points. Note that if you land exactly on location 0, you first receive 100 extra points (for making it all the around), and then your score is doubled, since 0 is evenly divisible by 7,
Every tenth move (that is, every tenth spin of the spinner, move numbers 10,20,30,... etc.), reduces the reward by 50 points. This penalty is applied up front, as soon as the 10th or 20th or 30th move is made, even if other actions at that instant also apply. Notice that with this rule it's possible for the reward amount to become negative.
Here is the driver class for the game:
import java.util.*;
public class OpolyDriver{
public static void main(String[] args){
System.out.println("Enter an int > 3 - the size of the board");
Scanner s = new Scanner(System.in);
int boardSize = s.nextInt();
[Code] ....
heres the methods:
REQUIRED CODE STRUCTURE: Your Opoly class must include the following methods (in addition to the Opoly constructor) and must implement the method calls as specified:
playGame - The top-level method that controls the game. No return value, no parameters. Must call drawBoard, displayReport, spinAndMove, isGameOver.
spinAndMove - spins the spinner and then advances the piece according to the rules of the game. No return value, no parameters. Must call spin and move.
spin - generates an integer value from 1 to 5 at random- all equally likely. Returns an integer, no parameters.
move - advances the piece according to the rules of the game. No return value, takes an integer parameter that is a value from 1 to 5.
isGameOver - checks if game termination condition has been met. Returns true if game is over, false otherwise. No parameters.
drawBoard - draws the board using *'s and an o to mark the current board position. Following each board display you should also report the current reward. No return value, no parameters.
displayReport - reports the end of the game, and gives the number of rounds of play, and the final reward. No return value, no parameters.
View Replies
View Related
May 9, 2015
Im trying to make a tic tac toe game that you play against the computer using a random number generator and two dimensional arrays for the game board. Im not trying to make a GUI, the assignment is to have the board in the console, which I have done. I have run into a few problems with trying to get the computer player to correctly generate 2 integers and have those two integers be a place on the game board. Here is my code so far.
import java.util.Random;
import java.util.Scanner;
public class TicTacToe {
private static Scanner keyboard = new Scanner(System.in);
private static char[][] board = new char[3][3];
public static int row, col;
[Code] ....
View Replies
View Related
Oct 2, 2014
I tried this program, its guessing game. Where program decide 1 number and user will guess number. I am getting 1 problem. When user want to play game again.the random number remain same. So where i can put reset random in code..? And 1 more question if I want to write driver code for this. What should i transfer to driver code.
import java.util.Random;
import java.util.Scanner;
public class GuessGame {
public static void main(String args[])
{
String choice="y";
[Code] ......
View Replies
View Related
May 22, 2014
For my jsp file, the code editor shows no error, but the projects window shows an error. I built my project again, cleaned the project, restart eclipse twice and summoned cthulhu. But my project still shows an error. How do I find the cause.
Eclipse project -
JSP file -
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="mine" uri="DiceFunctions"%>
[Code] ....
View Replies
View Related
Apr 5, 2014
I have written some error checking code
File name ErrorPage.jsp
<%@ page language="java" isErrorPage="true" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Error</title>
</head>
[code]...
I have put error.jsp and badpage.jsp file in public access folder that is web content in eclipsewhen I am running the code I am status code of 500 and not the errorpage.jsp message .
View Replies
View Related