import javax.swing.*;
import java.awt.event.*;

public class ActionFirst extends JFrame implements ActionListener...{


public static void main(String[] args) ...{
new ActionFirst();
}

public void actionPerformed(ActionEvent e)...{
//静态方法。不用声明
JOptionPane.showMessageDialog(this,"小子你打错了。重来!!");
}
public ActionFirst() ...{
super("action first");
JButton b=new JButton("click");
this.getContentPane().add(b);
b.addActionListener(this);//注册监听
this.setSize(200,300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//使关闭叉可用
}
}
Java Swing 示例
本文介绍了一个简单的 Java Swing 应用程序示例,展示了如何创建带有按钮的窗口,并为按钮添加动作监听器,当按钮被点击时会弹出消息对话框。
2533

被折叠的 条评论
为什么被折叠?



