我的一点看法
Toolkit kit=new Toolkit();和
Toolkit kit=Toolkit.getDefaultToolkit();
两个都可以用吧,只是第一个是创建新对象,第二个是引用系统中已有的对象
Toolkit kit=new Toolkit();和
Toolkit kit=Toolkit.getDefaultToolkit();
两个都可以用吧,只是第一个是创建新对象,第二个是引用系统中已有的对象
dimension这个词本身就是维(2维,3维)的意思呀!
如果还又不明白的,看看下面这个网址,也有下载版本,好像30多兆呢!
http://java.sun.com/j2se/1.4.1/docs/api/
有些类利用它的静态方法来产生一个引用。而不是用new 生成新对像
如http中一些类。
而不是Toolkit kit=new Toolkit()用new运算符创建对像。
private static Toolkit defaultToolkit = null;
//構造方法私有﹐別人無法調用
private Toolkit(){
..
}
//當沒有Toolkit實例時﹐新建實例﹐否則﹐返回以前建好的實例
public static Toolkit getDefaultToolkit(){
if (defaultToolkit == null){
defaultToolkit = new Toolkit();
return defaultToolkit;
}
else
return this.defaultToolkit;
}
}
/**
* This class is the abstract superclass of all actual
* implementations of the Abstract Window Toolkit. Subclasses of
* <code>Toolkit</code> are used to bind the various components
* to particular native toolkit implementations.
* <p>
* Most applications should not call any of the methods in this
* class directly. The methods defined by <code>Toolkit</code> are
* the "glue" that joins the platform-independent classes in the
* <code>java.awt</code> package with their counterparts in
* <code>java.awt.peer</code>. Some methods defined by
* <code>Toolkit</code> query the native operating system directly.
if (toolkit == null) {
try {
// We disable the JIT during toolkit initialization. This
// tends to touch lots of classes that aren't needed again
// later and therefore JITing is counter-productiive.
java.lang.Compiler.disable(); java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
String nm = null;
Class cls = null;
try {
nm = System.getProperty("awt.toolkit",
"sun.awt.motif.MToolkit");
try {
cls = Class.forName(nm);
} catch (ClassNotFoundException e) {
ClassLoader cl = ClassLoader.getSystemClassLoader();
if (cl != null) {
try {
cls = cl.loadClass(nm);
} catch (ClassNotFoundException ee) {
throw new AWTError("Toolkit not found: " + nm);
}
}
}
if (cls != null) {
toolkit = (Toolkit)cls.newInstance();
if (GraphicsEnvironment.isHeadless()) {
toolkit = new HeadlessToolkit(toolkit);
}
}
} catch (InstantiationException e) {
throw new AWTError("Could not instantiate Toolkit: " +
nm);
} catch (IllegalAccessException e) {
throw new AWTError("Could not access Toolkit: " + nm);
}
return null;
}
});
loadAssistiveTechnologies(); } finally {
// Make sure to always re-enable the JIT.
java.lang.Compiler.enable();
}
}
return toolkit;
}