📄 displayimage.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 + -