ImpressMessage.java
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
/** メッセージを立体的に表示するImpressMessageクラス */
public class ImpressMessage extends Applet {
/** メッセージの内容 */
public String message=null;
/** メッセージのフォント */
public Font textFont=null;
/** フォントのサイズ */
public int fontSize=18;
/** 初期設定のメソッド(生成時に自動的に呼ばれる)*/
public void init() {
String size = getParameter("size");
String style = getParameter("style");
String family = getParameter("family");
fontSize=18;
if ( size != null )
if ( size.equals("large") )
fontSize=36;
else if ( size.equals("small") )
fontSize=14;
if ( family == null ) family = "TimesRoman";
textFont = new Font(family, Font.PLAIN, fontSize);
if ( style != null ) {
if ( style.equals("italic") )
textFont = new Font(family, Font.ITALIC, fontSize);
else if ( style.equals("bold") )
textFont = new Font(family, Font.BOLD, fontSize);
}
message = getParameter("message");
if ( message == null ) message = "Welcome to Wakkanai!";
// フォントに合わせてアプレットの表示サイズを調整
resize( getFontMetrics( textFont ).stringWidth( message ) + 8,
fontSize*3/2 );
}
/** 初期画面を描くメソッド(画面登場時に自動的に呼ばれる)*/
public void paint( Graphics g ) {
g.setFont( textFont );
g.setColor( Color.darkGray );
g.drawString( message, 3, fontSize ); // 影を描く
g.setColor( Color.white );
g.drawString( message, 5, fontSize + 2 ); // ハイライト
g.setColor( Color.lightGray );
g.drawString( message, 4, fontSize + 1 ); // 文字の本体
}
}