2017-07-03 133 views
0

我试图该代码是旋转图像,但我要旋转的图像垂直像在360度0倾斜旋转的地球如何沿y轴旋转图像?

我试图的代码是RotatedIcon类的

public class MainClass extends JPanel { 
    static ImageIcon icon = null; 
    static RotatedIcon rotate = null; 
    static JLabel label = null; 

    public MainClass() { 
     try { 
      BufferedImage wPic = ImageIO.read(this.getClass().getResource(
        "globe.png")); 
      icon = new ImageIcon(wPic); 
      rotate = new RotatedIcon(icon, 180); 

      label = new JLabel(rotate); 

     } catch (Exception e) { 
      System.out.println("raise exception"); 
     } 
    } 

    @Override 
    protected void paintComponent(Graphics g) { 
     super.paintComponent(g); 
     label.repaint(); 
    } 

    public static void main(String[] args) throws IOException, 
      InterruptedException { 
     MainClass mainClass = new MainClass(); 
     JFrame frame = new JFrame(); 
     mainClass.add(label); 
     frame.add(mainClass); 
     frame.setSize(500, 500); 
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     frame.setVisible(true); 
     ActionListener taskPerformer = new ActionListener() { 
      int degree = 360; 

      public void actionPerformed(ActionEvent evt) { 

       rotate.setDegrees(degree); 
       degree = degree + 90; 
       label.repaint(); 

       mainClass.repaint(); 

      } 
     }; 
     Timer timer = new Timer(1000, taskPerformer); 
     // timer.setRepeats(false); 
     timer.start(); 
     Thread.sleep(5000); 
    } 
} 

https://tips4java.wordpress.com/2009/04/06/rotated-icon/参考链接我用了。 由于解释能够旋转图像,但不是垂直。

+0

你真的应该给你具体的例子,因为这个类所做的旋转并不是围绕着X轴,而是围绕着图标的中心。所以你想达到的目标还不清楚。 –

+0

我的意思是像沿Y轴垂直旋转地球保持中心不变 – JAVA

+0

你的意思是类似[this](https://stackoverflow.com/questions/30587938/is-there-any-easy-way-to-rotate-一个图像 - 使用-java的无跳约-Z轴)? – Frakcool

回答

1

如果你只有一个2D世界的平面图像,那么你最好能做的就是使用Marquee Panel

Marquee Panel将允许您滚动图像,并且可以将其设置为在到达结尾时进行换行。你不会得到3D效果,你会用平坦的2D图像在世界各地滚动。