⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 secretlabel.java

📁 java swing 开发代码
💻 JAVA
字号:
// SecretLabel.java// An extension of the JLabel class that listens to mouse clicks and converts// them to ActionEvents, which in turn are reported via an EventListenersList // object//package	jswing.ch27;import java.awt.event.*;import javax.swing.*;public class SecretLabel extends JLabel {  public SecretLabel(String msg) {    super(msg);    addMouseListener(new MouseAdapter() {      public void mouseClicked(MouseEvent me) {        fireActionPerformed(new ActionEvent(SecretLabel.this,                                             ActionEvent.ACTION_PERFORMED,                                             "SecretMessage"));      }    });  }  public void addActionListener(ActionListener l) {    // We'll just use the listenerList we inherit from JComponent.    listenerList.add(ActionListener.class, l);  }  public void removeActionListener(ActionListener l) {    listenerList.remove(ActionListener.class, l);  }  protected void fireActionPerformed(ActionEvent ae) {    Object[] listeners = listenerList.getListeners(ActionListener.class);    for (int i = 0; i < listeners.length; i++) {      ((ActionListener)listeners[i]).actionPerformed(ae);    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -