rangebean.java

来自「sun公司开发的,java2核心技术,卷II:高级性能,包括一系列的高级java」· Java 代码 · 共 46 行

JAVA
46
字号
/**
 * @version 1.20 1999-09-26
 * @author Cay Horstmann
 */

import java.awt.*;
import java.beans.*;
import java.io.*;
import javax.swing.*;

public class RangeBean extends JPanel
   implements VetoableChangeListener, Serializable
{  public RangeBean()
   {  add(new JLabel("From"));
      add(from);
      add(new JLabel("To"));
      add(to);

      from.addVetoableChangeListener(this);
      to.addVetoableChangeListener(this);
   }

   public void vetoableChange(PropertyChangeEvent event)
      throws PropertyVetoException
   {  int v = ((Integer)event.getNewValue()).intValue();
      if (event.getSource() == from && v > to.getValue())
         throw new PropertyVetoException("from > to", event);
      if (event.getSource() == to && v < from.getValue())
         throw new PropertyVetoException("to < from", event);
   }

   public int getFrom() { return from.getValue(); }
   public int getTo() { return to.getValue(); }

   public void setFrom(int v) throws PropertyVetoException
   {  from.setValue(v);
   }

   public void setTo(int v) throws PropertyVetoException
   {  to.setValue(v);
   }

   private IntTextBean from = new IntTextBean();
   private IntTextBean to = new IntTextBean();
}

⌨️ 快捷键说明

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