Results 1 to 3 of 3
  1. #1
    Yarin1312 is offline Member
    Join Date
    Jul 2012
    Rep Power

    Default How can i make a wheels rotate/flip

    look i'm attempt to make a car moving, and i'm tring to use g2d to rotate a rectangle for example just to understands how can i make the wheels rotate/flip, so look at that code:
    PHP Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class RotateTest extends JPanel {
     Timer timer;
     int x = 1;
     public RotateTest(){
      ActionListener task = new ActionListener(){
       public void actionPerformed(ActionEvent ae) {
        x += 1;
      timer = new Timer(25, task);
     public void paint(Graphics g){
            Graphics2D g2d = (Graphics2D) g;
            g2d.setColor(new Color(150, 150, 150));
            g2d.fillRect(20, 20, 80, 50);
            g2d.translate(180, -50);
            g2d.fillRect(80, 80, 80, 50);
     public static void main(String[] args) {
            JFrame frame = new JFrame("Rotation");
            frame.add(new RotateTest());
            frame.setSize(300, 200);
    Now someone car help me with this, beacuse when you run that code the right rectangle is flip in circle and not in his specific place without change no x or y,
    Can you fix the code for me? or give me an another option to make this?

    thanks :)

  2. #2
    totalspelnerd is offline Member
    Join Date
    Mar 2012
    Rep Power

    Default Re: How can i make a wheels rotate/flip

    In case you haven't found it out yet, what you are doing now is rotating it in the upper-right corner and you want to to rotate in the middle if I understood you correctly.

    g2d.rotate has 2 different parameters options. One with only rotation and one with rotation,x,y. The x and y is the position that it is going to be rotated at.

    Java Code:
    That is what you want if I understood you.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: How can i make a wheels rotate/flip

    Please don't unnecessarily bump old dead threads up to the top of the forum listing.


    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. How do I flip this image?
    By antnas in forum New To Java
    Replies: 2
    Last Post: 11-08-2012, 09:30 PM
  2. Flip int value(1234 becomes 4321)
    By Pojahn_M in forum New To Java
    Replies: 2
    Last Post: 09-28-2012, 12:47 AM
  3. Flip Pictures on DrJava
    By siddanth1 in forum New To Java
    Replies: 2
    Last Post: 02-10-2012, 03:08 AM
  4. coin flip program
    By chandrasekhar.melam in forum New To Java
    Replies: 5
    Last Post: 09-26-2011, 06:30 PM
  5. Othello/Reversi flip checkers
    By chielt in forum Java Applets
    Replies: 10
    Last Post: 01-03-2010, 12:25 AM

Posting Permissions

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