我想在这个程序中加入实现图片旋转,放大,缩小,我搞了半天搞不出来哦
//SwingPic.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SwingPic extends JFrame {
protected String filename = "", lastDir;
protected ImageIcon image;
Image im;
int height, width, count = 0;
JLabel labeledPic;
JScrollPane scroller;
Container content;
public SwingPic() {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
SwingUtilities.updateComponentTreeUI(this);
}
catch (Exception e)
{
}
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e) {
System.exit(0);}
}
);
setTitle("小虎的图片浏览器");
MenuBar mbar = new MenuBar();
Menu m = new Menu("文件");
m.add(new MenuItem("打开"));
m.add(new MenuItem("退出"));
mbar.add(m);
setMenuBar(mbar);
setSize(800, 600);
setVisible(true);
}
public void swingdraw() {
if(count==1) {
labeledPic = new JLabel(image, JLabel.CENTER);
labeledPic.setText(filename);
scroller = new JScrollPane(labeledPic);
scroller.setPreferredSize(new Dimension(height, width));
content = getContentPane();
content.add(scroller);
this.show();
}
else if(count>1) {
labeledPic = new JLabel(image, JLabel.CENTER);
labeledPic.setText(filename);
System.out.println("new jlabel ");
scroller = new JScrollPane(labeledPic);
scroller.setPreferredSize(new Dimension(height, width));
scroller.revalidate();
scroller.repaint();
}
}
public boolean action(Event evt, Object arg) {
if(arg.equals("打开")) {
FileDialog d =
new FileDialog(this, "Open image file", FileDialog.LOAD);
d.setFile("*.gif;*.jpg");
d.setDirectory(lastDir);
d.show();
String f = d.getFile();
lastDir = d.getDirectory();
if(f != null) {
im = Toolkit.getDefaultToolkit ().getImage (lastDir + f);
if(im==null) return false;
image=new ImageIcon(lastDir+f);
height = image.getIconHeight();
width = image.getIconWidth();
System.out.println("new image icon"+height+" "+width);
}
System.out.println("new file"+lastDir+f);
count++;
swingdraw();
}
else if(arg.equals("退出"))
System.exit(0);
else
return false;
return true;
}
public static void main(String[]args) {
SwingPic sp = new SwingPic();
}
}
大家帮我写写哦,谢谢了,呵呵
[此贴子已经被作者于2006-12-28 11:44:47编辑过]