public abstract class Spring extends Object
Spring类的一个实例包含三个表征其行为的属性: 最小值 , 优选值和最大值 。
这些属性中的每一个都可以参与基于一系列规则来定义其第四个, 值属性。
Spring类的一个实例可以被可视化为机械弹簧,当弹簧被压缩或拉伸远离其优选值时,其提供校正力。 该力被建模为距离优选值的距离的线性函数,但是具有两个不同的常数 - 一个用于压缩力,一个用于张力。 这些常数由弹簧的最小值和最大值指定,使得其最小值处的弹簧产生与当其处于其最大值时产生的相等和相反的力。 因此,优选值和最小值之间的差值表示弹簧可以被压缩的容易程度,其最大值和优选值之间的Spring可以扩展Spring的容易程度。 有关详细信息,请参阅sum(javax.swing.Spring, javax.swing.Spring)方法。
通过在定义简单的算术运算Spring S,的集合的行为Spring s时,可以减少到一个普通的(非复合) Spring 。 我们在Spring s上定义“+”,“ - ”, 最大和最小运算Spring ,因此在每个情况下,结果是一个Spring ,其特征与其组成弹簧具有有用的数学关系。
A Spring可以被视为具有单个公共点的一对间隔:优选值。 以下规则定义了一些可应用于间隔的a符( [a, b]指的是从a到b的间隔,其中a <= b )。
[a1, b1] + [a2, b2] = [a1 + a2, b1 + b2]
-[a, b] = [-b, -a]
max([a1, b1], [a2, b2]) = [max(a1, a2), max(b1, b2)]
如果我们将Spring表示为[a, b, c] ,其中a <= b <= c ,我们可以在Spring s上定义相同的算术运算Spring :
[a1, b1, c1] + [a2, b2, c2] = [a1 + a2, b1 + b2, c1 + c2]
-[a, b, c] = [-c, -b, -a]
max([a1, b1, c1], [a2, b2, c2]) = [max(a1, a2), max(b1, b2), max(c1, c2)]
两个间隔和Spring我们可以定义“ - ”和最小的否定:
X - Y = X + (-Y)
min(X, Y) = -max(-X, -Y)
对于体现算术运算符的这个类中的静态方法,我们实际上并不执行有问题的操作,因为在调用静态方法时,将快照该方法参数的属性的值。 相反,静态方法创建一个新的Spring实例,其中包含对方法参数的引用,以便新弹簧的特征跟踪弹簧的潜在变化特征。 这有点像功能语言中懒惰价值的想法。
如果要实现一个SpringLayout ,您可以找到进一步的信息和例子How to Use SpringLayout ,在Java教程的部分。
警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,对所有JavaBeans的长期存储的支持已经添加到java.beans包中。 请参阅XMLEncoder 。
SpringLayout , SpringLayout.Constraints
| Modifier and Type | Field and Description |
|---|---|
static int |
UNSET
表示属性值尚未计算的整数值。
|
| Modifier | Constructor and Description |
|---|---|
protected |
Spring()
用工厂方法创建一个
Spring 。
|
| Modifier and Type | Method and Description |
|---|---|
static Spring |
constant(int pref)
返回一个支柱 - 一个弹簧,其
最小值 ,
首选值和
最大值各自具有值
pref 。
|
static Spring |
constant(int min, int pref, int max)
返回弹簧,其
最小 ,
优选的 ,并且
最大值具有以下值:
min ,
pref和
max分别。
|
abstract int |
getMaximumValue()
返回此
Spring的
最大值 。
|
abstract int |
getMinimumValue()
返回此的
最小值
Spring 。
|
abstract int |
getPreferredValue()
返回此的
优选值
Spring 。
|
abstract int |
getValue()
返回此
Spring的当前
值 。
|
static Spring |
height(Component c)
返回一个弹簧,其
最小值 ,
首选
值 ,
最大值和
值属性由所提供组件的
minimumSize ,
preferredSize ,
maximumSize和
size属性的高度定义。
|
static Spring |
max(Spring s1, Spring s2)
返回
max(s1, s2) :一个弹簧的值始终大于(或等于)
s1和
s2的值。
|
static Spring |
minus(Spring s)
返回
-s :一个弹簧以相反的方向运行到
s 。
|
static Spring |
scale(Spring s, float factor)
返回一个弹簧,其
最小值 ,
优选
值 ,
最大值和
值属性均为参数spring
s 。
|
abstract void |
setValue(int value)
将此
Spring的当前
值设置为
value 。
|
static Spring |
sum(Spring s1, Spring s2)
返回
s1+s2 :一个春天,代表
s1和
s2系列。
|
static Spring |
width(Component c)
返回一个弹簧,其
最小值 ,
首选
值 ,
最大值和
值属性由所提供组件的
minimumSize ,
preferredSize ,
maximumSize和
size属性的宽度定义。
|
public static final int UNSET
public abstract int getMinimumValue()
Spring 。
minimumValue的这个
Spring属性
public abstract int getPreferredValue()
Spring 。
preferredValue的
Spring
public abstract int getMaximumValue()
Spring的
最大值 。
maximumValue这个
Spring
public abstract int getValue()
Spring的当前
值 。
value这个
Spring属性
setValue(int)
public abstract void setValue(int value)
Spring的当前
值设置为
value 。
value - 新设置的
value属性
getValue()
public static Spring constant(int pref)
pref 。
pref - 新弹簧的
最小值 ,
首选值和
最大值
pref
Spring
public static Spring constant(int min, int pref, int max)
min ,
pref和
max分别。
min - 新弹簧的
最小值
pref -
新春的首选值
max - 新弹簧的
最大值
min ,
pref和
max分别
Spring
public static Spring minus(Spring s)
-s :在相反方向运行的弹簧
s 。
-s :一个弹簧以相反的方向运行到
s
Spring
public static Spring sum(Spring s1, Spring s2)
s1+s2 :一个春天代表s1和s2串联。
在一个总和, s3 ,两个弹簧中, s1和s2 ,的菌株 s1 , s2和s3被保持在相同的水平(由它们的整数值 s隐含的精度内)。
压缩弹簧的应变是:
value - pref
------------
pref - min
张力弹簧的应变是:
value - pref
------------
max - pref
当setValue上调用的总和弹簧, s3 ,在应变s3被使用上面的公式之一来计算。
一旦和的应变已知,则设定s1和s2的值 s,使得它们具有等于和的应变。
对公式进行评估,以考虑舍入误差,并确保s1和s2的值 s的s1等于s3的值 。
s1+s2
s1和
s2的春季系列
Spring
public static Spring max(Spring s1, Spring s2)
max(s1, s2) :一个弹簧的值始终大于(或等于)
s1和
s2的值。
max(s1, s2) :一个弹簧的值总是大于(或等于)
s1和
s2的值
Spring
public static Spring scale(Spring s, float factor)
s 。
当factor为负时(根据间隔算术的规则),最小和最大属性被交换。
当因素例如为0.5f时,结果表示其输入的“中点” - 这对于将容器中的组件置于中心是有用的操作。
s - 春天的规模
factor - 按比例计算。
s乘以
factor
NullPointerException - 如果
s为空
public static Spring width(Component c)
c - 用于计算大小的组件
NullPointerException - 如果
c为空
public static Spring height(Component c)
c - 用于计算大小的组件
NullPointerException - 如果
c为空
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.