GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
String[] names = g.getAvailableFontFamilyNames();
for(String s:names)
System.out.println(s);
以上可以输出所有本地支持的字体,困惑的是:
public static synchronized GraphicsEnvironment getLocalGraphicsEnvironment()
public abstract String[] getAvailableFontFamilyNames();
以上为JDK的GraphicsEnvironment类的源代码,
一个抽象类的引用调用该类的抽象方法,这是什么语法,不解。。抽象类抽象方法
String[] names = g.getAvailableFontFamilyNames();
for(String s:names)
System.out.println(s);
以上可以输出所有本地支持的字体,困惑的是:
public static synchronized GraphicsEnvironment getLocalGraphicsEnvironment()
public abstract String[] getAvailableFontFamilyNames();
以上为JDK的GraphicsEnvironment类的源代码,
一个抽象类的引用调用该类的抽象方法,这是什么语法,不解。。抽象类抽象方法
解决方案 »
- [*] 如何修改jar包里的文件?
- JDK1.5环境变量配置出现异常.奇怪奇怪。。。 5 5
- 关于线程控制小球跳跃反弹的例子程序
- 各位大侠帮帮忙 jfreechart实现曲线图,怎么显示曲线上数据点的数据值?----急
- 关于JAVA中连接数据库查询
- 内部类的特性全集!
- 初学java应该用什么开发工具较好?
- 我装了个JCreator, 可是好象有期限30天啊! 怎么办!哪有不过期的
- 请解释一下一个很简单的问题:System.out.println(".......");……
- 是不是只要把applet打包成jar文件浏览器就要用到Plug in?
- JEditorPane显示html文本,想实现查找,同时自动定位功能,该怎么做?有滚动条
- SVN不能更新文档的问题,求解
抽象类的引用,指向实现了该抽象类的一个对象,该对象是由方法getLocalGraphicsEnvironment()实现的,目的是为了确保 单例模式(即只有一个该类的对象)!既然该类已经被实现了,第二个疑问也就没了……
public static synchronized GraphicsEnvironment getLocalGraphicsEnvironment()
{
if(localEnv == null)
{
String s = (String)AccessController.doPrivileged(new GetPropertyAction("java.awt.graphicsenv", null));
try
{
localEnv = (GraphicsEnvironment)Class.forName(s).newInstance();
if(isHeadless())
localEnv = new HeadlessGraphicsEnvironment(localEnv);
}
catch(ClassNotFoundException classnotfoundexception)
{
throw new Error((new StringBuilder()).append("Could not find class: ").append(s).toString());
}
catch(InstantiationException instantiationexception)
{
throw new Error((new StringBuilder()).append("Could not instantiate Graphics Environment: ").append(s).toString());
}
catch(IllegalAccessException illegalaccessexception)
{
throw new Error((new StringBuilder()).append("Could not access Graphics Environment: ").append(s).toString());
}
}
return localEnv;
}
其中localEnv被定义为:private static GraphicsEnvironment localEnv;
localEnv引用指向的是被new出来的对象或newInstance出来的对象,所以不应该是单例模式吧。