home *** CD-ROM | disk | FTP | other *** search
- import beeper.Beeper;
- import beeper.IBeeper;
- import com.ms.com.ComException;
- import java.applet.Applet;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Event;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.awt.Rectangle;
- import java.awt.Toolkit;
- import java.awt.Window;
- import java.awt.image.ImageObserver;
-
- public class javabeep extends Applet implements Runnable {
- IBeeper m_Beeper;
- Thread m_javabeep;
- private Graphics m_Graphics;
- private Image[] m_Images;
- private int m_nCurrImage;
- private int m_nImgWidth;
- private int m_nImgHeight;
- private boolean m_fAllLoaded;
- private final int NUM_IMAGES = 18;
- boolean m_fStandAlone;
-
- public void start() {
- if (this.m_javabeep == null) {
- this.m_javabeep = new Thread(this);
- this.m_javabeep.start();
- }
-
- this.m_Beeper = (IBeeper)(new Beeper());
- }
-
- public void stop() {
- if (this.m_javabeep != null) {
- this.m_javabeep.stop();
- this.m_javabeep = null;
- }
-
- }
-
- public boolean mouseDown(Event evt, int x, int y) {
- String BeeperString = new String();
-
- try {
- this.m_Beeper.Beep();
-
- for(int i = 1; i <= this.m_Beeper.getCount(); ++i) {
- BeeperString = BeeperString + this.m_Beeper.getItem(i) + " ";
- }
- } catch (ComException var7) {
- BeeperString = "Error from Beeper.Beep: handled in mouseDown method";
- }
-
- this.m_Graphics.drawString(BeeperString, x, y);
- return true;
- }
-
- private void displayImage(Graphics g) {
- if (this.m_fAllLoaded) {
- g.drawImage(this.m_Images[this.m_nCurrImage], (((Component)this).size().width - this.m_nImgWidth) / 2, (((Component)this).size().height - this.m_nImgHeight) / 2, (ImageObserver)null);
- FontMetrics fm = ((Component)this).getFontMetrics(((Component)this).getFont());
- String message = new String("Click me with the mouse!");
- g.drawString(message, (((Component)this).size().width - fm.stringWidth(message)) / 2, 3 * ((Component)this).size().height / 4);
- }
- }
-
- public String getAppletInfo() {
- return "Name: javabeep\r\n" + "Author: Steve Horn\r\n" + "Created with Microsoft Visual J++ Version 1.0";
- }
-
- public void run() {
- this.m_nCurrImage = 0;
- if (!this.m_fAllLoaded) {
- ((Component)this).repaint();
- this.m_Graphics = ((Component)this).getGraphics();
- this.m_Images = new Image[18];
- MediaTracker tracker = new MediaTracker(this);
- int i = 1;
-
- do {
- String strImage = "images/img00" + (i < 10 ? "0" : "") + i + ".gif";
- if (this.m_fStandAlone) {
- this.m_Images[i - 1] = Toolkit.getDefaultToolkit().getImage(strImage);
- } else {
- this.m_Images[i - 1] = ((Applet)this).getImage(((Applet)this).getDocumentBase(), strImage);
- }
-
- tracker.addImage(this.m_Images[i - 1], 0);
- ++i;
- } while(i <= 18);
-
- try {
- tracker.waitForAll();
- this.m_fAllLoaded = !tracker.isErrorAny();
- } catch (InterruptedException var5) {
- }
-
- if (!this.m_fAllLoaded) {
- this.stop();
- this.m_Graphics.drawString("Error loading images!", 10, 40);
- return;
- }
-
- this.m_nImgWidth = this.m_Images[0].getWidth(this);
- this.m_nImgHeight = this.m_Images[0].getHeight(this);
- }
-
- ((Component)this).repaint();
-
- while(true) {
- try {
- this.displayImage(this.m_Graphics);
- ++this.m_nCurrImage;
- if (this.m_nCurrImage == 18) {
- this.m_nCurrImage = 0;
- }
-
- Thread.sleep(50L);
- } catch (InterruptedException var6) {
- this.stop();
- }
- }
- }
-
- public void destroy() {
- }
-
- public static void main(String[] args) {
- javabeepFrame frame = new javabeepFrame("javabeep");
- ((Window)frame).show();
- ((Component)frame).hide();
- ((Component)frame).resize(((Container)frame).insets().left + ((Container)frame).insets().right + 320, ((Container)frame).insets().top + ((Container)frame).insets().bottom + 240);
- javabeep applet_javabeep = new javabeep();
- ((Container)frame).add("Center", applet_javabeep);
- applet_javabeep.m_fStandAlone = true;
- applet_javabeep.init();
- applet_javabeep.start();
- ((Window)frame).show();
- }
-
- public void init() {
- ((Applet)this).resize(320, 240);
- }
-
- public void paint(Graphics g) {
- if (this.m_fAllLoaded) {
- Rectangle r = g.getClipRect();
- g.clearRect(r.x, r.y, r.width, r.height);
- this.displayImage(g);
- } else {
- g.drawString("Loading images...", 10, 20);
- }
-
- }
- }
-