0

So I did a project that requires me to rotate a wheel counter-clockwise. I did so. Now I'm asked to rotate it clockwise. I've tried many things (like subtracting 10 instead of adding 10 on the x2 & y2 variables), but it always messes up the structure of the wheel. What am I doing wrong? Here's the class that builds the wheel:

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;

class DrawShapes extends JPanel {
    private static final long serialVersionUID = 838002164453315800L;

    public void paintComponent(Graphics g) {
        g.setColor(Color.BLACK);
        g.fillRect(RotateFrame.oneX, RotateFrame.oneY, 6, 6);

        g.setColor(Color.GREEN);
        g.fillArc(RotateFrame.centerX, RotateFrame.centerY, 200, 200, 355, 10);
        g.fillArc(RotateFrame.centerX, RotateFrame.centerY, 200, 200, RotateFrame.x2 - 5, 10);
        g.setColor(Color.red);
        g.fillArc(RotateFrame.centerX, RotateFrame.centerY, 200, 200, RotateFrame.x2 + 85, 10);
        g.fillArc(RotateFrame.centerX, RotateFrame.centerY, 200, 200, RotateFrame.x2 + 45, 10);
        g.fillArc(RotateFrame.centerX, RotateFrame.centerY, 200, 200, RotateFrame.x2 - 45, 10);
        g.fillArc(RotateFrame.centerX, RotateFrame.centerY, 200, 200, RotateFrame.y2 - 5, 10);
        g.fillArc(RotateFrame.centerX, RotateFrame.centerY, 200, 200, RotateFrame.y2 + 85, 10);
        g.fillArc(RotateFrame.centerX, RotateFrame.centerY, 200, 200, RotateFrame.y2 + 45, 10);
        g.fillArc(RotateFrame.centerX, RotateFrame.centerY, 200, 200, RotateFrame.y2 - 45, 10);

        g.setColor(Color.black);
        g.drawArc(RotateFrame.centerX, RotateFrame.centerY, 200, 200, 0, 360);


    }
}

Here's the class that rotates the wheel:

import java.awt.BorderLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;

public class RotateWheel implements MouseListener {

    boolean up = false;
    boolean down = true;
    boolean left = false;
    boolean right = true, visible = true, mouseClicked = false;
    public static int oneX = 7;
    public static int oneY = 7;
    JFrame frame;
    DrawShapes doTheThing;
    public static int x2 = 0, y2 = 180, i = 1, speedControl = 0;
    public static int centerX = 45, centerY = 39;
    public int change = 0;
    public static void main(String[] args) {
        // TODO Auto-generated method stub
    }

    private void update() {
        while (true) {
            if (oneX >= 283) {
                right = false;
                left = true;

            }
            if (oneX <= 7) {
                right = true;
                left = false;

            }
            if (oneY >= 259) {
                up = true;
                down = false;
                speedControl += 2 * 2;
            }
            if (oneY <= 7) {
                up = false;
                down = true;
                speedControl += 20;
            }
            if (up)
                oneY--;
            if (down)
                oneY++;
                    try {
                        Thread.sleep(0);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    frame.repaint();
                    x2 = x2 -10;
                    y2 = y2 -10;

                    if (x2 >= 360 || x2 > 0) {
                        x2 = 0;

                    }
                    if (y2 >= 360 || y2 > 0) {
                        y2 = 0;

                    }

                    frame.repaint();
                    try {
                        Thread.sleep(speedControl);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
        }
    }

    @Override
    public void mouseClicked(MouseEvent arg0) {
        // TODO Auto-generated method stub
        mouseClicked = true;
        System.out.println("true");
    }

    @Override
    public void mouseEntered(MouseEvent arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void mouseExited(MouseEvent arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void mousePressed(MouseEvent arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void mouseReleased(MouseEvent arg0) {
        // TODO Auto-generated method stub

    }

}

0 Answers0