| componentHiddeen | コンポーネントが非表示になった時に発生する |
|---|---|
| componentShown | コンポーネントが表示されたときに発生する |
| componentMoved | コンポーネントが移動したときに発生する |
| componentResized | コンポーネントがリサイズしたときに発生する |
ComponentAdapterクラス:ComponentListenerインターフェースを実装済みのクラスです。
以下のコードはcomponentHiddeenイベントとcomponentShownイベントの使用例です。
public class ComponentEventSample {
/*
* アプリケーションエントリーポイント
*/
public static void main(String args[]){
new ComponentEventSample();
}
Frame frm;
TextField txt1;
Button btn1;
Label lbl1;
/*
* コンストラクタ
*/
public ComponentEventSample(){
this.frm = new Frame("ComponentEventSample");
frm.setSize(300,400);
frm.setLayout(new GridLayout(3,1));
frm.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent ev){
System.exit(0);
}
});
this.txt1 = new TextField();
txt1.setSize(10,20);
txt1.setBackground(Color.blue);
txt1.addComponentListener(new MyComponetAdapter());
frm.add(txt1);
this.btn1 = new Button();
btn1.setLabel("Visible");
btn1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
txt1.setVisible(!txt1.isShowing());
}
});
frm.add(btn1);
this.lbl1 = new Label();
frm.add(lbl1);
frm.setVisible(true);
}
private class MyComponetAdapter extends ComponentAdapter{
public void componentHidden(ComponentEvent ev){
lbl1.setText("componentHidden: txt1 is Hidden" );
}
public void componentShown(ComponentEvent ev){
lbl1.setText("componentHidden: txt1 is Shown" );
}
}
}
0 件のコメント:
コメントを投稿