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

📄 rangebean.java

📁 corejava的源程序内有好多的源代码
💻 JAVA
字号:
/**
   @version 1.21 2001-08-20
   @author Cay Horstmann
*/

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

/**
   A bean with two integer text fields to specify a range
   of values.
*/
public class RangeBean extends JPanel
{  
   public RangeBean()
   {  
      add(new JLabel("From"));
      add(from);
      add(new JLabel("To"));
      add(to);

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

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

   /**
      Sets the from property.
      @param v the new lower bound of the range
   */
   public void setFrom(int v) throws PropertyVetoException
   {  
      from.setValue(v);
   }

   /**
      Gets the from property.
      @return the lower bound of the range
   */
   public int getFrom() { return from.getValue(); }

   /**
      Sets the to property.
      @param v the new upper bound of the range.
   */
   public void setTo(int v) throws PropertyVetoException
   {  
      to.setValue(v);
   }

   /**
      Gets the to property.
      @return the upper bound of the range
   */
   public int getTo() { return to.getValue(); }

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

⌨️ 快捷键说明

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