Bouncing Ball Around The Screen - It Keeps Disappearing

Oct 23, 2014

I'm trying to do is get this ball to bounce around the screen and ive gotten so far but not sure how to proceed. The ball keeps disappearing.

//bouncing ball

float x; //ball x position
float dx = 3; //ball x direction is right, step 5
float y; //ball y position
float dy = 3;
void setup () //runs once at start

[Code] ....

View Replies


ADVERTISEMENT

Program That Displays A Smiley Face Bouncing Around The Screen

May 30, 2014

I am writing a program that displays a smiley face bouncing around the screen. When I load the program it just shows a blank black JFrame. Here is the panel JPanel

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ReboundPanel extends JPanel {
private final int WIDTH = 300, HEIGHT = 100;
private final int DELAY = 20, IMAGE_SIZE= 35;
private ImageIcon image;

[Code]...

I have a suspicion that it might have to do with image = new ImageIcon("happyFace.gif");

I have tried other programs using .gif and they haven't worked on my computer and I haven't been able to figure out why.

View Replies View Related

Changing Horizontally Bouncing To Vertically Bouncing Balls

May 3, 2014

change these horizontally bouncing balls to vertically bouncing balls.

package PkgBallBounce2;
import java.applet.*;
import java.awt.*;
import javax.swing.*;

[Code]....

View Replies View Related

Swing/AWT/SWT :: Making Ball Bounce Around A Screen

Aug 12, 2014

I've got to make a ball bounce around a screen.... From what I can gather they seem to hold back useful java code.

anyway, i've changed the code over and over, and think this is the most succinct way i can manage it. but i have a problem. where i've marked the code (*****) and the following line are conditional on each other. so one won't provide the correct answer without the other line executing first, and vice versa (ignore the code after, i haven't looked at where that should be yet ). Anyway I don't really want to rip the code apart, again, because i'm pretty sure it's close.

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

Add A Background Image For Code Without Disappearing Button And Label?

Mar 10, 2014

How can i add a background image for this code without disappearing the button and label? I want a frame that has a background and still shows the buttons and label that I place. and how can I insert Buffered Reader in this code, this is a file organizer, but it only shows first line of a text file. I want to show the whole text file. And is it possible to also show path of the file?

import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Scanner;

[code]....

View Replies View Related

Swing/AWT/SWT :: JButtons Disappearing On Click And Reappearing When Mouseover Occurs

Mar 30, 2015

I'm having issues with JButtons and painting methods, whenever I click a grid on the board, the buttons in the JPanel disappear. Here is the board class:

package GUI;
public class Board extends JPanel implements Observer {
/**
*
*/
// private static final long serialVersionUID = 1L;
private final int boardSizeX;
private final int boardSizeY;
private final int L = 20;

[Code] ....

I know the code is messy in places, this will be fixed later, just need some pointers on how to solve the JButton issue.

View Replies View Related

Horizontal To Vertical Bouncing Balls

May 3, 2014

I'm new to java and I need changing the direction of these balls from a horizontal axis to a vertical axis bouncing in the center. I've tried reversing the integers but there seems to be something i've missed.

package package_bouncingball;
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
public class Class_bouncingball extends Applet implements Runnable  

int x_pos1 = 150;

[Code]...

View Replies View Related

Cardlayout Format - Change Main Menu Screen Into Game Screen On Button Click

Mar 16, 2015

I'm making a game of checkers for my A2 Computing coursework which is due in within a week. I have completely finished the game, and only thing I have left to do is connect the two JPanels together via a CardLayout that I have made. However I am unsure how to do so

Here is the code from my CardLayout:

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JButton;

[Code] ....

I have kept the code I am displaying to a minimal, hence I have removed all the action listeners for my buttons, anyway the problem I have is that, I would like it so that when the user clicks on the 'Multiplayer' button which is the array button ourButtons[1], it will then transition into my main game screen so that the user can then play a game of checkers.

Here is the main important GUI from my CheckerBoard class:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
  public class CheckerBoard extends JPanel implements ActionListener, MouseListener {
// Main routine that opens an Applet that shows a CheckerBoard
public static void main(String[] args) {
new CLayout();
 
[Code] ....

Once again kept to a minimal.

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

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 Create Multiple Threads Of Ball

Apr 18, 2014

Actually, i want to create multiple ball using multithreading.I have created a class 'CreateBall' and this class is making ball and second class 'Balls' is a Panel where the ball is display.But only one ball is being displayed.

Here is my code.......

CreateBall.java
import java.awt.*;
public class CreateBall implements Runnable
{
int px,py;
int w=20,h=20;
Graphics g;
public CreateBall(int px,int py)

[Code] .....

View Replies View Related

How To Make Curve Motion With Ball Object

Jun 25, 2013

I want to make a simply game,actualy not a game but I want to moving object curve just like angry bird. Where I can move an object with curve motion. But I don't know how. I just can make it move straight(left,right,down,up).

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

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

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

Java Program - Track Position Of Imaginary Ball As It Bounces Around Imaginary Box

Oct 3, 2014

I am working on a program that asks me to track the position of an imaginary ball as it bounces around an imaginary box. The user gives me input for the starting position of the ball (x,y), the bottom-left boundaries of the box (xl, yl), the top right boundaries (xr, yr) and the angle. The program then needs to find where the ball will hit the box, and then print that location and find the new angle for the next point. My program currently works in most cases if the angle is less than pi.

Here is my code

public class BouncyBall {
public static void main(String args[]){
if (args.length != 8) {
System.out.println("Error: usage is X, Y, Angle, Xl, Yl, Xr, Yr,N");
System.exit(1);
}
double x,y,xl,yl,xr,yr,angle;
int n;
x=Double.parseDouble(args[0]);
y=Double.parseDouble(args[1]);

[Code] .....

View Replies View Related

How To Add Tiles To Screen

Mar 24, 2014

this is my first java game im making i tried to add tiles to the screen but i just get a black screen with no errors?

View Replies View Related

How To Clear Console Screen

Apr 2, 2014

How to clear console screen ? I am using Linux machine.

1) Runtime.getRuntime().exec("clear"); // this is not working. Not clearing the screen

2) for ( int i = 0; i < SOME_NUMBER; i++)
System.out.println();

2nd way is working but i think it is not a good option as i need to move scroll bar again and again.

View Replies View Related

JSF :: How To Force Refresh Screen

Oct 9, 2014

in my JSF2 app I have ​​screens composed with :

- Header
- Body

In the header I have a combo list. At each change in value in the combo list I have an Ajax request that updates the data in the Body. So far everything is working properly. Now the home screen's structure should be change when the value of combo list change. To do this I have :

- 1 ManagedBean HomeBean that manage the home
- 1 ManagedBean HeaderBean that manage the header
- 2 object HomeScreen1.java and HomeScreen2.java that allows me to valued data from each screen
- 2 services HomeScreen1Loader.java and HomeScreen2Loader.java that manage loading of each type of screen
- 1 template home.xhtml
- 2 fichier home1.xhtml et home2.xhtml

When I log in to the application, I get the good page corresponding (Element type 1 => home page 1). But when I select a type 2 item, the actionListener methode is execute, ManagedBean's data was updated (for type 2 screen) , but the page does not updated. What do you do ?

HeaderBean.java :

package com.omb.view;
import java.io.Serializable;
import java.util.List;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

[Code] .....

View Replies View Related

Adding Selector On The Screen

Jan 30, 2014

I was working on adding a selector on the screen. Searching for code, I found something that some created better than I ever could. I'm trying to integrate it into my code.

I have a program that is pretty MVC.

I'm in my controller class and I'm calling this code:

java - Drawing a bounding rectangle to select what area to record - Stack Overflow

I've changed it to a runnable and called a wait after I called this class, but it still continues on to the next line.

I'm thinking I'll have to either create a super controller (one that manages two controllers and have a multiple set of views and models) because I'll have multiple views or I'll have to figure out how to wait for it to finish as a thread. As mentioned above, wait() doesn't work.

This is the code in my controller after I changed it back from a Runnable:

SelectionRectangle m_rect = new SelectionRectangle();
//Thread m_thread = new Thread(m_rect);
//m_thread.start();
TopLeft = m_rect.getTopLeft();
BottomRight = m_rect.getBottomRight();
C_view.setText(TopLeft.toString());

View Replies View Related

Disabling All Screen Buttons

Apr 29, 2014

I'm having an issue with a swing application I'm working on. Java version is 4 (I know...). I have a main screen panel with multiple sub-panels (rows). Each of these row panels contains an additional 2 sub-panels. One of these 2 sub-panels contains buttons. When 1 button is pressed, I want to disable all of the buttons on-screen (or any other way of blocking user input) until a background event finishes. The row panels do not know about each other.

The first thing I have tried doing is, when a button is pressed, getting the parent. Using the parent I then iterate through its components, and so on until I'm iterating through the buttons. For each button, I am doing a .setEnabled(false); However, this does not work, why. I've also tried wrapping this process in SwingUtilities.invokeLater() out of desperation, but that didn't work either.

What would be the cleanest way to disable all buttons? Or block all user input? I've also tried adding an opaque dialog which hasn't worked. Last resort would be maintaining some sort of button list, but I'd rather not.

View Replies View Related







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