20130513【Java】(アプレット)ボタンを使う
お題
(アプレット)ボタンを使う
ボタンを押して背景色を変更する
ソース
import java.awt.*;
public class ButtonSample extends java.applet.Applet {
public void init() {
add(new Button("Red"));
add(new Button("Green"));
add(new Button("Blue"));
}
public boolean action(Event e, Object obj){
if(obj.equals("Red")){
setBackground(Color.red);
} else if(obj.equals("Green")){
setBackground(Color.green);
} else if(obj.equals("Blue")) {
setBackground(Color.blue);
}
return true;
}
}
実行結果
