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

📄 appletlauncher.java

📁 利用設定來製作簡易地 applet, 可以很快速的寫出 applet 來.
💻 JAVA
字号:
/* Thinlet GUI toolkit - www.thinlet.com
 * Copyright (C) 2002-2003 Robert Bajzat (robert.bajzat@thinlet.com) */
package thinlet;

import java.applet.*;
import java.awt.*;

/**
 * <code>AppletLauncher</code> is a double buffered applet
 * to launch any <i>thinlet</i> component
 */
public class AppletLauncher extends Applet implements Runnable {
	
	private transient Thinlet content;
	private transient Image doublebuffer;
	
	/**
	 * Applet instance is created by the browser or applet viewer
	 */
	public AppletLauncher() {
		super(); // for javadoc
	}
	
	/**
	 * Called by the browser to inform this applet that it has been loaded into
	 * the system, it displays the <i>Loading...</i> label and starts the loader thread
	 */
	public void init() {
		setBackground(Color.white); setForeground(Color.darkGray);
		setLayout(new BorderLayout());
		add(new Label("Loading...", Label.CENTER), BorderLayout.CENTER);
		new Thread(this).start();
	}
	
	/**
	 * Create a new <i>thinlet</i> instance of the class given as
	 * <code>class</code> applet parameter, and show it or the
	 * message of the thrown exception. First try a contructor with
	 * an applet parameter (thus you get this applet instance e.g. for
	 * the parameters of the applet HTML tag), then the empty constructor
	 */
	public void run() {
		try {
			Class thinletclass = Class.forName(getParameter("class"));
			try {
				content = (Thinlet) thinletclass.getConstructor(new Class[] {
					Applet.class }).newInstance(new Object[] { this });
			} catch (NoSuchMethodException nsme) {
				content = (Thinlet) thinletclass.newInstance();
			}
			removeAll();
			add(content, BorderLayout.CENTER);
		} catch (Throwable exc) {
			removeAll();
			add(new Label(exc.getClass().getName() + " " +
				exc.getMessage(), Label.CENTER), BorderLayout.CENTER);
		}
		doLayout(); repaint();
	}
	
	/**
	 * Clear the double buffer image, the overriden method lays out its
	 * components (centers the <i>thinlet</i> component)
	 */
	public void doLayout() {
		super.doLayout();
		if (doublebuffer != null) {
			doublebuffer.flush();
			doublebuffer = null;
		}
	}
	
	/**
	 * Called by the browser to inform this applet that it should stop its execution,
	 * it clears the double buffer image
	 */
	public void stop() {
		if (doublebuffer != null) {
			doublebuffer.flush();
			doublebuffer = null;
		}
	}
	
	/**
	 * Call the paint method to redraw this component without painting a
	 * background rectangle
	 */
	public void update(Graphics g) {
		paint(g);
	}

	/**
	 * Create a double buffer if needed,
	 * the <i>thinlet</i> component paints the content
	 */
	public void paint(Graphics g) { 
		if (doublebuffer == null) {
			Dimension d = getSize();
			doublebuffer = createImage(d.width, d.height);
		}
		Graphics dg = doublebuffer.getGraphics();
		dg.setClip(g.getClipBounds());
		super.paint(dg);
		dg.dispose();
		g.drawImage(doublebuffer, 0, 0, this);
	}
	
	/**
	 * Called by the browser to inform this applet that it is being reclaimed,
	 * it calls the <i>thinlet</i> component's <code>destroy</code> method
	 * (its return value is irrelevant)
	 */
	public void destroy() {
		content.destroy();
	}
}

⌨️ 快捷键说明

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