Counting Scoreboard - How Many Times A Ball Hits Moving Platform In Pong

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


ADVERTISEMENT

Ball Class For Pong Won't Add To JPanel

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

How To Make Pong Ball Slowly Increase Speed

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

Ping Pong Game - Ball Drop And Catch

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

Add Color To Ball In Pong - Speed Up When Contact Made With Paddle

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

Counting How Many Times A Value Appears In Array

Nov 23, 2014

I have this code but I can't seem to get it to work. It keeps saying that "count" cat be found and that it cannot return a value whose type is void.

Java Code: public class Cuantos {
static int getPosition(double listOfValues[], double targetValue ) {
int i,count,
position = -1;
for (i=0; i < listOfValues.length; i++) {
if (listOfValues[i] == targetValue)

[code]....

View Replies View Related

Ball Object Which Implements Runnable Interface And Traces Various Positions Of A Ball

Feb 11, 2014

a) I have a Ball Object which implements the Runnable interface and traces the various positions of a ball.

b) I then have a Ball_Bounce JPanel inside a JFrame which creates two instances of the Ball object and then paints them to the JPanel.

As per my understanding, when the main() program in Ball_Bounce.java is started, there a total of three threads running in this program, one for each ball and one for the main(). What I cannot understand is whenever the balls collide, I end up getting the "Collision" message twice even though the collision is checked only in the main() thread.

[#]public class Ball implements Runnable
{
private boolean xUp, yUp, xUp1, yUp1;
private int x, y, xDx, yDy;
private final int MAX_X = 500, MAX_Y = 500;
private boolean flag = true;
private static Thread ball;
 
[code]...

View Replies View Related

Doesn't Rename File Even Though It Hits Code

Oct 21, 2014

I have two files - I can get the second one to populate with the first ones data and then delete the first one. I cannot get it to then rename itself to the name of the first file. It also only hits the 'rename' section of the code providing I place system.gc in otherwise it completely skips it.

the code I use is below:

Java Code:

finally{
try {
br.close();

// mp br.close();
//mp System.gc();

[code]...

View Replies View Related

How To Get Pacman To Horizontally Flip As It Hits Right Wall

Apr 9, 2014

I cannot get this crappy looking pacman to horizontally flip as he hits the right wall.

Here is my JFrame

package MyPacman;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

[Code] ....

I do not understand how I can alter my paintComponent. Is it possible to set my paintComponent to an Image variable, and then flip the image with Math.Radius?

View Replies View Related

Airplane Seat Reservations - Loop Until User Hits 0

Nov 11, 2014

I'm writing a classic airplane seating program. The program runs fine except for two things:

1) I want the user to exit the program when 0 is inputted (program also quits when all seats are reserved - this works fine already). Now the program quits when user hits blank line with enter. How to fix this and make 0 the exit key?

2) I would like for there to be a line below the seating chart saying that there are XX number of seats available. When user makes reservations, the line should update every time under the seating chart saying that there are such and such number of seats available. How to implement this?

import java.util.*;
public class OmaAirplane {
public static void main(String[] args) {
System.out.println("Welcome to the seat reservation system!");
char[][] seats = new char [8][6];
ArrayList<String> reservedSeats = new ArrayList<>();
for (int i=0;i<8;i++){

[code]....

View Replies View Related

Loop Airplane Seating Reservations Until All Seats Taken Or User Hits 0

Nov 11, 2014

I'm writing a classic airplane seating program. The program runs fine except for two things:

1) I want the user to exit the program when 0 is inputted (program also quits when all seats are reserved - this works fine already). Now the program quits when user hits blank line with enter. How to fix this and make 0 the exit key?

2) I would like for there to be a line below the seating chart saying that there are XX number of seats available. When user makes reservations, the line should update every time under the seating chart saying that there are such and such number of seats available. Any pointers on how to implement this?

import java.util.*;
public class OmaAirplane {
public static void main(String[] args) {
System.out.println("Welcome to the seat reservation system!");
char[][] seats = new char [8][6];
ArrayList<String> reservedSeats = new ArrayList<>();

[Code] .....

View Replies View Related

RMI With Doing Calculations Across A Server / Client Platform

Apr 6, 2014

It's an RMI program that has to be able to return the mean, mode and median of a set of numbers.It's composed of 4 classes; a client, an implementation class (with the math), an Interface, and a server class.

import java.rmi.NotBoundException;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.io.*;
 
[code]....

View Replies View Related

Pong Game Won't Update

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

Unable To Keep Platform Object Within Applet Window?

Jun 12, 2014

I created a simple java game in which i have to keep the ball up with a platform, similar to the game brick breaker. Everything works great. I am using keyListener to move the platform left and right. My only problems is that I am unable to keep the platform in bounds of the applet window. I know Its something to do with my logic in the update method of my Platform class but I'm stumped. Here are the 3 classes:

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

[Code].....

View Replies View Related

NoClassDefFoundError With Java Standard Platform Class?

Feb 18, 2015

I am facing NoClassDefFoundError with one of the java standard platform class (java.text.DigitList$1)

java.text.DigitList class is part of rt.jar so it should not create any issue as such.

I am using Java 1.6.0_06

StackTrace:
Unhandled exception java.lang.NoClassDefFoundError: java/text/DigitList$1
at java.text.DigitList.shouldRoundUp(DigitList.java:4 11)
at java.text.DigitList.round(DigitList.java:363)
at java.text.DigitList.set(DigitList.java:351)
at java.text.DigitList.set(DigitList.java:272)
at java.text.DecimalFormat.format(DecimalFormat.java: 584)
at java.text.DecimalFormat.format(DecimalFormat.java: 507)
at java.text.NumberFormat.format(NumberFormat.java:26 9)

View Replies View Related

JAVA Platform Game Jumping And Collision

Sep 16, 2014

i have problem in what comes to jumping because in what i have now mario jumps with the key lsitener, key pressed up arrow and it jumps smooth but when im trying to make it fall down he appears immediatly at ground and it doesnt simulate the fall as it should be.

import java.awt.BorderLayout;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;
import java.awt.EventQueue;

[code]....

The other problem is that i dont really know how to detect collisions if there is a method that makes easier this proceso and how to make the map to continue and repeat so mario could continue walking,

View Replies View Related

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 View Related

Simple Ping Pong Game

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

Difference Between Terms - Architecture Neutral And Platform Independent

Aug 12, 2014

I have just started learning Java from a local teacher, this teacher said that the Architecture Neutral refers to Hardware while Platform Independent refers to Operating System, but I found a link to a White Paper by James Gosling. The chapter 4 of this White Paper mentions about both binary code format that is independent of hardware architecture and operating system interfaces, but the main point to be noted is that he has put both under the heading Architecture Neutral. Does it mean that the original buzz word is Architecture Neutral, which includes both hardware and operating system independence?

View Replies View Related

Pong Game - Y Axis Collision Detection

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

Simple Pong Game - Touch Red Block

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

How To Display SWF Files In Java Code JEditorPane Using Eclipse Platform

Apr 28, 2014

Here attached my java code am trying to display .swf or .fla files from this code but am not able to retrieve .swf or .fla files.

View Replies View Related

Swing/AWT/SWT :: Printing JTable - Java (TM) Platform SE Binary Has Stopped Working

Nov 19, 2014

I am getting the following message when trying to print a JTable.

"Java(TM) platform SE binary has stopped working"

Here is the code:

try {
MessageFormat headerFormat = new MessageFormat("Page {0}");
MessageFormat footerFormat = new MessageFormat("- {0} -");
table.print(JTable.PrintMode.FIT_WIDTH, headerFormat, footerFormat);
} catch (java.awt.print.PrinterException pe) {
System.err.println("Error printing: " + pe.getMessage());
}

View Replies View Related

Buttons To Add And Remove 1 Ball

Apr 29, 2015

1. BALL

import javax.swing.Timer;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Ball extends JPanel {
private int delay = 10;
private Timer timer = new Timer(delay, new TimerListener());
private int x = 0; private int y = 0;

[Code] ...

View Replies View Related

Magic 8 Ball Code

Dec 5, 2014

I am writing a three part program that essentially works like a magic 8 ball. I have the switch/case part which gives the answers from a random number generator, then I also have a graphics file to create the ball as a visual. Lastly I have the frame to display the ball. The problem I am having is that, I am trying to make the program so that when you type in a question and press return the ball will show the answer and then you can type another question and press return and the ball will show a different answer. To quit you would simply type "quit". Right now however the ball is not showing up in my frame until I type quit, then to ask another question I have to end the run and start over again. Here is my program so far:

Case/Switch:
public class MagicEightBall
{
private int number;
private String answer;

[code]....

View Replies View Related

Ball Stopping At The Edge Of Maze

Mar 7, 2015

I am doing an assignment which involves creating a maze and a ball that needs to go through the maze to an end tile then stop the scenario. The maze is made up of 208 buttons in a Jbutton Grid layout. I am replacing certain buttons with a brown tile icon to make up the maze. The ball needs to run along those brown tiles as its path and not be able to move off the brown tile icon images.

I have built the maze and have got quite far with this but now I am stumped on the concept of keeping the ball within the boundary edges and on the brown tiles. I have been told to use if statements, but not had the process explained to me in a way I can understand.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved