Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


AmanDeep
move an object
1 Answer(s)      3 years and 2 months ago
Posted in : Java Beginners


//Dear Deepak i want to write a code which mover the ball along x-co-ordinates 9 times on for loop execution, but the ball is not moving, please help. Thanks. :)

//MoveBall.java import javax.swing.*;

import java.awt.*;

public class MoveBall

{

public static void main(String[] args)

{

MoveBall d = new MoveBall();
new Thread().start();

}

public MoveBall()

{

JFrame frame = new JFrame("Drawing with Alpha");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().add(new Ball());

frame.setSize(400,400);

frame.setVisible(true);

}

public class Ball extends JComponent implements Runnable
{
    int x=80, y=100;
    int radius = 20;
    public void paint(Graphics g)
    {
        g.setColor(Color.magenta);
        g.fillOval(x-radius, y-radius,2*radius,2*radius);
        //g.drawOval(20,20, x, y);
    }
    public void start()
    {
        Thread th = new Thread();
        th.start();
    }

    public void run()
    {
        for(int i=0; i<10; i++)

        {
            repaint();
            try
            {
                Thread.sleep(200);
                x = x+10;

            }
            catch(Exception e)
            {
            }
        }
    }
}

}


Advertisement
View Answers

September 19, 2011 at 10:20 AM


please visit the following link:

Move ball



Related Tutorials/Questions & Answers:
move an object
move an object   //Dear Deepak i want to write a code which mover the ball along x-co-ordinates 9 times on for loop execution, but the ball... visit the following link: Move ball
JavaScript move file
JavaScript move file...; In this section, we are going to move a file from one folder to another using JavaScript. In the given example, firstly we have created an ActiveXObject object
Advertisements
MX Move Effect in Flex4
MX Move Effect in Flex4: The component move from one point to another point by using Move effect. You will set the xFrom, yFrom, xTo, yTo, xBy and yBy property for moving a component. The tag of Move effect is <mx:Move>
JavaScript move div
JavaScript move div...; This section illustrates you how to move a div element on the window using... 'Hello World' in order to move it on the browser. For this, we have used onClick
Spark Move Effect in Flex4
Spark Move Effect in Flex4: The component move from one point to another point by using Move effect. You will set the xFrom, yFrom, xTo, yTo, xBy and yBy property for moving a component. The tag of Move effect is <s:Move>
Java file move
Java file move In this section, you will learn how to move a file... a file but here we have used this method to move a file from one directory to another. You can see in the given example, we have created an object of File
JavaScript move image
JavaScript move image...; This section illustrates you how to move an image on the window using JavaScript. In the following code, we have defined an image 'node.jpg' in order to move
How to move a value in array?
How to move a value in array?   Enter value at the End: 5 Display...]5 Index at [3]8 and when i enter 0 in last index it will move and if i enter again zero in last index it will not move anymore... pls help..thank you
How to move a value in array?
How to move a value in array?   Enter value at the End: 5 Display...]5 Index at [3]8 and when i enter 0 in last index it will move and if i enter again zero in last index it will not move anymore... pls help..thank you
object
object  is it possible to create object in the same class..?.   Yes, you can. class CreateObject { CreateObject(){ System.out.println("I have an object."); } public static void main(String[] args
how to move label in jframe in java?
how to move label in jframe in java?  please any one can give me code for moving a java label in Jframe
Move text on the frame
Move text on the frame using Java Program In this section, you will learn how to move text on the frame. As you have already learned about the html marquee... to move the specified string. import java.awt.*; import 
how to move pointer in Textfield to newline
how to move pointer in Textfield to newline  consider my case and provide me solutions: import java.awt.; import java.awt.event.; class Table1 extends Frame implements ActionListener{ TextField tf1,tf2,tf3
iphone programming combining move and flip - Java Beginners
iphone programming combining move and flip  Hi, I would like to combine the move image and flip image codes so that i can move and flip different images to show another image
Move Image in Java Swing
How to Move Image in Java Swing In this section, you will learn how to move an image using mouse. For this purpose, we have specified an image and using... to move this image, we have used public void mouseMoved() and public void
How to move a file from a directory to other directory
How to move a file from a directory to other directory  I tried the above example it will move the folder to other directory but it does not move the image file or other file to a specified directory. Can anyone help me? Thanks
How To Move Image Smoothly
How To Move Image Smoothly       In this example you will see how to move image smoothly on mouse motion using Java.  To move an image, we have used the Listener interface
Move Curve Control Point
Move Curve Control Point       In this section, you will studied how to move the curve control point and manipulates the shape of curve. The Control points
We are providing Downloadable Version of Mandrake Move Linux
Mandrake Move Live Linux Now Available Linux Mandrake Move Live CD's We are providing the free downloadable version of Mandrake Official Move Live... on a one bootable CD. Mandrake Move is based on Mandrake 9.2. Mandrake move
object of object class
object of object class  what do u mean by "object of object class
radio button selection should move the control to a text box that needs to be complete
radio button selection should move the control to a text box that needs to be complete  on selection of a radio button mouse should move to a particular text box that needs to be filled. How
object creation
object creation  when will java object is created? is it at runtime or compiletime
Object
Object       An object...). In an object, variables store values for later use and methods are the unit... are the basic units of the object-oriented programming. Objects are the part of our day
Object Oriented
Object Oriented  C++ is Purely object oriented or not .Then why java called purely object oriented
Object reference not set to an instance of an object
Object reference not set to an instance of an object  Object reference not set to an instance of an object
Flex Component Move with the help of drag and drop
Flex Button Drag and Drop with X and Y Co-ordinate :- In this tutorial you can  drag and drop for button with x and y co-ordinate or move one place to another in container. In this tutorial we can explain how to use Drag Manager
Session Object
Session Object  Why do we require Session Object?  Hello.... The session object is used by the developers to store and retrieve user's related data such as login details. The javax.servlet.http.HttpSession object
object as argument
object as argument  what happens when we pass a object into a method???if java is pass by value how does this makes a difference.....pllzzz give me more clarification on why we pass objects in a margument
ArrayList object
ArrayList object  i have am ArrayList object it containg data base records in it, now i want to display this ArrayList object data in my jsp programe, plz help me
Object Creations
Object Creations  String a[][]=new String[10][20]; The above line how many objects are created
Java object
Java object  Which class should you use to obtain design information about an object
Advertisements
 

 

 

DMCA.com