日期:2014-05-20 浏览次数:20805 次
public class Test extends JLabel { private BufferedImage[] images = new BufferedImage[16]; private int index; public Test(BufferedImage original) { for (int i = 0; i < images.length; i++) { double theta = -2 * Math.PI * i / images.length; BufferedImage img = new BufferedImage(original.getWidth(), original.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = img.createGraphics(); g2d.drawRenderedImage(original, AffineTransform .getRotateInstance(theta, original.getWidth() / 2, original.getHeight() / 2)); images[i] = img; } } public void rotate() { index = (index + 1) % images.length; setIcon(new ImageIcon(images[index])); } public static void main(String[] args) throws Exception { final Test test = new Test(ImageIO.read(Test.class .getResourceAsStream("1335971717_7428.png"))); JFrame jf = new JFrame("Test"); jf.add(test); jf.setSize(100, 100); jf.setVisible(true); new Thread() { public void run() { try { for (;;) { test.rotate(); sleep(100); } } catch (InterruptedException ex) { ex.printStackTrace(); } } }.start(); } }