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


ADVERTISEMENT

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

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

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

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

Change Type / Custom Color Of Rectangle Made Through DragMode

Jun 9, 2014

What I'm trying to do is basically draw a Rectangle outline through left-click and then dragging the mouse to the size one wants.

After one has created this rectangle, the user can change the color of the rectangle through clicking the 3 sliders found on the top in the program. Upon the change in color, the rectangle should change from "g.drawRect" to "g.fillRect" and use the desired color.

I have the basic outline of the program done, but working with the last part (the color and changing of the Rectangle type after changing the color)

Is there like a "then" command in Java? Like: after you've done x, do y. That would make this heaps easier.

import java.awt.event.*;
import java.awt.*;
import java.applet.*;
 
//Diese Applikation offnet ein Fenster,
//in welchem durch einen gehaltenen linken Mouse Klick
//ein Reckteck gezeichnet wird
 
public class WhatIsTheProblem006 extends Applet
implements AdjustmentListener {

[Code] ....

View Replies View Related

Random Color Ball And Move Bottom Bar Vector?

Feb 20, 2014

I created this simple vector java program where ball falling and when collide with the bar below, the ball stops.

I need to make the ball falling randomly from different direction and also need to make the bar move left right using keyboard arrow.

Code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
 //using timer to increase the counter

[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

JavaFX 2.0 :: Setting Background Color For Layout - Fill / Color On OS X

Jun 10, 2014

No problem setting background color for layouts, e.g. bdrPn.setBackground(new Background((new BackgroundFill(Color.BLACK, CornerRadii.EMPTY, Insets.EMPTY))));
 
But neither of the following are working for me, running JavaFX 8 on latest OS-X
 
scene = new Scene(bdrPn, winW, winH, Color.BLACK);
scene.setFill(Color.BLACK); 
scene.setFill() worked fine for previous versions of JavaFX.

View Replies View Related

Can't Get Background Color To Change From Basic Gray Color

Oct 20, 2014

I've just started working on a program and i'm already having difficulties with the program. I can't get the background color to change from the basic gray color. Maybe you can tell me what i'm doing wrong.

import javax.swing.JFrame;
import javax.swing.WindowConstants;
import java.awt.*;
import java.lang.Object;
import java.awt.Color;
public class FrameDemo{
public static void main(String args[]){
Toolkit toolkit = Toolkit.getDefaultToolkit ();

[Code]...

also if theres any way to shorten up what I have there, that would be great.

View Replies View Related

Contact List - Showing Different Details

Sep 27, 2014

I have this Contact List program and im stuck on how to make my contact list show their different details. I don't know what to do , I want my program to be like this. What should I do next to make my every entry have different information then show on to the right side of the panel the information when i click the show details button .

package phonebook;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;

[Code] ....

View Replies View Related

Contact Information - How To Utilize Objects

Jun 14, 2014

I'm trying to create contact information as object and another object as parcel then calculate the shipping fee. Problem is I don't have a good understanding in implementing object type to my code. Attached are what I've done and I know that my constructor in my parcel class and contact class are probably wrong too but I don't know what to do with it.

//contact class
public class Contact {
private String Name;
private String Address;
private String City;
private String State;
private double Xco;
private double Yco;

[Code] .....

View Replies View Related

Working On A Contact List Program With A GUI

Nov 27, 2014

I am working on a contact list program with a GUI for a school project.I'm running into all kinds of issues when trying to update the JList in my GUI which displays the contacts.I think my issues are being caused by a lack of synchronization between the contact list that stores the data, and the contact list that is being displayed.I've tried all kinds of getters and setters, passing array indexes, passing array member objects etc.

General rundown of how I want the GUI/Code to work: When I select an object in the JLIst, the fields on the right should display that objects information.When the "Add Contact" button is created, a new blank contact should be created and added to the Contact List, and then displayed in the JList.When a field on the right side of the GUI is updated, the object in the contact list is updated simultaneously (using document listener), and therefore the JList would also be updated.

View Replies View Related

ArrayList - Contact Information / Address Book

Jul 5, 2014

I have a question about arraylist objects.... I want to create an address book that will contain a persons information (name, phone, address, email..etc..). The first two snippets of code are from the same class ContactArrayList and the last one is from the class Contact. Do I need to create a separate arraylist for each data type? Is it possible to use a single arraylist to contain all the object (person) information and then be searched for using a GUI? I would also like to be able to access this data to be manipulated using a JFrame (add, edit, and search).

public class ContactArrayList<E> implements List<E> {
public int size, capacity;
E contact;
private E[] contacts;
public ContactArrayList() {
size = 0;
capacity = 20;

[Code] ....

View Replies View Related

GUI Phonebook - Getting A Button To Work For Deleting Contact?

Apr 24, 2014

I'm working on a GUI Phonebook and need getting a button to work for deleting a contact. I identified the error I get in the Gui class where it says applyDeleteEntry(); on line 106 with comments. The entries are stored in a .txt file which is created for you.

Main class:

import javax.swing.*;
import java.awt.*;
public class Main{
public static void main(String args[]) throws Exception{
Phonebook mainPhonebook = new Phonebook();
Gui mainGui = new Gui();

[Code] .....

View Replies View Related

Input String Color Name And Set It To Color Object

Nov 24, 2009

If I want to read from file the word "red" And then the following is not the right way like in the code ,, How to set the Color name

File inputFile = new File ("C:\input.txt");
Scanner scan = new Scanner (inputFile);
String RedColor=scan.nextLine();
Color backColor = new Color(redColor);

View Replies View Related

Choose Option To Get Contact Details - Not Getting Output Expected

Feb 20, 2015

When I run my program and choose option 2 to get contact details I am expecting it to display as follows (First Name, Last Name): Contacts how have been entered:

0) John Doe
1) George Smith
2) Nancy Davis

Please enter the number corresponding to the contact you would like to view:

Instead for a personal contact it is displaying as follows:Contacts who have been entered:

0) Doe 1 F St. (last name, address)

Please enter the number corresponding to the contact you would like to view:

Instead for a business contact it is displaying as follows:Contacts who have been entered:

0) 1 F St. jd@gmail.com (address, email)

Please enter the number corresponding to the contact you would like to view:

Then when I enter the number to display the contact for personal it is returning me only first name and business is only returning me first and last name. It should be returning the full contact info that was put in during the add contact step. I thought I programmed everything properly but it isn't displaying what I want to seeMy code is listed below.

ContactList

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package contactlist;
import java.util.ArrayList;
import java.util.Scanner;

[code]....

View Replies View Related

How Recursion Calls Are Made

Jun 5, 2014

How the recursion works. I tried to figure out writing down low, mid, high at each recursive call. But I seem to be making a mistake somehow. I don't understand where the values are returned to in

if(leftmax>rightmax){
return leftmax;}
else
return rightmax;

Here's the code:

public class Maximum{
public static int max(int[] a,int low,int high){
int mid,leftmax,rightmax;
if(low==high)
return a[low];

[Code] ....

firstly leftmax=max(a,0,4)

Then what is the next line executed?Is it rightmax=max(a,5,8).

After this is it leftmax=max(a,5,6)

rightmax=max(a,7,8)

I tried to understand what these recursion calls by writing them down.But I somehow make a mistake.

View Replies View Related

Referring To Object That Has Not Yet Been Made?

Apr 16, 2015

I am trying to make a for loop using an iterator that refers to an object of a class that hasnt been made yet. The class is called MyArrayList but it does not have a Main. A MyArrayList object is made externally so I am unsure how to refer it to the object from within the class. Is there a place holder I could use such as Object.Iterator() or something similar. I have created an inner class that implements the Iterator interface. Here is the code that I need to adjust to do this:

public class ListIterator<E> implements Iterator<E> {
public myIterator() {
Iterator it = MyArrayList.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
}
}

View Replies View Related

Speed Of Sound Program

Feb 11, 2015

I have to write a program that asks the user to enter "air", "water", or "steel", and the distance that a sound wave will travel in the medium. The program should then display the amount of time it will take. The amount of time it takes sound to travel in air can be calculated as follows;

Time = Distance/1,100

The amount of time it takes sound to travel in water can be calculated with the following formula:

Time=Distance/4,900

The amount of time it takes sound to travel in steel can be calculated with the following formula:

Time=Distance/16400

Here is my code:

import java.lang.String;
/**
This program displays numbers padded with leading zeros.
*/
 
public class SpeedofSound {
public static void main(String[] args) {
double D; // declares this as double
D = keyboard.nextDouble();
 const double A = 1100; // declares this as a constant

[Code] .....

The following is the error I'm getting:

----jGRASP exec: javac SpeedofSound.Java
error: Class names, 'SpeedofSound.Java', are only accepted if annotation processing is explicitly requested
1 error
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

View Replies View Related

Speed Of Sound Java

Jul 27, 2014

I can't get the output to read correctly. I get 0 as the answer.

import java.util.Scanner;
public class TheSpeedofSound777
{

public static void main(String[] args)
{

System.out.println("Gordon Elam Sr July 26, 2014 ");

[code]...

View Replies View Related

Speed Ticket Program

Jan 5, 2015

public class TextLab03st
{
public static void main(String args[])
{
System.out.println("Text Lab 03");
System.out.println();
System.out.print("What is the posted speed limit? --> ");
int speedLimit = Expo.enterString();
System.out.println("");
System.out.print("How fast was the car travelling in mph? --> ");
int trueSpeed = Expo.enterString();
int ticketPrice;

[code]...

I tried everything and there's supposedly one error saying it reached the end of the file while parsing. I'm trying to make a speeding ticket program for my class.

View Replies View Related

Two Windows Are Being Made Of Game

Jan 19, 2014

I have a game which is very simple: it is two images, and one needs to reach the other. Once it does, it resets. I have a class which holds the two images, and another which holds the game. My images class extends my game class. The problem I am having is that when I run the program, not one, but two frames appear. One is the perfect game, working perfectly, and the other is the game without images. I want the one that is the game without images to simply stop appearing. I believe it is appearing because my class that displays the image is extending the game class, but I can't not extend it because if I do I get a whole lot of bugs and errors.

Image class:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;

[code]....

View Replies View Related

Displacing A Shape Made Of Asterisks

May 5, 2014

I'm making a program that prints arrows of varying tail length, head width, and displacement.The shape algorithms are working properly, but the displacement isn't working. The first arrow has zero displacement, and the second one is supposed to be bigger and start the print at 10 spaces right and 5 spaces down from the default, but it's not working. I tried changing the displacement settings of the first arrow, and no changes happened, so I know that the positions aren't registering properly in general. How to pass the xAdj and yAdj (displacement) values? I think I have the empty space formula set up, but it's still not running.

Driver:
public class Driver
{
//default values
public static final int Arrow_Default_xAdj = 0;
public static final int Arrow_Default_yAdj = 0;
public static final int Arrow_Default_tail = 5;
public static final int Arrow_Default_width = 5;

[code]...

View Replies View Related

Increase Counter When A Post Is Made?

May 15, 2015

I was wondering what the easiest way would be to keep track of everytime someone makes a new post on reddit (social media site, for those who don't know). I want the program to keep track of the number of posts made with a counter, but that's the easy part. How do I set up a program to actually communicate with and monitor reddit's servers in this manner?

View Replies View Related

How To Calculate Data Transfer Speed

Feb 25, 2014

Two machines are connected in a LAN & Sharing Files in between them.

Everything is Working Fine but now i want to calculate the Copying Speed/data transfer Speed between them.

View Replies View Related







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