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

📄 appletframe.java

📁 本代码为java编写的泡泡龙游戏
💻 JAVA
字号:

import java.applet.Applet;
import java.applet.AppletContext;
import java.applet.AppletStub;
import java.applet.AudioClip;

import java.awt.Frame;
import java.awt.Image;
import java.awt.Toolkit;

import java.awt.event.WindowListener;
import java.awt.event.WindowEvent;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import java.net.MalformedURLException;
import java.net.URL;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;

/**
 * <p>A Frame for running an Applet so the applet can run as an application.
 */
public class AppletFrame extends Frame implements AppletStub, AppletContext, WindowListener 
{

    GameApplet applet;
    Hashtable props = new Hashtable ();
      
    /**
     * Construct a Frame of the given size to run the given Applet
     *
     * @param name the Frames title
     * @param applet the applet to run
     * @param width width of the game frame
     * @param height height of the game frame
     */
    public AppletFrame (String name, GameApplet applet, int width, int height) {
        
        super (name);
        this.applet = applet;
        applet.setStub (this);
        applet.setAsApplication();
        
        // Get insets
        show ();
        width += this.getInsets().left + this.getInsets().right;
        height += this.getInsets().top + this.getInsets().bottom;
        hide ();
        
        setSize (width, height);
        this.add ("Center", applet);
        show ();
        //注册窗口事件
        addWindowListener (this);

        applet.init ();
        applet.start ();
    }

    // AppletStub API
    //当Applet要重新调整大小时调用
    public void appletResize (int width, int height) {
        setSize (width, height);
    }
    //获取applet上下文的处理程序。
    public AppletContext getAppletContext () {
        return this;
    }
    //获取基 URL
    public URL getCodeBase () {
        URL u = null;
        try { 
            u = new File (System.getProperty ("user.dir")).toURL (); 
        }
        catch (MalformedURLException me) {}
        
        return u;
  }
    //获取嵌入 applet 的文档的 URL
    public URL getDocumentBase () {
        URL u = null;
        try { 
            u = new File (System.getProperty ("user.dir")).toURL (); 
        }
        catch (MalformedURLException me) {}
        
        return u;
  }
    //返回 HTML 标记中命名参数的值
    public String getParameter (String name) {
        return (String) props.get (name);
    }
     //设置 HTML 标记中命名参数的值
    public void setParameter (String name, String value) {
        props.put (name, value);
    }
    //确定 applet 是否处于激活状态
    public boolean isActive () {
        return true;
    }

    // AppletContext API
    //使用给定的名称找到并返回此 applet 上下文所代表的文档中的 applet。
    public Applet getApplet (String name) {
        return applet;
    }
    //找到此 applet 上下文所代表的文档中的所有 applet。
    public Enumeration getApplets () {
        return null;
    }
    //创建音频剪辑
    public AudioClip getAudioClip (URL url) {
        return Applet.newAudioClip (url);
    }
    //返回能被绘制到屏幕上的 Image 对象
    public Image getImage (URL url) {
        return Toolkit.getDefaultToolkit ().getImage (url);
    }

    public void showDocument (URL url) {}
    public void showDocument (URL url, String target) {}
    //请求参数字符串显示在 "status window" 中。
    public void showStatus (String status) {
        System.out.println (status);
    }

    public void setStream (String key, InputStream stream) throws IOException {}
    //返回此 applet 上下文中指定键所关联的流。
    public InputStream getStream (String key) {
        return null;
    }
    //找到此 applet 上下文中所有流对应的键
    public Iterator getStreamKeys () {
        return null;
    }
  
    // Windowlistener interface
    //关闭窗口
    public void windowClosing(WindowEvent e) {
        AppletFrame.this.applet.stop ();
        dispose ();
        System.exit (0);
    }
        
    public void windowActivated(WindowEvent e) {}
    public void windowClosed(WindowEvent e) {}
    public void windowDeactivated(WindowEvent e) {}
    public void windowDeiconified(WindowEvent e) {}
    public void windowIconified(WindowEvent e) {}
    public void windowOpened(WindowEvent e) {}
     
}

⌨️ 快捷键说明

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