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