java
1import javax.swing.*; 2import java.awt.event.*; 3 4public class SwingTest extends JFrame implements ActionListener{ 5 JLabel label; 6 7 public static void main(String[] args){ 8 SwingTest test = new SwingTest("SwingTest"); 9 10 test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 11 test.setVisible(true); 12 } 13 14 SwingTest(String title){ 15 setTitle(title); 16 setBounds( 10, 10, 300, 200); 17 18 label = new JLabel(""); 19 20 JButton btn = new JButton("Push"); 21 btn.addActionListener(this); 22 23 JPanel p = new JPanel(); 24 p.add(label); 25 p.add(btn); 26 27 getContentPane().add(p); 28 } 29 30 public void actionPerformed(ActionEvent e){ 31 label.setText("Push"); 32 } 33}
ActionEventの使い方について調べていたら、上記のようなサンプルコードを見かけたのですが
このコードにおける btn.addActionListener(this)の this は何を指しているのでしょうか?
またthis以外で表現する方法はありますか?
thisは継承をしたときに
this.自分のクラスのメソッド、または変数
super.スーパークラスのメソッド、または変数
などと使うことは知っていたのですが、this単体だと何を指しているのかわからないです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/09 02:18 編集
2018/11/09 02:26
2018/11/09 06:20
2018/11/09 06:33
2018/11/12 06:51
2018/11/13 01:50
2018/11/13 01:54