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

📄 mediatracker.java

📁 《移动Agent技术》一书的所有章节源代码。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

    /**
     * Returns a list of all media that have encountered an error.
     * @return       an array of media objects tracked by this 
     *                        media tracker that have encountered 
     *                        an error, or <code>null</code> if 
     *                        there are none with errors.
     * @see          java.awt.MediaTracker#isErrorAny
     * @see          java.awt.MediaTracker#getErrorsID
     * @since        JDK1.0
     */
    public synchronized Object[] getErrorsAny() {
	MediaEntry cur = head;
	int numerrors = 0;
	while (cur != null) {
	    if ((cur.getStatus(false, true) & ERRORED) != 0) {
		numerrors++;
	    }
	    cur = cur.next;
	}
	if (numerrors == 0) {
	    return null;
	}
	Object errors[] = new Object[numerrors];
	cur = head;
	numerrors = 0;
	while (cur != null) {
	    if ((cur.getStatus(false, false) & ERRORED) != 0) {
		errors[numerrors++] = cur.getMedia();
	    }
	    cur = cur.next;
	}
	return errors;
    }

    /**
     * Starts loading all images tracked by this media tracker. This 
     * method waits until all the images being tracked have finished 
     * loading. 
     * <p>
     * If there is an error while loading or scaling an image, then that 
     * image is considered to have finished loading. Use the 
     * <code>isErrorAny</code> or <code>isErrorID</code> methods to 
     * check for errors. 
     * @see         java.awt.MediaTracker#waitForID(int)
     * @see         java.awt.MediaTracker#waitForAll(long)
     * @see         java.awt.MediaTracker#isErrorAny
     * @see         java.awt.MediaTracker#isErrorID
     * @exception   InterruptedException  if another thread has 
     *                                     interrupted this thread.
     * @since       JDK1.0
     */
    public void waitForAll() throws InterruptedException {
	waitForAll(0);
    }

    /**
     * Starts loading all images tracked by this media tracker. This 
     * method waits until all the images being tracked have finished 
     * loading, or until the length of time specified in milliseconds  
     * by the <code>ms</code> argument has passed. 
     * <p>
     * If there is an error while loading or scaling an image, then  
     * that image is considered to have finished loading. Use the 
     * <code>isErrorAny</code> or <code>isErrorID</code> methods to 
     * check for errors. 
     * @param       ms       the number of milliseconds to wait 
     *                       for the loading to complete.
     * @return      <code>true</code> if all images were successfully 
     *                       loaded; <code>false</code> otherwise.
     * @see         java.awt.MediaTracker#waitForID(int)
     * @see         java.awt.MediaTracker#waitForAll(long)
     * @see         java.awt.MediaTracker#isErrorAny
     * @see         java.awt.MediaTracker#isErrorID
     * @exception   InterruptedException  if another thread has 
     *                                     interrupted this thread.
     * @since       JDK1.0
     */
    public synchronized boolean waitForAll(long ms)
	throws InterruptedException
    {
	long end = System.currentTimeMillis() + ms;
	boolean first = true;
	while (true) {
	    int status = statusAll(first, first);
	    if ((status & LOADING) == 0) {
		return (status == COMPLETE);
	    }
	    first = false;
	    long timeout;
	    if (ms == 0) {
		timeout = 0;
	    } else {
		timeout = end - System.currentTimeMillis();
		if (timeout <= 0) {
		    return false;
		}
	    }
	    wait(timeout);
	}
    }

    /**
     * Calculates and returns the bitwise inclusive <b>OR</b> of the 
     * status of all media that are tracked by this media tracker. 
     * <p>
     * Possible flags defined by the 
     * <code>MediaTracker</code> class are <code>LOADING</code>, 
     * <code>ABORTED</code>, <code>ERRORED</code>, and 
     * <code>COMPLETE</code>. An image that hasn't started 
     * loading has zero as its status. 
     * <p>
     * If the value of <code>load</code> is <code>true</code>, then
     * this method starts loading any images that are not yet being loaded. 
     * @param        load   if <code>true</code>, start loading 
     *                            any images that are not yet being loaded.
     * @return       the bitwise inclusive <b>OR</b> of the status of 
     *                            all of the media being tracked.
     * @see          java.awt.MediaTracker#statusID(int, boolean)
     * @see          java.awt.MediaTracker#LOADING
     * @see          java.awt.MediaTracker#ABORTED
     * @see          java.awt.MediaTracker#ERRORED
     * @see          java.awt.MediaTracker#COMPLETE
     * @since        JDK1.0
     */
    public int statusAll(boolean load) {
	return statusAll(load, true);
    }

    private synchronized int statusAll(boolean load, boolean verify) {
	MediaEntry cur = head;
	int status = 0;
	while (cur != null) {
	    status = status | cur.getStatus(load, verify);
	    cur = cur.next;
	}
	return status;
    }

    /**
     * Checks to see if all images tracked by this media tracker that 
     * are tagged with the specified identifier have finished loading. 
     * <p>
     * This method does not start loading the images if they are not 
     * already loading. 
     * <p>
     * If there is an error while loading or scaling an image, then that 
     * image is considered to have finished loading. Use the 
     * <code>isErrorAny</code> or <code>isErrorID</code> methods to 
     * check for errors. 
     * @param       id   the identifier of the images to check.
     * @return      <code>true</code> if all images have finished loading, 
     *                       have been aborted, or have encountered 
     *                       an error; <code>false</code> otherwise.
     * @see         java.awt.MediaTracker#checkID(int, boolean)
     * @see         java.awt.MediaTracker#checkAll()
     * @see         java.awt.MediaTracker#isErrorAny()
     * @see         java.awt.MediaTracker#isErrorID(int)
     * @since       JDK1.0
     */
    public boolean checkID(int id) {
	return checkID(id, false, true);
    }

    /**
     * Checks to see if all images tracked by this media tracker that 
     * are tagged with the specified identifier have finished loading. 
     * <p>
     * If the value of the <code>load</code> flag is <code>true</code>, 
     * then this method starts loading any images that are not yet 
     * being loaded. 
     * <p>
     * If there is an error while loading or scaling an image, then that 
     * image is considered to have finished loading. Use the 
     * <code>isErrorAny</code> or <code>isErrorID</code> methods to 
     * check for errors. 
     * @param       id       the identifier of the images to check.
     * @param       load     if <code>true</code>, start loading any 
     *                       images that are not yet being loaded.
     * @return      <code>true</code> if all images have finished loading, 
     *                       have been aborted, or have encountered 
     *                       an error; <code>false</code> otherwise.
     * @see         java.awt.MediaTracker#checkID(int, boolean)
     * @see         java.awt.MediaTracker#checkAll()
     * @see         java.awt.MediaTracker#isErrorAny()
     * @see         java.awt.MediaTracker#isErrorID(int)
     * @since       JDK1.0
     */
    public boolean checkID(int id, boolean load) {
	return checkID(id, load, true);
    }

    private synchronized boolean checkID(int id, boolean load, boolean verify)
    {
	MediaEntry cur = head;
	boolean done = true;
	while (cur != null) {
	    if (cur.getID() == id
		&& (cur.getStatus(load, verify) & DONE) == 0)
	    {
		done = false;
	    }
	    cur = cur.next;
	}
	return done;
    }

    /**
     * Checks the error status of all of the images tracked by this 
     * media tracker with the specified identifier. 
     * @param        id   the identifier of the images to check.
     * @return       <code>true</code> if any of the images with the 
     *                          specified identifier had an error during 
     *                          loading; <code>false</code> otherwise.
     * @see          java.awt.MediaTracker#isErrorAny
     * @see          java.awt.MediaTracker#getErrorsID
     * @since        JDK1.0
     */
    public synchronized boolean isErrorID(int id) {
	MediaEntry cur = head;
	while (cur != null) {
	    if (cur.getID() == id
		&& (cur.getStatus(false, true) & ERRORED) != 0)
	    {
		return true;
	    }
	    cur = cur.next;
	}
	return false;
    }

    /**
     * Returns a list of media with the specified ID that 
     * have encountered an error.
     * @param       id   the identifier of the images to check.
     * @return      an array of media objects tracked by this media 
     *                       tracker with the specified identifier 
     *                       that have encountered an error, or 
     *                       <code>null</code> if there are none with errors.
     * @see         java.awt.MediaTracker#isErrorID
     * @see         java.awt.MediaTracker#isErrorAny
     * @see         java.awt.MediaTracker#getErrorsAny
     * @since       JDK1.0
     */
    public synchronized Object[] getErrorsID(int id) {
	MediaEntry cur = head;
	int numerrors = 0;
	while (cur != null) {
	    if (cur.getID() == id
		&& (cur.getStatus(false, true) & ERRORED) != 0)
	    {
		numerrors++;
	    }
	    cur = cur.next;
	}
	if (numerrors == 0) {
	    return null;
	}
	Object errors[] = new Object[numerrors];
	cur = head;
	numerrors = 0;
	while (cur != null) {
	    if (cur.getID() == id
		&& (cur.getStatus(false, false) & ERRORED) != 0)
	    {
		errors[numerrors++] = cur.getMedia();
	    }
	    cur = cur.next;
	}
	return errors;
    }

    /**
     * Starts loading all images tracked by this media tracker with the 
     * specified identifier. This method waits until all the images with 
     * the specified identifier have finished loading. 
     * <p>
     * If there is an error while loading or scaling an image, then that 
     * image is considered to have finished loading. Use the 
     * <code>isErrorAny</code> and <code>isErrorID</code> methods to 
     * check for errors. 
     * @param         id   the identifier of the images to check.
     * @see           java.awt.MediaTracker#waitForAll
     * @see           java.awt.MediaTracker#isErrorAny()
     * @see           java.awt.MediaTracker#isErrorID(int)
     * @exception     InterruptedException  if another thread has 
     *                          interrupted this thread.
     * @since         JDK1.0
     */
    public void waitForID(int id) throws InterruptedException {
	waitForID(id, 0);
    }

    /**
     * Starts loading all images tracked by this media tracker with the 
     * specified identifier. This method waits until all the images with 
     * the specified identifier have finished loading, or until the 
     * length of time specified in milliseconds by the <code>ms</code> 
     * argument has passed. 
     * <p>
     * If there is an error while loading or scaling an image, then that 
     * image is considered to have finished loading. Use the 
     * <code>statusID</code>, <code>isErrorID</code>, and
     * <code>isErrorAny</code> methods to check for errors. 
     * @param         id   the identifier of the images to check.
     * @param         ms   the length of time, in milliseconds, to wait 
     *                           for the loading to complete.
     * @see           java.awt.MediaTracker#waitForAll
     * @see           java.awt.MediaTracker#waitForID(int)
     * @see           java.awt.MediaTracker#statusID
     * @see           java.awt.MediaTracker#isErrorAny()

⌨️ 快捷键说明

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