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

📄 imagebox.java

📁 WebHangman a game can be play on the website contain the total code of JAVA
💻 JAVA
字号:
package com.aztsoft.games.hangman;

import com.aztsoft.games.util.GameLogger;
import com.aztsoft.games.util.GoogleImageKit;

import java.awt.*;
import java.util.Vector;

/**
 * useful to draw images representing the words
 */
public class ImageBox {
    final static int kMAXIMAGES = 20;
    private static boolean securityAccessErrorOccured = false;
    String keyword;

    Vector imageVector = null;

    public ImageBox(String keyword) {
        this.keyword = keyword;
    }

    public void loadImages() {
        Thread mthread = new Thread() {
            public void run() {
                GameLogger.log("checking google for images on" + keyword);
                GoogleImageKit googleImageKit = new GoogleImageKit(keyword);
                try {
                    imageVector = googleImageKit.fetchVectorOfImages();
                } catch (java.security.AccessControlException ace) {
                    System.out.println("securityAccessErrorOccured - User has not accepted certificate,\nor certificate has expired - Will function without querrying for images.");
                    securityAccessErrorOccured = true;
                }
            }
        };
        if (!securityAccessErrorOccured) {
            mthread.start();
        }

    }

    private int counter = 0;

    public void paint(Graphics g, Dimension d, Component c) {
        if (imageVector != null) {
            if (imageVector.elementAt(counter) != null) {
                g.drawImage((Image) imageVector.elementAt((counter)), 50, 50, null);
            }
            if (imageVector.elementAt(counter + 1) != null) {
                Image tempImage = (Image) imageVector.elementAt(counter + 1);
                g.drawImage(tempImage, (int) d.getWidth() - 50 - tempImage.getWidth(c), 50, null);
            }
        }
    }

    public int getLength() {
        return imageVector.size();
    }

    public void changeImage() {
        if (imageVector != null) {

            if (counter >= imageVector.size() - 2) {
                counter = 0;
            } else {
                counter += 1;
            }
        }

    }

}

⌨️ 快捷键说明

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