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.


>> REGISTER NOW TO START POSTING


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

Results 1 to 6 of 6

Thread: Making my own GUI tookit. Looking for some advice.

  1. #1
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Making my own GUI tookit. Looking for some advice.

    Hi.

    Just for fun and exercise I have started to create my own GUI toolkit, much like AWT, Swing, Qt, etc.
    Its not my goal to make the next big thing and cash in lots of moneys; I just want to spend some time on more complex projects as a kind of training.

    Now this is a fairly complicated project and I have already spent a couple of hours just planning all kinds of classes I could need for this and how all these classes are supposed to work together, and now I want to share some of my thoughts and maybe get some advice from more experienced programmers; maybe a push in the right (or better) direction.

    Heres the basic concept:
    • Everything in the GUI is a component
    • Components are structured in a ComponentTree
    • The ComponentTree manages the updating and rendering of all components in the GUI
    • Components always have a parent (which is a component) unless they are the root of the ComponentTree
    • Components can have any number of children (which are components)
    • The componentTree is rendered by an in-order traversal of the tree starting at the root
    • The componentTree is updated by a level-order traversal starting at the leafs (going up the tree to the root)
    • Each component defines a viewport (rectangular) and its children must be contained completely within the viewport of their parent
    • The viewport of a child must be contained completely within the viewport of its parent


    Very rough draft of the class hierarchy:
    GUI-Toolkit-Classes.jpg

    A basic example GUI: (Showing a frame, menubar, panels to the left and bottom, and a pane with a picture in the center. Also: a border layout)
    GUI-Example.jpg
    This is how the component tree would look like internally: (for the example GUI above)
    Frame
    {
        Menu Bar
        {
            File MenuButton
            {
                File MenuButton label
            }
            Edit MenuButton
            {
                Edit MenuButton label
            }
            About MenuButton
            {
                About MenuButton label
            }
        }
        Left Panel
        {
        }
        Center Pane
        {
            Picture
        }
        Bottom Panel
        {
        }
    }

    There are also 2 other important aspects I left out so far:
    1. Compositions & Layouts
      • A Composition is a component that you can add / remove other components to / from (Composition is an interface)
      • A Composition can have a layout attached. The layout of the composition can change the positioning and size of components which have been added to the composition
    2. Floating Components
      • An alternative variation of a Component is the FloatingComponent
      • Floating components are NOT components. They can not be the root of a component tree, they are never the parent to a component nor a child of a component
      • Floating components are usually temporary and *float* on top of all other components in the component tree
      • Examples are drop-down menus, tooltips, context menus, etc
      • Floating components are still registered at a component tree and are also updated / rendered by their tree just like regular components



    What do you guys think about this? Would this work out this way or should I structure it differently?

    Thank you very much and sorry for that big wall of text.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Making my own GUI tookit. Looking for some advice.

    At a very bare minimum, all of your components should inherit from java.awt.Component (or, at least the root of your hierarchy tree should).
    You should also consider implementing different awt and Swing interfaces, based on what your components are.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Making my own GUI tookit. Looking for some advice.

    Well, to get something showing on the screen, you're going to have to *at least* inherit from an AWT component (unless you really want to go down the scary road of handling native UI stuff yourself, eek). And at that point, AWT will already have almost everything you talked about. It's really cool you just want to experiment, but you might be stepping on your own toes by reinventing the wheel a little?

    Instead, you might want to start by creating your own custom components withing Swing or AWT, as opposed to trying to re-implement the whole thing.Maybe an auto-complete component, or a dockable window, stuff like that?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Making my own GUI tookit. Looking for some advice.

    Thank you for the comments.

    I dont really see the benefit of using the AWT-Component class. There is a lot of deprecated functionality and things that I might not really need. Furthermore I am using OpenGL for rendering and own input libraries.
    The example picture I provided in my original post is actually already showing a working example of the code I have so far. Buttons, Labels, Panels, Layouts, Checkboxes, Pictures, etc; all of them work already.
    I am just not sure if I am happy with the way they work right now or if I should try to take an other approach.

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Making my own GUI tookit. Looking for some advice.

    Wait, so you're using OpenGL to natively create windows and components? If so, that's actually pretty impressive...

    Although, AWT isn't really deprecated, it's just older than Swing. Swing is built on top of AWT. But now I'm not really sure what your question is?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Making my own GUI tookit. Looking for some advice.

    Quote Originally Posted by KevinWorkman View Post
    Wait, so you're using OpenGL to natively create windows and components? If so, that's actually pretty impressive...
    Yes, I am using OpenGL to render everything. For the native calls I am using lwjgl right now, although jogl should work too. Both libraries are only providing a 1:1 binding of OpenGL.
    But lwjgl does also give me OpenAL and OpenCL support in just one library, so I prefer that.

    Quote Originally Posted by KevinWorkman View Post
    Although, AWT isn't really deprecated, it's just older than Swing. Swing is built on top of AWT.
    I know that AWT is not really deprecated because Swing is actually still using many of the AWT classes at some points, but the AWTComponent class has so many deprecated methods and/or fields. They are still using the Vector class without generics internally. And there are many other relics of the past.

    Quote Originally Posted by KevinWorkman View Post
    But now I'm not really sure what your question is?
    I just want some people who I can to talk about the concepts I have worked out so far. Its so hard to look into the future and plan ahead; I am just hoping for some experienced users to maybe give me some advice, or simply reconfirm my concepts so far if it isnt that bad after all.

Similar Threads

  1. Replies: 6
    Last Post: November 27th, 2012, 08:57 PM
  2. Need some help/advice for my GUI code.
    By J-Ark in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 4th, 2010, 12:23 PM
  3. Replies: 3
    Last Post: February 1st, 2010, 12:24 AM