【发布时间】:2016-05-26 08:15:43
【问题描述】:
我最近在 Java 方面学到了很多东西,但有些东西确实困扰着我。例如,当程序涉及构造函数时,我学习/被教导如何使用 ActionListeners,
public class test extends JFrame implements ActionListener {
JButton button;
public test
{
setLayout(null);
setSize(1920,1080);
setTitle("test");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
button = new JButton("");
button.setBounds(x,x,x,x);
button.AddActionListener(this); //What can replace the this parameter here.
button.setVisible(true);
add(button);
}
public static void main(String[] args) {
test testprogram = new test();
test.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent clickevent) {
if (clickevent.GetSource() == button) {
//DoSomething
}
}
【问题讨论】:
-
看看javadoc
标签: java button this actionlistener frames