用NetBeans创建GUI

来源:百度知道 编辑:UC知道 时间:2024/06/05 00:24:17
我用netbeans拖了一个界面,但不知道如何加监听事件。我的例子也都是没有监听的。jframe有个事件 属性,但我不知道如何用。在Eclipse中都是代码敲进去的。这个不会搞。
请问谁能给个按钮的监听例子?谢谢大哥!

import java.awt.Container;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;

public class ButtonListener
{
public static void main(String[] args)
{
LoginFrame frame=new LoginFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class LoginFrame extends JFrame//定义登录框架
{
private JButton forgotButton;//找回密码

public LoginFrame()//构造函数
{
setTitle("QQ用户登录");
setBounds(344,244,330,240);
setResizable(false);
JPanel textPanel=new JPanel();//定义文本面板
Container contentPane=getContentPane();//得到窗口框架
forgotButton=new JButton("忘记密码");
forgotButton.setBounds(275, 104, 87, 22);
forgotButton.addActionListener(new ActionListener()//