import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class RotateImage extends JFrame {
MyPanel panel = new MyPanel();
public RotateImage() {
setSize(400,400);
setContentPane(panel);
setVisible(true);
}
public class MyPanel extends JPanel {
ImageIcon image = new ImageIcon("Sample.jpg");
int width = image.getIconWidth();
int height =image.getIconHeight();
long angle = 30;
public MyPanel(){
super();
}
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
g2d.rotate (Math.toRadians(angle), 60+width/2, 60+height/2);
g2d.drawImage(image.getImage(), 60, 60, this);
g2d.dispose();
}
}
public static void main(String[] args) {
new RotateImage();
}
}我的图片和类文件放在同一个文件夹之内, 但是无论如何就只能显示一个空的panel, 请问可能是什么样的问题呢?
先感谢拉
还有 最好用 RotateImage.class.getClassLoader().getResource("Sample.jpg")这种方法。
相对目录针对不同环境、不同主题的定义也是不同的,如Eclipse的资源定位问题,编译器也许是可自定义的