Beispiel #1
0
 @Override
 T getInstance() {
   try {
     ReflectUtil.checkPackageAccess(clazz);
     return clazz.newInstance();
   } catch (InstantiationException | IllegalAccessException ignored) {
   }
   return null;
 }
Beispiel #2
0
  /**
   * Returns an instance of the default toolkit. The default toolkit is the subclass of <code>
   * Toolkit</code> specified in the system property <code>awt.toolkit</code>, or <code>
   * gnu.java.awt.peer.gtk.GtkToolkit</code> if the property is not set.
   *
   * @return An instance of the system default toolkit.
   * @error AWTError If the toolkit cannot be loaded.
   */
  public static Toolkit getDefaultToolkit() {
    if (toolkit != null) return (toolkit);

    String toolkit_name = System.getProperty("awt.toolkit", default_toolkit_name);

    try {
      Class cls = Class.forName(toolkit_name);
      Object obj = cls.newInstance();

      if (!(obj instanceof Toolkit))
        throw new AWTError(toolkit_name + " is not a subclass of " + "java.awt.Toolkit");

      toolkit = (Toolkit) obj;
      return (toolkit);
    } catch (Exception e) {
      throw new AWTError("Cannot load AWT toolkit: " + e.getMessage());
    }
  }