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

📄 mediatrackerapplet.java

📁 提供 精通Java Web动态图表编程 一书的源代码, 大家赶快下载呀
💻 JAVA
字号:
// Fig. 2.11_02: MediaTrackerApplet.java
// 用MediaTracker加载图像

import java.awt.*; // 引入 java.awt包中所有的类
import javax.swing.*; // 引入 javax.swing包中所有的类

public class MediaTrackerApplet extends JApplet
{
  private Image[] images = new Image[3];
  private Image bg; // 背景图像
  private MediaTracker mt = null;

  // 初始化
  public void init()
  {
    bg = getImage(getCodeBase(), "images/background.gif");

    // 初始化MediaTracker
    mt = new MediaTracker(this);
    mt.addImage(bg, 0);

    for (int i = 0; i < images.length; i++)
    {
      images[i] = getImage(getCodeBase(), "images/logo" + (i + 1) + ".jpg");
      mt.addImage(images[i], i + 1);
    }
  }


  public void paint(Graphics g)
  {
    try
    {
      mt.waitForAll();
    }
    catch (InterruptedException e)
    {
      System.out.println(e);
      return ;
    }

    if (mt.isErrorAny())
    {
      for (int i = 0; i <= 4; i++)
      {
        if (mt.isErrorID(i))
        {
          g.drawString("图像产生错误状况!文件标志为:" + i, 10, 40 + 20 * i);
        }
      }

      return ;
    }

    g.drawImage(bg, 0, 0, this);
	
	g.setFont(new Font("汉真广标", Font.PLAIN, 30));

    g.drawString("MediaTracker 的使用", 15, 30);

    for (int i = 0; i < 3; i++)
    {
      g.drawImage(images[i], 410, 40+i * 100, this);
    }

  }
}

/**************************************************************************
 * (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 + -