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/参考链接我用了。 由于解释能够旋转图像,但不是垂直。
你真的应该给你具体的例子,因为这个类所做的旋转并不是围绕着X轴,而是围绕着图标的中心。所以你想达到的目标还不清楚。 –
我的意思是像沿Y轴垂直旋转地球保持中心不变 – JAVA
你的意思是类似[this](https://stackoverflow.com/questions/30587938/is-there-any-easy-way-to-rotate-一个图像 - 使用-java的无跳约-Z轴)? – Frakcool