⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 displayimage.java

📁 非常好的java事例以及带源码事例的java2教程
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;
import java.net.*;

public class DisplayImage extends JApplet
{
  public void init()
  {
    ImageIcon icon = null;
    try
    {
      icon = new ImageIcon(new URL(getCodeBase(),"Images/wrox_logo.gif"));
    }
    catch(MalformedURLException e)
    {
      System.out.println("Failed to create URL:\n" + e);
    }

    int imageWidth = icon.getIconWidth();           // Get icon width
    int imageHeight = icon.getIconHeight();         // and its height
    resize(imageWidth,imageHeight);                 // Set applet size to fit the image

    // Create panel a showing the image
    ImagePanel imagePanel = new ImagePanel(icon.getImage());

    getContentPane().add(imagePanel);               // Add the panel to the content pane
  }

   // Class representing a panel displaying an image
   class ImagePanel extends JPanel
   {
     public ImagePanel(Image image)
     {
      this.image = image;
     }

     public void paint(Graphics g)
     {
       g.drawImage(image, 0, 0, this);                        // Display the image
     }

     Image image;                                             // The image
   }
}

⌨️ 快捷键说明

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