Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Graphic Environment Abstract Methods

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Thanked 0 Times in 0 Posts

    Default Graphic Environment Abstract Methods


    I was recently looking at the GraphicsEnvironment class in Javadoc and some example code on google. I am confused on the usage of the abstract method .getAllFonts() and .getAllAvailableFontsFamily(). I understand getting a GraphicsEnvironment by calling getLocalGraphicEnvironment, but what I am confused about is calling the static abstract method getAllFonts() and getAllAvailableFontsFamily() on the GraphicEnvironment object when both methods are abstract. Can somebody explain to me why?

  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Thanked 619 Times in 561 Posts
    Blog Entries

    Default Re: Graphic Environment Abstract Methods

    In Java you can't have static abstract methods. Those methods are in fact only declared abstract.

    If you want to get all the fonts, get the local graphics environment, then the respective methods from the object you get.

    GraphicsEnvironment local = GraphicsEnvironment.getLocalGraphicEnvironment();
    // get all fonts
    Font[] fonts = local.getAllFonts();
    // get all available font families
    String[] fontFamilies = local.getAvailableFontFamilyNames();

  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    javapenguin (January 6th, 2012)

  4. #3
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Madgaon, Goa, India
    Thanked 48 Times in 46 Posts

    Default Re: Graphic Environment Abstract Methods

    The reference returned from getLocalGraphicEnvironment() is a reference to an object of a class that extends GraphicsEnvironment -- and implements all abstract methods.

    Try printing the class of the object returned -- after the first line of the code posted by helloworld922 add

Similar Threads

  1. [SOLVED] Abstract Classes Help
    By SweetyStacey in forum Object Oriented Programming
    Replies: 10
    Last Post: May 6th, 2010, 06:15 AM
  2. Replies: 1
    Last Post: March 23rd, 2010, 02:29 AM
  3. [SOLVED] Error "TitleChanger is abstract; cannot be instantiated"
    By Uzual in forum AWT / Java Swing
    Replies: 2
    Last Post: May 26th, 2009, 11:23 AM
  4. Replies: 1
    Last Post: July 10th, 2008, 05:03 AM
  5. Java program with abstract class along with two subclasses
    By crazydeo in forum Collections and Generics
    Replies: 2
    Last Post: June 10th, 2008, 11:45 AM