Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

Java: GUI Overview

JavaFAQ Home » Java Notes by Fred Swartz Go to all tips in Java Notes by Fred Swartz


Bookmark and Share

A GUI (Graphical User Interface) is easy to create after you have a few basic elements from these groups:

  1. Top-level Containers (eg, JFrame)
  2. Intermediate Containers (eg, JPanel, JMenuBar)
  3. Components (eg, JLabel, JButton, JTextField)
  4. Listeners (eg, ActionListener)
  5. Layouts (eg, FlowLayout, BorderLayout, GridBagLayout)

Top-level Containers are windows (JFrame, JDialog). Each window has two intermediate containers - a menubar which contains the menus, and the content pane which holds the components.

Intermediate Containers (eg, JPanel) contain components. Components are added to the intermediate container. Every container has a layout manager, which specifies how the components are arranged in the container.

Layouts specify how to arrange components in a JPanel (or other intermediate container). Every JPanel starts with a default layout manager, but it's better to set it explicitly.. Use one of Java's layout managers: FlowLayout, BorderLayout, GridLayout, GridBagLayout, BoxLayout, etc.

Components are the user interface controls like buttons (JButton, ...), text boxes (JTextField, JTextArea, ...), menus, etc. These are added to a container with the add() method, and the place they appear on a container is determined by the layout which is used for that container.

Listeners are attached to components and contain the code that is called when the component is used (eg, a button is clicked). This is how a user action on a component (like a click on a JButton or moving a JSlider) is connected to a Java method. As long as you work with components, you never have to use low-level listeners (eg, mouse listeners and key listener) because the components take care of this for you.

Other. The above are essential elements for user interfaces, but others will be useful in some programs. Eg, drawing graphics, animation, mouse, keyboard, sound, ... Good guidance on the appearance can be found in Sun's Java Look and Feel Design Guidelines, which is available on-line for free (java.sun.com/products/jlf/ed2/book/).

Program Organization

There are some simple patterns using constructors, anonymous listeners, etc to produce a reasonable program.

Tools to help build a GUI

Some IDEs have GUI editors. There are also separate GUI editors, eg XUI and UICompiler.


 Printer Friendly Page  Printer Friendly Page
 Send to a Friend  Send to a Friend

.. Bookmark and Share

Search here again if you need more info!
Custom Search



Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy