关于J一个java程序的, 程序已经实现了图片的放大和缩小的功能,现在请你修改一下,使得图片可以旋转
importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;publicclasslianxi3extends...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class lianxi3 extends JFrame {
JPanel jPanel,jPanel1;
JLabel jLabel;
Image image;
ImageIcon imageIcon;
JButton jButton,jButton1;
float www=1;
float hhh=1;
public lianxi3() {
super("图片");
jPanel1=new JPanel();
jButton = new JButton("变大");
jButton1 = new JButton("变小");
image = Toolkit.getDefaultToolkit().getImage("src/img1.jpg");
jLabel = new JLabel();
jPanel1.add(jButton);
jPanel1.add(jButton1);
imageIcon = new ImageIcon(image);
jLabel.setIcon(imageIcon);
this.add(jLabel, BorderLayout.NORTH);
this.add(jPanel1, BorderLayout.SOUTH);
this.setVisible(true);
this.setSize(600, 600);
jButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jButton){
big();
} } });
jButton1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jButton1){
small();
} } });
}
public static void main(String[] args) {
new lianxi3();
}
public void big(){
int width=imageIcon.getIconWidth();
int height=imageIcon.getIconWidth();
double bigger=1.2;
www=(float)(width*bigger);
hhh=(float)(height*bigger);
System.out.println(www+""+hhh);
Math.pow(www,hhh);
image = image.getScaledInstance((int)www, (int)hhh, Image.SCALE_DEFAULT);
imageIcon = new ImageIcon(image);
jLabel.setIcon(imageIcon);
}
public void small(){
int width=imageIcon.getIconWidth();
int height=imageIcon.getIconWidth();
double bigger=0.8;
www=(float)(width*bigger);
hhh=(float)(height*bigger);
System.out.println(www+""+hhh);
Math.pow(www,hhh);
image = image.getScaledInstance((int)www, (int)hhh, Image.SCALE_DEFAULT);
imageIcon = new ImageIcon(image);
jLabel.setIcon(imageIcon);
}
}
另外你在添加两个按钮 展开
import java.awt.*;
import java.awt.event.*;
public class lianxi3 extends JFrame {
JPanel jPanel,jPanel1;
JLabel jLabel;
Image image;
ImageIcon imageIcon;
JButton jButton,jButton1;
float www=1;
float hhh=1;
public lianxi3() {
super("图片");
jPanel1=new JPanel();
jButton = new JButton("变大");
jButton1 = new JButton("变小");
image = Toolkit.getDefaultToolkit().getImage("src/img1.jpg");
jLabel = new JLabel();
jPanel1.add(jButton);
jPanel1.add(jButton1);
imageIcon = new ImageIcon(image);
jLabel.setIcon(imageIcon);
this.add(jLabel, BorderLayout.NORTH);
this.add(jPanel1, BorderLayout.SOUTH);
this.setVisible(true);
this.setSize(600, 600);
jButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jButton){
big();
} } });
jButton1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jButton1){
small();
} } });
}
public static void main(String[] args) {
new lianxi3();
}
public void big(){
int width=imageIcon.getIconWidth();
int height=imageIcon.getIconWidth();
double bigger=1.2;
www=(float)(width*bigger);
hhh=(float)(height*bigger);
System.out.println(www+""+hhh);
Math.pow(www,hhh);
image = image.getScaledInstance((int)www, (int)hhh, Image.SCALE_DEFAULT);
imageIcon = new ImageIcon(image);
jLabel.setIcon(imageIcon);
}
public void small(){
int width=imageIcon.getIconWidth();
int height=imageIcon.getIconWidth();
double bigger=0.8;
www=(float)(width*bigger);
hhh=(float)(height*bigger);
System.out.println(www+""+hhh);
Math.pow(www,hhh);
image = image.getScaledInstance((int)www, (int)hhh, Image.SCALE_DEFAULT);
imageIcon = new ImageIcon(image);
jLabel.setIcon(imageIcon);
}
}
另外你在添加两个按钮 展开
1个回答
2015-01-07
展开全部
Graphics 旋转画布 。。。。。。。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询