※上記の広告は60日以上更新のないWIKIに表示されています。更新することで広告が下部へ移動します。

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.geom.*;
import javax.imageio.*;
import javax.swing.*;

public class AffineTest extends JPanel{
private double t = 0;
private double dt = Math.toRadians(90);
private BufferedImage img = null;
public static void main(String[] args){
	JFrame frame = new JFrame("アフィン変換テスト");
	frame.getContentPane().add(new AffineTest());
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setSize(400,400);
	frame.setVisible(true);
}
public AffineTest(){
	try{
		File file = new File("test.jpg");
		img = ImageIO.read(file);
		addMouseListener(new MyMouse());
	}catch(Exception e){}
}

class MyMouse extends MouseAdapter{
	public void mouseClicked(MouseEvent e){
		t += dt;
		repaint();
	}
}

public void update(Graphics g){paint(g);}
public void paintComponent(Graphics g){
	super.paintComponent(g);
	Graphics2D g2 = (Graphics2D)g;
	AffineTransform a = AffineTransform.getRotateInstance( t , 180 , 50 );
	g2.setTransform(a);
	g2.drawImage(img , 10 , 40 , this);
}
}