日期:2014-05-20 浏览次数:20694 次
package prx.swing.java2d;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
//图像旋转演示
public class RotateImageDemo extends JFrame {
/**
*
*/
private static final long serialVersionUID = 5590452310554415844L;
JSlider jSlider = new JSlider(JSlider.HORIZONTAL, 0, 180, 0); // 设定旋转角度
ImagePane imagePane = new ImagePane(); // 绘制图像的面板
public RotateImageDemo() {
super("图像旋转演示"); // 调用父类构造函数
jSlider.setPaintTicks(true); // 绘制标志位
jSlider.setMajorTickSpacing(45); // 设置标志尺寸
jSlider.setMinorTickSpacing(5);
jSlider.setPaintLabels(true); // 绘制出数字
jSlider.setBorder(new javax.swing.border.TitledBorder(BorderFactory
.createEmptyBorder(), "图像的旋转度")); // 设置边框
jSlider.addChangeListener(new ChangeListener() { // 滑动条jSlider事件处理
public void stateChanged(ChangeEvent ce) {
int value = ((JSlider) ce.getSource()).getValue(); // 获取设置值
double angle = (float) value / 180 * Math.PI; // 得到旋转角度(弧度制)
imagePane.ratoteImage((float) angle); // 旋转图像
}
});
Container container = getContentPane(); // 得到窗口容器