显示文本框
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.image.*;
public class ScrollingImage  extends JFrame implements ActionListener
{ private ImageIcon colorVersion = null ;
    private ImageIcon grayVersion = null ;
    private BufferedImage originalImage = null;
private JLabel imageLabel = new JLabel();
private JButton quit = new JButton("Quit");
private JButton gray= new JButton("Gray");
private JButton recover= new JButton("Recover");
private JButton shrink= new JButton("Shrink");
private String fileName = "scenery.jpg";
public ScrollingImage()
{
super ("Scrolling Image");
Image colorImage = getToolkit().getImage("scenery.jpg");
Image grayImage = createImage(new FilteredImageSource(
colorImage.getSource(),new GrayFilter(true,50)));
colorVersion=new ImageIcon(colorImage);
grayVersion=new ImageIcon(grayImage);
ImageIcon icon = new ImageIcon(fileName);
imageLabel.setIcon(icon);
JScrollPane scrollingLabel = new JScrollPane(imageLabel);
scrollingLabel.setPreferredSize(new Dimension(500,400));
JPanel info =new JPanel(new GridLayout(4,1));
info.add(new JLabel("image Name: "+fileName));
info.add(new JLabel("Initial image Width: "+icon.getIconWidth()));
info.add(new JLabel("Initial image Height: "+icon.getIconHeight()));
info.add(new JLabel("scrollPane Dimension: "+"500,400"));
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,scrollingLabel,info);
split.setDividerSize(5);
split.setOneTouchExpandable(true);
split.setContinuousLayout(true);

JPanel buttons = new JPanel(new FlowLayout());
buttons.add(quit);
buttons.add(gray);
buttons.add(recover);
buttons.add(shrink);

getContentPane().add("Center",split);
getContentPane().add("South",buttons);
quit.addActionListener(this);
gray.addActionListener(this);
recover.addActionListener(this);
shrink.addActionListener(this);
imageLabel .setIcon(colorVersion);
validate();pack();setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{ if (ae.getSource()==quit)
System.exit(0);

if(ae.getSource()==recover)
imageLabel.setIcon(colorVersion);
if(ae.getSource()==gray)
imageLabel.setIcon(grayVersion);
else if(ae.getSource()==shrink)
{ }
    }
 
public static void main (String args[])
{
ScrollingImage sti = new ScrollingImage();
}
}放缩
import javax.swing.*; import java.awt.*; 
import java.awt.event.*; class C extends JFrame 

    public static void main(String[] args) 
    {  new C(); }     public C() 
    { 
     final JLabel imgView = new JLabel(new ImageIcon("scenery.jpg")) 
        { 
            public void paintComponent(Graphics g) 
            { 
                super.paintComponent(g); 
                g.drawImage(((ImageIcon)getIcon()).getImage(), 0, 0, getWidth(), getHeight(), null); 
            } 
        }; 
        addKeyListener(new KeyAdapter() 
        { 
            public void keyPressed(KeyEvent e) 
            { 
                double zoomFactor = e.getKeyCode() == KeyEvent.VK_UP    ?  1.1 : 
                                    e.getKeyCode() == KeyEvent.VK_DOWN  ?  .9 : 1; 
                imgView.setSize((int)(imgView.getWidth() * zoomFactor), 
                                (int)(imgView.getHeight() * zoomFactor)); 
            } 
        }); 
        add(imgView); 
        setSize(800, 600); 
        setVisible(true); 
        setDefaultCloseOperation(EXIT_ON_CLOSE); 
    } 

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【rpdou】截止到2008-07-21 10:06:16的历史汇总数据(不包括此帖):
    发帖的总数量:1                        发帖的总分数:0                        每贴平均分数:0                        
    回帖的总数量:0                        得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:0                        结贴的总分数:0                        
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:1                        未结的总分数:0                        
    结贴的百分比:0.00  %               结分的百分比:---------------------
    无满意结贴率:---------------------无满意结分率:---------------------
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html