Display.getDefault(): 该方法会返回用户图形界面线程中的Display实例,不管当前线程是否是用户图形界面线程.如果这个实例不存在,默认创建一个用户图形界面线程中的Display实例.
/**
* Returns the default display. One is created (making the thread that
* invokes this method its user-interface thread) if it did not already
* exist.
*
* @return the default display
*/
public static Display getDefault()
{
synchronized (Device.class)
{
if (Default == null)
Default = new Display();
return Default;
}
}
Display.getCurrent(): 返回当前线程中的Display实例.如果这是一个图形界面线程,实例非空;如果当前线程不是一个图形界面线程,则实例为空.
/**
* Returns the display which the currently running thread is the
* user-interface thread for, or null if the currently running thread is not
* a user-interface thread for any display.
*
* @return the current display
*/
public static Display getCurrent()
{
return findDisplay(Thread.currentThread());
}