up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up
up

解决方案 »

  1.   

    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
      

  2.   

    //ImagePain.javaimport java.awt.*;
    import java.awt.event.*;public class ImagePain extends Frame
    {


    public ImagePain()
    {
    ImageCanvas images = new ImageCanvas("images\\photo.jpg");
    add(images);
    }

    public static void main(String[] args)
    {
    ImagePain f = new ImagePain();     
    f.addWindowListener( new WindowAdapter() 
    {         
    public void windowClosing( WindowEvent e) 
    {
    System.exit(0);
    }
    });     
    f.setSize(800, 600);     
    f.show(); 
    }

    class ImageCanvas extends Canvas
    {
    Image i;
    public ImageCanvas(String imageName)
    {
    i = Toolkit.getDefaultToolkit().getImage(imageName);
    MediaTracker mt = new MediaTracker(this);
    try
    {
    mt.addImage(i,0);
    mt.waitForID(0);
    }
    catch(InterruptedException e)
    {
    e.printStackTrace();
    }
    }

    public void paint(Graphics g)
    {
    g.drawImage(i,0,0,this);
    }

    public Dimension getPreferredSize()
    {
    int w = i.getWidth( this );
    int h = i.getHeight( this );
    return new Dimension( w, h );
    }
    }
    }