java actionperformed_java中的事件处理和java中actionPerformed方法的...

我在java中为simpleGUI编写了一个小代码.

package guidemo1;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

public class GuiDemo1 implements ActionListener{

JButton button;

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

GuiDemo1 gui=new GuiDemo1();

gui.go();

}

public void go()

{

JFrame frame=new JFrame();

button=new JButton();

frame.getContentPane().add(button);

button.addActionListener(this);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setSize(300, 200);

frame.setVisible(true);

}

@Override

public void actionPerformed(ActionEvent e) {

//throw new UnsupportedOperationException("Not supported yet.");

button.setText("I've been clicked");

}

}

我是JAVA的新手.我对此计划几乎没有任何疑问.

有人可以解释一下如何在没有任何调用的情况下执行actionPerformed方法吗?

在这里我已经在go()方法本地定义了框架对象,我们在actionPerformed中使用了按钮,这是另一种方法.怎么可能?按钮是否嵌入到框架中?

谢谢..

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值