Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Help with moving an object in Java?

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with moving an object in Java?

    Hello all,
    Could someone give me some advice on how to tackle this problem please - thank you in advance. So basically I have a program that paints a simple object image. There are 5 of these objects altogether and different classes and methods have been set up to do this and this works correctly. The program currently also asks the user if they would like to change the colour of this object shape, and which shape they would like to change (user inputs a number 1-5) then the program will change the colour of this shape.

    But the new task is for the user to input a number (1-5) to which shape they would like to MOVE position of. Any ideas on how this would be done? Would there need to be different methods for changePositionX, changePositionY? The user needs to input the X and Y co ordinates and then this will move the selected shape to its NEW position in the current JFRAME.
    Thank you, if any code is needed I will paste it in.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,310
    My Mood
    Mellow
    Thanks
    194
    Thanked 669 Times in 656 Posts

    Default Re: Help with moving an object in Java?

    I would paint the shapes on a JPanel which is then added to the JFrame. Each shape change entered by the user, color, x/y position - whatever - affects the attributes of the shape(s) which are then redrawn in the JPanel's paintComponent() method. These techniques are discussed in the Java Tutorials in the Custom Painting topic.

Similar Threads

  1. Hello Moving to Java programming
    By littleb in forum Member Introductions
    Replies: 1
    Last Post: February 2nd, 2014, 06:39 AM
  2. 2d sidescroller moving background in java
    By person101 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 18th, 2014, 12:50 PM
  3. [SOLVED] help with java game source code..
    By hemla in forum Object Oriented Programming
    Replies: 7
    Last Post: March 7th, 2013, 05:48 PM
  4. How To Track A Moving Object
    By mahdi.nikoo in forum Algorithms & Recursion
    Replies: 7
    Last Post: November 2nd, 2012, 01:03 PM
  5. Replies: 3
    Last Post: November 10th, 2011, 06:11 AM