fetchimage.java

来自「Java经典例程 从外国一大学计算机教授出版物下载的代码 经典」· Java 代码 · 共 37 行

JAVA
37
字号
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.net.*;

class FetchImage extends Frame {

  /*  Fetch an image program  by  J M Bishop  Jan 1997
   *  ======================  Java 1.1
   *                          updated B Worrall Aug 2000

   *  Fetches a jpg or gif image into a window.
   *  Illustrates use of awt.image. */

  private Image image;

  public void paint(Graphics g) {
    g.drawImage(image, 50, 50, this);
  }

  public static void main(String[] args) throws Exception {
    new FetchImage(args[0]);
  }

  FetchImage (String name) throws Exception {
    URL imageURL = new URL(name);
    image = createImage((ImageProducer) imageURL.getContent());
    setSize(300, 300);
    setVisible(true);
    addWindowListener(new WindowAdapter () {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });
 }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?