用applet里Graphics类的的DRAWIMAGE方法也应该可以实现~~如果想看它是如何实验的就用JAD反编译那个网页的CLASS文件看里面的代码就行了。看看网页的代码也可以。

解决方案 »

  1.   

    /*
     * @(#)ScalePanel.java 1.0 03/08/31
     *
     * You can modify the template of this file in the
     * directory ..\JCreator\Templates\Template_1\Project_Name.java
     *
     * You can also create your own project template by making a new
     * folder in the directory ..\JCreator\Template\. Use the other
     * templates as examples.
     *
     */
    package myprojects.scalepanel;import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;public class ScalePanel extends JPanel
    {
    public ScalePanel()
    {
    setPreferredSize( new Dimension( 300, 200 ) );
    setBackground( Color.white );
    setLayout( null );
    JTextField text = new JTextField( "haha" );
    text.setEnabled( false );
    text.setBounds( 50, 50, 100, 30 );
    add( text );
    setEnabled( false );
    } private static void scaleComponent(Component comp, double scale)
    {
    int w = comp.getWidth();
    int h = comp.getHeight();
    comp.setSize((int) (w * scale), (int) (h * scale));
    if(comp instanceof Container)
    {
    Container container = (Container) comp;
    Component[] comps = container.getComponents();
    for(int i=0; i<comps.length; i++)
    scaleComponent(comps[i], scale);
    }
    } public static void main( String[] args )
    {
    final JFrame f = new JFrame();
    f.setSize( 500, 400 );
    final ScalePanel panel = new ScalePanel();
    final JScrollPane jsp = new JScrollPane( ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED );
    jsp.getViewport().setView( panel );
    Container pane = f.getContentPane();
    pane.add( jsp ); JButton b = new JButton( "scale" );
    b.addActionListener( new AbstractAction() {
    public void actionPerformed( ActionEvent e )
    {
    double scale = 2;
    scaleComponent(panel, scale);
    }
    });
    pane.add( b, BorderLayout.SOUTH ); f.show();
    }
    }