class ClickAction implementsまあ、ざっとこんな感じですね。――ところが、これをコンパイルすると、エラーが起きるはずです。「mylabelって変数がわからない」といわれます。
ActionListener {
public void actionPerformed(ActionEvent ev){
mylabel.setText("You are clicked!");
}
}
※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
import java.awt.*; import java.awt.event.*; public class Test5 extends Frame { Label mylabel; Button mybutton; public Test5() { super(); setTitle("Hello"); setSize(300,150); setLayout(null); mylabel = new Label("Hello World."); mylabel.setBounds(50,50,200,30); this.add(mylabel); mybutton = new Button("OK"); mybutton.setBounds(100,100,100,25); this.add(mybutton); mybutton.addActionListener(new ClickAction()); } public static void main (String args []) { new Test5().setVisible(true); } class ClickAction implements ActionListener { public void actionPerformed(ActionEvent ev){ mylabel.setText("You are clicked!"); } } }
<< 前へ |