import java.applet.Applet; import java.awt.*; /** * Flashnavi風アプレットの本体です. * ロゴ, およびticker用のスレッドを作成したあと, 自分自身もスレッドになります. * 10秒待ってから, 画面を切り替えます. * * @author Kawaguchi Koji * @version 1.0 */ public class Fnavi extends Applet implements Runnable { /** * ダブルバッファ用のオフラインイメージです. */ Image offimage; /** * offimage 用のグラフィック・コンテキストです. */ Graphics offgraphics; /** * ロゴ表示用スレッドです. */ LogoThread logothread; /** * Ticker表示用スレッドです. */ TickerThread tickerthread; /** * ロゴイメージです. */ Image logoimage; /** * ロゴ表示用スレッドで使うフォントです. */ Font logofont; /** * Ticker表示用スレッドで使うフォントです. */ Font tickerfont; /** * 画面サイズです. */ int scrx, scry; /** * 画面の表示モードです. * 初期画面なら true, サイト表示画面なら false です. */ boolean logoflying; /** * 自分自身のクラスです. * 他のクラスと、メソッドの呼び出し表記を合わせるために使います. */ private Fnavi fnavi = this; /** * 初期化メソッドです. * HTMLファイルからパラメータを読み出します. * ロゴイメージの読み出しや, オフラインイメージの作成などを行います. */ public void init() { int tickerfontsize, logofontsize; // パラメータの読み込み try { scrx = Integer.parseInt(getParameter("width")); scry = Integer.parseInt(getParameter("height")); tickerfontsize = Integer.parseInt(getParameter("tickerfontsize")); logofontsize = Integer.parseInt(getParameter("logofontsize")); } catch (NumberFormatException e) { fnavi.o("xsize, ysize, tickerfontsize error."); scrx = 320; scry = 240; tickerfontsize = 10; logofontsize = 16; } logoimage = getImage(getCodeBase(), getParameter("logoimage")); tickerfont = new Font(getParameter("tickerfont"), Font.PLAIN, tickerfontsize); logofont = new Font(getParameter("logofont"), Font.BOLD, logofontsize); // offline imageの作成 offimage = createImage(scrx, scry); offgraphics = offimage.getGraphics(); offgraphics.setColor(Color.black); offgraphics.fillRect(0, 0, scrx, scry); } /** * 開始メソッドです. * スレッドを起動して, 自分自身をスレッドとして動かします. */ public void start() { fnavi.o("fnavi.start"); // 画像の準備 MediaTracker mt = new MediaTracker(this); mt.addImage(logoimage, 0); try { mt.waitForAll(); } catch (InterruptedException e) { fnavi.o(e.toString()); } if (tickerthread == null) { // スレッドの作成 FontMetrics fm = getFontMetrics(tickerfont); tickerthread = new TickerThread(this, new Point(0, scry - fm.getHeight()*2), new Dimension(scrx, fm.getHeight()), tickerfont, offgraphics); } if (logothread == null) { // スレッドの作成 logothread = new LogoThread(this, new Dimension(scrx, scry - tickerthread.getRect().height * 2), offgraphics, logoimage, logofont); } // スレッドの起動 logoflying = true; logothread.start(); tickerthread.start(); // 自分自身をスレッドとして起動 Thread me = new Thread(this); me.start(); } /** * スレッドの本体です. * 10秒待ってから, 初期画面から表示画面に切り替えます. */ public void run() { // 待ち時間 try { Thread.sleep(10000); } catch (InterruptedException e) {} // スクリーンに文字を表示 logoflying = false; } /** * 停止メソッドです. * スレッドを停止させます. */ public void stop() { fnavi.o("fnavi.stop"); if (logothread != null) { logothread.stop(); logothread = null; } if (tickerthread != null) { tickerthread.tostop(); tickerthread.stop(); tickerthread = null; } } /** * 画面の再描画リクエストを発生します. */ void redraw() { repaint(); } /** * ペイントメソッドです. * オフラインイメージをスクリーンに表示します. * * @param g グラフィックコンテキスト */ public void paint(Graphics g) { g.drawImage(offimage, 0, 0, this); } /** * 更新メソッドです. * paintメソッドを呼び出すだけです. * * @param g グラフィックコンテキスト */ public void update(Graphics g) { paint(g); } /** * 画面の表示モードを取得します. * * @return 初期画面なら true, サイト表示画面なら false を返します. * @see #logoflying */ boolean getLogoFlying() { return logoflying; } /** * ログを出力します. * * @param s 出力する文字列 */ void o(String s) { System.out.println(s); } }