SimpleEvent.java
资源名称:Source.rar [点击查看]
上传用户:songled
上传日期:2022-07-14
资源大小:94k
文件大小:1k
源码类别:
进程与线程
开发平台:
Java
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class SimpleEvent extends Object {
- private static void print(String msg) {
- String name = Thread.currentThread().getName();
- System.out.println(name + ": " + msg);
- }
- public static void main(String[] args) {
- final JLabel label = new JLabel("--------");
- JButton button = new JButton("Click Here");
- JPanel panel = new JPanel(new FlowLayout());
- panel.add(button);
- panel.add(label);
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- print("in actionPerformed()");
- label.setText("CLICKED!");
- }
- });
- JFrame f = new JFrame("SimpleEvent");
- f.setContentPane(panel);
- f.setSize(300, 100);
- f.setVisible(true);
- }
- }