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

📄 newlabel2.java

📁 《java事件处理指南》一书的代码,好东西
💻 JAVA
字号:
import javax.swing.*;import java.awt.*;import java.beans.*;public class NewLabel2 extends JLabel implements PropertyChangeListener,                                                 VetoableChangeListener{   private FontColor2 fontColor;   public NewLabel2(String str, FontColor2 fc)   {      super(str);      fontColor = fc;      setForeground(fontColor.getColor());/*  When a NewLabel object is created, its FontColor object       *//*  registers both a PropertyChangeListener and a                 *//*  VetoableChangeListener.  These two listeners with implement   *//*  the color associated with the FontColor object as a           *//*  constrained property.                                         */      fontColor.addPropertyChangeListener(this);      fontColor.addVetoableChangeListener(this);   }   public FontColor2 getFontColor()   {      return fontColor;   }   public void setFontColor(FontColor2 fc)   {      fontColor = fc;   }/*  The NewLabel2 class serves as a PropertyChangeListener and thus  *//*  provides an implementation of the propertyChange() method.  If   *//*  the PropertyChangeEvent was due to a change in the "color"       *//*  property, the text color of the NewLabel is changed.             */   public void propertyChange(PropertyChangeEvent event)   {      if ( event.getPropertyName().equals("color") )      {         setForeground( (Color)event.getNewValue() );      }   }/*  The NewLabel2 class also serves as a VetoableChangeListener and  *//*  thus provides an implementation of the vetoableChange() method.  *//*  This method determines if the proposed change is unacceptable.   *//*  If it is, a PropertyVetoException is thrown.                     */   public void vetoableChange(PropertyChangeEvent event)                                    throws PropertyVetoException   {      if ( event.getPropertyName().equals("color") )      {         Color color = (Color)event.getNewValue();         if ( color.equals(Color.green) )         {            throw new PropertyVetoException("Green is forbidden", event);         }      }   }}

⌨️ 快捷键说明

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