classes/RevName2.java
import browser.Applet;
import awt.Graphics;
import awt.Color;
import awt.Font;
/**
マウスの操作で表示が反転するアプレット RevName のクラス定義
*/
class RevName extends Applet {
/**
表示する文字列
*/
public String message = "Fujio Maruyama";
/**
マウスボタンが押されているかどうかを示すフラグ
*/
private boolean stateFlag = false;
/**
初期設定を行う。フォントとアプレットのサイズを調整
*/
protected void init() {
this.font = getFont( "TimesRoman", Font.ITALIC, 24 );
width = this.font.stringWidth( message ) + 10;
resize( width, 32 );
}
/**
アプレットにグラフィックを描く。
最初の表示の時には自動的に、後は repaint() によって呼び出される。
*/
public void paint( Graphics g ) {
/*
マウスボタンが押されている
*/
if( stateFlag == false ) {
g.setForeground( Color.black );
g.paint3DRect( 0, 0, width, 32, true, false );
g.setForeground( Color.yellow );
g.drawString( message, 5, 22 );
}
/*
マウスボタンが放されている
*/
else {
g.setForeground( Color.yellow );
g.paint3DRect( 0, 0, width, 32, true, true );
g.setForeground( Color.black );
g.drawString( message, 5, 22 );
}
}
/**
マウスボタンが押された時に自動的に呼び出される。
*/
public void mouseDown( int x, int y ) {
stateFlag = true;
repaint(); // paint() を呼び出す
}
/**
マウスボタンが放された時に自動的に呼び出される。
*/
public void mouseUp( int x, int y ) {
stateFlag = false;
repaint(); // paint() を呼び出す
}
}