rangebean.java
来自「java核心技术源代码」· Java 代码 · 共 84 行
JAVA
84 行
/**
@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 + =
减小字号Ctrl + -
显示快捷键?