全部版块 我的主页
论坛 数据科学与人工智能 IT基础 JAVA语言开发
1131 5
2015-07-27

  • Core Java™ 2 Volume II - Advanced Features, Seventh Edition
  • By: Cay S. Horstmann; Gary Cornell

  • Publisher: Prentice Hall

  • Pub. Date: November 22, 2004   Most Recent Edition

  • Print ISBN-10: 0-13-111826-9

  • Print ISBN-13: 978-0-13-111826-3

  • Pages in Print Edition: 1024

  • Subscriber Rating: [0 Ratings]



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2015-7-27 01:10:21

The Bean-Writing Process

复制代码
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-7-27 01:14:34
Simple Properties

A simple property is one that takes a single value such as a string or a number. The fileName property of the ImageViewer is an example of a simple property. Simple properties are easy to program: Just use the set/get naming convention we indicated earlier. For example, if you look at the code in Example 8-1, you can see that all it took to implement a simple string property is the following:

[size=28.3500003814697px]
复制代码



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-7-27 01:16:55
Indexed Properties

An indexed property is one that gets or sets an array. A chart bean (see below) would use an indexed property for the data points. With an indexed property, you supply two pairs of get and set methods: one for the array and one for individual entries. They must follow this pattern:


Type[] getPropertyName()
void setPropertyName(Type[] x)
Type getPropertyName(int i)
void setPropertyName(int i, Type x)

Here's an example of the indexed property we use in the chart bean that you will see later in this chapter.

复制代码


The


setPropertyName(int i, Type x)

method cannot be used to grow the array. To grow the array, you must manually build a new array and then pass it to this method:



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-7-27 01:20:00
Constrained Properties

[size=28.3500003814697px]A constrained property is constrained by the fact that any listener can “veto” proposed changes, forcing it to revert to the old setting. The Java library contains only a few examples of constrained properties. One of them is the closed property of the JInternalFrame class. If someone tries to callsetClosed(true) on an internal frame, then all of its VetoableChangeListeners are notified. If any of them throws a PropertyVetoException, then the closed property is not changed, and the setClosedmethod throws the same exception. For example, a VetoableChangeListener may veto closing the frame if its contents have not been saved.

[size=28.3500003814697px]To build a constrained property, your bean must have the following two methods to manageVetoableChangeListener objects:

[size=28.3500003814697px]public void addVetoableChangeListener(VetoableChangeListener listener);public void removeVetoableChangeListener(VetoableChangeListener listener);

[size=28.3500003814697px]Just as there is a convenience class to manage property change listeners, there is a convenience class, called VetoableChangeSupport, that manages vetoable change listeners. Your bean should contain an object of this class.

[size=28.3500003814697px]
private VetoableChangeSupport vetoSupport = new VetoableChangeSupport(this);


[size=28.3500003814697px]Adding and removing listeners should be delegated to this object. For example:

[size=28.3500003814697px]
复制代码



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-7-27 01:21:18

Example 8-2. FileNameBean.java

复制代码
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群