谁能帮我修改一下下面的Java程序,点击按钮可以旋转图片
importjavax.swing.*;importjava.awt.event.*;importjava.awt.*;publicclasslianxi5extends...
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class lianxi5 extends JFrame{
JPanel jPanel;
JButton jButton;
JLabel jLabel;
Image image;
ImageIcon imageIcon;
float scalew=1;
float scaleh=1;
float xuzh=0;
public lianxi5(){
super("dda");
jPanel=new JPanel();
jButton=new JButton("旋转");
image=Toolkit.getDefaultToolkit().getImage("src/img1.jpg");
imageIcon=new ImageIcon(image);
jLabel=new JLabel();
jLabel.setIcon(imageIcon);
jPanel.add(jLabel);
this.add(jPanel,BorderLayout.NORTH);
this.add(jLabel,BorderLayout.SOUTH);
this.setVisible(true);
this.setSize(600,600);
jButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
turn();
}
});
}
public static void main(String[] args) {
new lianxi5();
}
public void turn(){
int width=image.getWidth(jLabel);
int height=image.getHeight(jLabel);
double scale=1;
scalew=(float)(scalew*scale);
scaleh=(float)(scaleh*scale);
Math ma=new Math();
ma.pow(scalew, scaleh);
ma.round(xuzh=xuzh-5);
Bitmap bitmap=Bitmap
}
} 展开
import java.awt.event.*;
import java.awt.*;
public class lianxi5 extends JFrame{
JPanel jPanel;
JButton jButton;
JLabel jLabel;
Image image;
ImageIcon imageIcon;
float scalew=1;
float scaleh=1;
float xuzh=0;
public lianxi5(){
super("dda");
jPanel=new JPanel();
jButton=new JButton("旋转");
image=Toolkit.getDefaultToolkit().getImage("src/img1.jpg");
imageIcon=new ImageIcon(image);
jLabel=new JLabel();
jLabel.setIcon(imageIcon);
jPanel.add(jLabel);
this.add(jPanel,BorderLayout.NORTH);
this.add(jLabel,BorderLayout.SOUTH);
this.setVisible(true);
this.setSize(600,600);
jButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
turn();
}
});
}
public static void main(String[] args) {
new lianxi5();
}
public void turn(){
int width=image.getWidth(jLabel);
int height=image.getHeight(jLabel);
double scale=1;
scalew=(float)(scalew*scale);
scaleh=(float)(scaleh*scale);
Math ma=new Math();
ma.pow(scalew, scaleh);
ma.round(xuzh=xuzh-5);
Bitmap bitmap=Bitmap
}
} 展开
1个回答
展开全部
/*这样就好了
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package main;
/**
*
* @author stcdasqy
*/
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import static main.lianxi3.rotateImage;
public class lianxi5 extends JFrame {
JPanel jPanel;
JButton jButton;
JLabel jLabel;
Image image;
ImageIcon imageIcon;
float scalew = 1;
float scaleh = 1;
float xuzh = 0;
public lianxi5() {
super("dda");
jButton = new JButton("旋转");
image = Toolkit.getDefaultToolkit().getImage("src/img1.jpg");
imageIcon = new ImageIcon(image);
jLabel = new JLabel();
jLabel.setIcon(imageIcon);
this.add(jLabel, BorderLayout.NORTH);
this.add(jButton, BorderLayout.SOUTH);
this.setVisible(true);
this.setSize(600, 600);
jButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
turn();
}
});
}
public static void main(String[] args) {
new lianxi5();
}
public void turn() {
int width = image.getWidth(jLabel);
int height = image.getHeight(jLabel);
double scale = 1.5;
scalew = (float) (width * scale);
scaleh = (float) (height * scale);
BufferedImage bufImg = new BufferedImage(image.getWidth(null), image.getHeight(null),BufferedImage.TYPE_4BYTE_ABGR);
Graphics g = bufImg .createGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
//imageIcon.setImage(bufImg);
imageIcon.setImage(rotateImage(bufImg,30));
jLabel.setIcon(imageIcon);
jLabel.setSize(imageIcon.getIconWidth(), imageIcon.getIconHeight());
}
public static BufferedImage rotateImage(final BufferedImage bufferedimage,
final int degree) {
int w = bufferedimage.getWidth();
int h = bufferedimage.getHeight();
int nw = (int) (bufferedimage.getWidth()*1.414);
int nh = (int) (bufferedimage.getHeight()*1.414);
int type = bufferedimage.getColorModel().getTransparency();
BufferedImage img;
Graphics2D graphics2d;
(graphics2d = (img = new BufferedImage(nw, nh, type))
.createGraphics()).setRenderingHint(
RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2d.rotate(Math.toRadians(degree), nw / 2, nh / 2);
graphics2d.translate(nw/2-w/2, nh/2-h/2);
graphics2d.drawImage(bufferedimage, 0, 0, null);
graphics2d.dispose();
return img;
}
}
追问
import static main.lianxi3.rotateImage;
这句话是什么来的
追答
显示错误的话,删掉就好。。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询