Swing提供了许多的在Swing组件内部使用的实用工具,SwingUtilities类就是其中一个。它提供了许多的涉及计算、转换、访问控制、布局等方面的方法,这些方法已广泛的应用在各种Swing组件当中。当然,我们也可以把它拿来应用到我们自己的程序当中。
下面我们就来了解一个这些实用的功能.
(1)转换方法
MouseEvent convertMouseEvent(Component source, MouseEvent ourceEvent, Component destination)
将一个鼠标事件从一个组件转换到另一个组件上。
Point convertPoint(Component source, int x, int y, Component estination)
Point convertPoint(Component source, Point aPoint, Component destination)
将一个组件上的点坐标转换成另一个组件上的坐标点。
void convertPointFromScreen(Point p, Component c)
将一个屏暮坐标点转换成一个组件的坐标点.
void convertPointToScreen(Point p, omponent c)
将一个组件上的坐标点转换成屏暮坐标。
Rectangle convertRectangle(Component source, Rectangle aRectangle, Component destination)
将一个组件上的矩形坐标转换成另一个组件上的矩形坐标.
(2)计算方法
Rectangle[] computeDifference(Rectangle r1,Rectangle r2)
Rectangle computeIntersection(int x, int y, int width, int height, Rectangle dest)
Rectangle computeUnion(int x, int y, int width, int [...]
DOM是用与平台和语言无关的方式表示XML文档的官方W3C标准,是以层次结构组织的节点或信息片断的集合,它总是把文档看成一个文档
树,SAX处理能够立即开始,而不是等待所有的数据被处理,对于大型文档来说是个巨大的优点,JDOM无疑转为Java平台设计,它简化与XML的交互并
且比使用DOM更快,但是它大量的试用具体类操作从而降低了操作的灵活性,dom4j代表了全新的开发结果,集成的XPath支持、XML
Schema支持以及用于大文档或流化文档的基于事件的处理,它大量的使用了接口定义,提供了比JDOM大得多的灵活性。下面是一个简单的生成xml例
子:
package org.bulktree.xml;
import java.io.FileWriter;
import java.io.UnsupportedEncodingException;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
/** *//**
*
* @author bulktree Email: laoshulin@gmail.com
* @date Aug 3, 2008
*/
public class XmlTest02 {
public Document createDocument() throws DocumentException {
/**//*
* 产生 一个document对象
*/
Document doc = DocumentHelper.createDocument();
/**//*
* 添加一个跟元素
*/
Element root = doc.addElement(“Students“);
Element child1 = root.addElement(“student“);
/**//*
* 设置属性ID
*/
child1.addAttribute(“ID“, “001“);
Element subChild1 = child1.addElement(“name“);
subChild1.setText(“bulktree“);
Element subChild2 = child1.addElement(“age“);
subChild2.setText(“22“);
Element subChild3 = child1.addElement(“sex“);
subChild3.setText(“男“);
Element child2 = root.addElement(“student“);
child2.addAttribute(“ID“, “002“);
child2.addElement(“name“).setText(“laoshulin“);
child2.addElement(“age“).setText(“22“);
child2.addElement(“sex“).setText(“女“);
return doc;
}
public void writerDocument() throws Exception {
/**//*
* 格式化输出
*/
OutputFormat of = new OutputFormat(“ “, true);
/**//*
* 输出到屏幕
*/
// XMLWriter xmlWriter = new XMLWriter(System.out, of);
/**//*
* 输出到流中
*/
XMLWriter xmlWriter = new XMLWriter(new FileWriter(“student.xml“), of);
xmlWriter.write(this.createDocument());
xmlWriter.close();
}
public static void main(String[] args) throws Exception {
new XmlTest02().writerDocument();
}
}
在编程中常常会遇到需要动态操纵数组,比如在运行时增加和删除数组元素,而且有时在编译时又不想确定数组大小希望它可以动态伸缩,在java中解决这一问题的方法是使用java.util包中的ArrayList类,该类提供了许多的方法可以实现数组的动态操控,我是一名java初学者在这里只想把自己的学习成果与大家分享,以后我还会写很多关于java的文章,希望大家多给意见!空话不多说,我们要注重实效来看个例子吧!(在Win2000下调试通过)
import java.util.*;
public class ArrayListTest { public static void main(String[] args) { ArrayList staff = new ArrayList(); Employee emp = new Employee(”Ivan”,60000,1984,10,6); [...]
javadoc是生成一个java api文档生成工具。存在于jdk安装目录下的bin目录中。
javadoc在命令行使用还是比较复杂的,在eclipse、idea等IDE中却比较方便,在命令行使用的麻烦的原因是众多的参数。
但是IDE傻瓜型的操作在有些时候还完成不了想要的任务。这时候,就需要懂得一些参数命令的用法了。
在说明具体使用之前, 严重声明:生成javadoc 不要求你的java代码是可编译的。唯一要求的是存在.java文件。
下面是具体的用法:
D:\>javadoc -help
用法:javadoc [选项] [软件包名称] [源文件] [@file]
-overview <文件> 读取 HTML 文件的概述文档
-public 仅显示公共类和成员
-protected 显示受保护/公共类和成员(默认)
-package 显示软件包/受保护/公共类和成员
-private 显示所有类和成员
-help 显示命令行选项并退出
-doclet <类> 通过替代 doclet 生成输出
-docletpath <路径> 指定查找 doclet 类文件的位置
-sourcepath <路径列表> 指定查找源文件的位置
-classpath <路径列表> 指定查找用户类文件的位置
-exclude <软件包列表> 指定要排除的软件包的列表
-subpackages <子软件包列表> 指定要递归装入的子软件包
-breakiterator 使用 BreakIterator 计算第 1 句
-bootclasspath <路径列表> 覆盖引导类加载器所装入的
类文件的位置
-source <版本> 提供与指定版本的源兼容性
-extdirs <目录列表> 覆盖安装的扩展目录的位置
-verbose 输出有关 Javadoc 正在执行的操作的消息
-locale <名称> 要使用的语言环境,例如 en_US 或 en_US_WIN
-encoding <名称> 源文件编码名称
-quiet [...]
| 一 | 二 | 三 | 四 | 五 | 六 | 日 |
|---|---|---|---|---|---|---|
| « 4 | ||||||
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 | |||