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);
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.
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.
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.
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:
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; }
/* * 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 part1; import java.awt.*; import java.applet.*; import java.awt.event.*; import javax.swing.*; class brick {
I am using libgdx and box2d to try to make a simple cannon game.
When I have the cannonball collide with another object I want to delete that object and have it stop calling all of it's functions. It doesn't seem like I can have it delete itself, and the contactListener has a reference to the cannonball and other object, but if I set either to null, it seems the original reference still exists and the object isn't deleted.
I am making a very simple 2D array game where the player is asked what size they would like the game board to be. After entering, it displays the board and the player 'P' starts at index [0][0]. After that, they are asked for an action, which can be "up", "down", "left", "right", or "exit". I will be including some extra later (like a treasure at the end, or random obstacles), but for now this is what the game consists of.
I was instructed to "do nothing" when/if the player attempts to go out of bounds. I am trying to simply print an error, such as "Out of bounds! Try again.", then prompt the player again for an action. I even tried to make a boolean method to catch it, but to no avail.
I don't want the exception to occur at all. I just simply want the error message to print to the player and ask for another action. I would prefer not to use try/catch, or try/catch/finally since I already tried that and it still gave the exception error.This program consists of two classes. I will show the class containing the main first, then the client-server type class second.
import java.util.Scanner; public class Driver { public static void main(String[] args) { World world = new World(); boolean keepPlaying; keepPlaying = true; boolean isOutOfBounds; isOutOfBounds = false; int height = 0; int width = 0; int x = 0; int y = 0;
I am writing code for a simple java game. The problem I am running into is that I have a moving icon (J button) that is controlled using the keyboard (arrows) and I also have stationary icons (J button). Is there a way to keep the moving icon from passing over the stationary icon? I would like the stationary icon to act like a wall.
The game is too have two players, each user clicks a button and two dices will roll, if a user rolls a double they win.
firstly I have started with two imageview's and a button I am trying to randomise two images by clicking one button I have managed to randomise one image in one box but I am struggling to randomise both image views here is my code so far.
I am trying to make a simple platformer game in Java. When I try to move the character I made it only moves over then immediately back
import java.awt.event.KeyEvent; public class UCC { private int xLoc; private int yLoc; private int xSpeed; private int ySpeed; private double gravity; private int size;
Haven't used java in a long long time and firstly need to know if its possible to build an app to replicate my ipad touch so that I can loop it between two different points on the screen. Friend recommended I got netbeans to get me started but wanted to ensure its possible before I get started.
And we have a class that draws a rectangle of 10 pixel height and 10 pixel width at 0,0 coordinates.
And we want to move with the arrows the rectangle but not to go off the frame.
The question is:
How can I do that if I draw another rectangle, it knows where is the other object and they not collapse. And so on, they move, but not collapse, just touch and stop.
I want to make a touchable program to install on my costumer information server that my client can search and register via my local database, how can i do this????
I'm trying to stress test JavaFX and I'm on Window 8.1 using 1.8.0_20-b26. I have an application that has many objects on the scene with animation timers and overall it purposefully runs very slow. I have listeners on the root AnchorPane for touch input and if I generate many touch point events after a few minutes I get "Too many touch points reported" exceptions (posted below) and the app of course no longer responds to touch input. Is it possible to catch the exception and then reset the scene touch input so it goes back to normal without restarting the application? If it lost any current touch input that's fine.
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: Too many touch points reported at javafx.scene.Scene$ScenePeerListener.touchEventNext(Scene.java:2686) at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleNextTouchEvent$346(GlassViewEventHandler.java:1090)
I'm trying to implement a two finger gesture to move a control for a touch screen. However simply touching the screen with two fingers will generate several events that jump all over the place. This here is the code:
Two finger move pressed First layout: 100.0, 100.0 Move by 94.0, 209.0 event set=4 Move by 1.0, 0.0 event set=5 Move by 95.0, 208.0 event set=6 Move by 1.0, 1.0 event set=8 Move by 96.0, 208.0 event set=11 Move by 219.0, 147.0 event set=11 Move by -121.0, 61.0 event set=13
I know that there is the possibility that I get multiple events with the same event set id. However this is not always the case. I would have expected to get one for each of the finger in the gesture. Why is that? As I understand the difference between changing the layout coordinates and the transformation is, that with the transformation coordinates, the bounds in parent changes, but not the bounds itself.
I'm not entirely clear on what effect this has, especially as I will also have the zoom and rotate gesture on the component. Which one is the better choice to change?To my understanding the coordinates of the touchpoint are relative to the parent component. In this case the layout coordinates of the rectangle. This would mean that I have to calculate the delta of the touch point in the onTouchMoved to the touch point of onTouchPressed.
This would get me the vector the rectangle moved.In the above example I use the main touch point of the two touchpoints of the event. As I understand it this should always be the same one. The correct way would be to calculate the geometric mean of the two points and use that, but that has the same effect. Simplifying the above example to one touch point only shows the same jumping behavior.
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 {
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.
In the following piece of code Iam confused as to where the InputMismatchException in the catch block is thrown on the first place? Is the InputMismatchException thrown automatically with declaring to throw the exception?
import java.util.*;
public class InputMismatchExceptionDemo { public static void main(String[] args) { Scanner input = new Scanner(System.in); boolean continueInput = true;
Is it a best practice to return from try block or place return statement after try-catch when we intend to return a value from a method(* Catch block is being also used to rethrow the exception)??