顺时针旋转车轮而不旋转方法

时间:2015-04-06 04:40:07

标签: java swing awt

所以我做了一个项目,要求我逆时针旋转一个轮子。我这样做了。现在我被要求顺时针旋转它。我尝试了很多东西(比如减去10而不是在x2和y2变量上加10),但它总是会弄乱轮子的结构。我究竟做错了什么?这是构建方向盘的类:

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);


    }
}

这是旋转方向盘的类:

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 个答案:

没有答案