AmanDeep
move an object
1 Answer(s)      a year and 8 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)
            {
            }
        }
    }
}

}

View Answers

September 19, 2011 at 10:20 AM


please visit the following link:

Move ball









Related Pages:
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
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>
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
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
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
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 
Moving Cursor within ResultSet
.style1 { text-align: center; } .style2 { background-color: #FFFFCC; } Moving Cursor Within ResultSet There are many methods are given to move...); // Getting reference to connection object statement = connection.createStatement
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
Flex component move using drag and drop in Flex4
Flex component move using drag and drop in Flex4: In this example you can see how we can drag and drop the component from one place to another... title="Flex component move using drag and drop" width="
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
Photoshop Tutorial : How to remove an object from a picture
How to remove an object from a picture       We are going to learn the method to remove an object from a picture. If you want to remove an object, which you don't want to like
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-Oriented Programming
Java: Object-Oriented Programming Beyond OOP Here's an interesting article about going beyond OOP: The Next Move in Programming: A Conversation with Sun's Victoria Livschitz at java.sun.com/developer/technicalArticles/Interviews
Spring Framework
, we will move on to the main process of any enterprise application: Data... Data Objects and Object Relational Mapping (ORM) tools like Hibernate, OJB
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 creation
object creation  when will java object is created? is it at runtime or compiletime
Object Oriented
Object Oriented  C++ is Purely object oriented or not .Then why java called purely object oriented
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
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
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
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 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
Java object
Java object  Which class should you use to obtain design information about an object
Object Creations
Object Creations  String a[][]=new String[10][20]; The above line how many objects are created
Java object
Java object  What is mutable object and immutable object?  An Immutable object is a kind of object whose state cannot be modified after it is created. This is as opposed to a mutable object, which can be modified
Session Object
Session Object   What is the Max amount of information that can be saved in a Session Object ?   There is no such limit on the amount of information that can be saved in a Session Object. The only limit is the Session
object array
object array  Hi i have array that is object[] obj= { new string("hi"), new vector().add(10), new hashmap().setkey()} display(obj); display(object{[] obj) {} Now my question is what is the string length and how to retrieve
Vector object[]
Vector object[]  I want to create payslip in java public Vector...(); Object[] value = new Object[] {"Employee Name",f.ename.getSelectedItem()}; rec.add(value); value = new Object[] {"Mary-Kate Olsen", "Ashley
class and Object
class and Object  how many classes,References and objects in this following statement.... A a=new B();   Hi, In the statement: A a=new B(); There are 2 classes, Class A and Class B. References : 1 (Object of B
implect object
implect object  how i implment implect object   Hi Friend, Please visit the following links: http://www.roseindia.net/help/java/o/jsp-implicit-objects.shtml http://www.roseindia.net/jsp/jspfundamentals.shtml Thanks
constructor or object
constructor or object  object or construct which create first?   A constructor is always created first. Here is an example: class Example { Example(String st){ System.out.println(st); } public
JDBC ResultSet Scroll Insensitive Type Example
JDBC ResultSet Scroll Insensitive Type Example: Through this ResultSet type the cursor can move in any direction. It is insensitive which means result set... object to create a Scroll-Insensitive, read only ResultSet object
JDBC ResultSet Scroll Sensitive Type Example
JDBC ResultSet Scroll Sensitive Type Example: Through this ResultSet type the cursor can move in any direction. It is sensitive which means result set... the statement object to create a Scroll-Sensitive, read only ResultSet object
object and method
object and method  a college would like to automate managing courses offered to students. initially only three courses are involved. each courses has... and an application that creates the necessary object
Object slicing
Object slicing  I have a program as bellow: #include<iostream.h> #include<conio.h> class A { public: int x; A() { x=10; } }; class B:public A { protected: int y
Class and object
the object of subclass Thanks

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.