📄 loadimageapplet.java
字号:
// Fig. 2.11_01: LoadImageApplet.java
// 加载并显示图像文件
import java.awt.*; // 引入java.awt包中所有的类
import javax.swing.*; // 引入javax.swing包中所有的类
import java.net.*; // 引入java.net包中的类,支持网络功能
import javax.imageio.*; // 引入java的高级图形处理包
public class LoadImageApplet extends JApplet
{
private Image logoJPG, logoBMP, logoPNG;
private ImageIcon logoGIF;
// 初始化
public void init()
{
// 处理JPG格式图像
logoJPG = getImage(getDocumentBase(), "logo.jpg");
// 处理PNG格式图像
logoPNG = getImage(getDocumentBase(), "logo.png");
try
{
// 处理GIF格式文件
logoGIF = new ImageIcon(new URL(getCodeBase(), "logo.gif"));
// 处理BMP格式图像
logoBMP = ImageIO.read(new URL(getCodeBase(), "logo.bmp"));
}
catch (Exception e)
{
System.out.print("打开图形文件出错!\n" + e);
return ;
}
}
// 加载并显示图像文件
public void paint(Graphics g)
{
// 调用父类的 paint 方法
super.paint(g);
g.setColor(Color.ORANGE);
// 设置字体
g.setFont(new Font("汉真广标", Font.PLAIN, 30));
g.drawString("加载并显示图像文件", 10, 35);
// 显示图像文件
g.drawImage(logoJPG, 5, 50, this);
g.drawImage(logoPNG, 160, 50, this);
g.drawImage(logoBMP, 5, 160, this);
logoGIF.paintIcon(this, g, 160, 160);
} // paint 方法结束
} // LoadImageApplet 类结束
/**************************************************************************
* (C) Copyright 2004-2005 by Jingkui Zhong(钟京馗) and Huan Tang(唐桓). *
* All Rights Reserved. *
* *
* DISCLAIMER: The authors of this code have used their *
* best efforts in preparing the code. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these codes. The authors *
* shall not be liable in any event for incidental or consequential *
* damages in connection with, or arising out of, the furnishing, *
* performance, or use of these programs. *
**************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -