Results 1 to 2 of 2
  1. #1
    ilovenayoon is offline Member
    Join Date
    Dec 2009
    Posts
    1
    Rep Power
    0

    Exclamation Bouncing ball program... having problems..

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class PracticalExam extends JApplet
    {
    	int x = 70;
    	int y = 100;
    	int xVelocity = 5;
    	int yVelocity = 5;
    
    	public void start()
    	{
    		System.out.println("firing start...");
    
    		Timer timer;
    		final int FREQ = 33;
    		timer = new Timer(FREQ, new ActionListener()
    		{
    			public void actionPerformed(ActionEvent evt)
    			{
    				repaint();
    			}
    		});
    
    		timer.start();
    	}
    
    
    	public void paint(Graphics g)
    	{
    
    		if ( (x > 350) || (x < 50) )
    		{
    			xVelocity = -xVelocity;
    		}
    
    		if ( (x < 350) || (x > 50) )
    		{
    			g.setColor(Color.white);
    			g.fillRect(x,y,30,30);
    			x += xVelocity;
    			y += yVelocity;
    			g.setColor(Color.green);
    			g.fillRect(x,y,30,30);
    		}
    
    		if ( (y > 250) || (y < 50) )
    		{
    			yVelocity = -yVelocity;
    		}
    
    		if ( (y < 250) || (y > 50) )
    		{
    			g.setColor(Color.white);
    			g.fillOval(x,y,50,50);
    			x += xVelocity;
    			y += yVelocity;
    			g.setColor(Color.red);
    			g.fillRect(x,y,50,50);
    		}
    
    	}
    }


    I was making a progam that a ball bounces the wall.
    My purpose was to make the ball change its shape and color when it bounces.
    But I am having problems...
    Please help me editting...... emergency T^T

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

Similar Threads

  1. [SOLVED] Bouncing ball with polar coordinates
    By Ypsilon IV in forum New To Java
    Replies: 4
    Last Post: 04-22-2009, 01:19 AM
  2. How to create a bouncing ball animation
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-21-2008, 09:43 PM
  3. high bouncing ball
    By bouncingball in forum Reviews / Advertising
    Replies: 1
    Last Post: 06-19-2008, 12:21 PM
  4. bouncing ball issue
    By adam405 in forum New To Java
    Replies: 1
    Last Post: 03-18-2008, 04:48 AM
  5. Problem deleting ball from bouncing ball app
    By adlb1300 in forum New To Java
    Replies: 2
    Last Post: 12-03-2007, 10:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •