CIS-75 Home http://www.c-jump.com/CIS75/CIS75syllabus.htm

Swing, the Java Foundation Classes for UI Components


  1. Programming User Interface in Java
  2. Java Foundation Classes
  3. Sample Code for Week One
  4. Compiling and Running Sample Code
  5. Swing vs. JFC
  6. Swing Components
  7. The Swing Class Hierarchy
  8. Getting Started using the Swing
  9. Complete Swing Example
  10. Swing Components
  11. Model-View-Controller Design
  12. JPanel
  13. Complete JPanel Example
  14. Swing Look and Feel
  15. Setting the Window Close Box
  16. Setting the Window Close Box, Cont.
  17. Making a Reusable ApplicationFrame Class
  18. A Simple Two-Button Program
  19. JFrame Revisited
  20. Swing Layouts
  21. Using Layout Managers
  22. Border Layout
  23. GridLayout and Radio Buttons
  24. Menus and Actions
  25. Menu Events
  26. JDialog Input Dialogs
  27. Custom Dialog Example

1. Programming User Interface in Java



2. Java Foundation Classes



3. Sample Code for Week One



4. Compiling and Running Sample Code



5. Swing vs. JFC



6. Swing Components



7. The Swing Class Hierarchy



8. Getting Started using the Swing



9. Complete Swing Example



10. Swing Components



11. Model-View-Controller Design



12. JPanel


  • JPanels are containers that are

    • automatically double buffered

    • repainted more quickly and smoothly.

  • It is recommended that a program

    1. creates a simple JPanel

    2. adds the panel to JFrame object

    3. adds all other components to the panel object.

  • For example,

    
        JPanel jpan = new JPanel();
        frame.getContentPane().add( jpan );
        JButton jbut = new JButton( "Hello" );
        jpan.add( jbut );
    
    

13. Complete JPanel Example



14. Swing Look and Feel

  • Swing programs will start up in their own native look and feel rather than the Windows, Motif or Mac style.

  • It is best to set the OS-specific system look and feel.

  • The idea is to use UIManager.setLookAndFeel method.

  • For complete example see A3/application/SwingMain.java ( download ) sample program.

  • 
    // Setting OS-specific look and feel:
    private static void setSystemLookFeel()
    {
        // Force GUI to come up in the OS-specific look and feel
        String laf = UIManager.getSystemLookAndFeelClassName();
        try
        {
            UIManager.setLookAndFeel(laf);
        }
        catch (UnsupportedLookAndFeelException exc )
        {
            System.err.println("Unsupported: " + laf);
        }
        catch (Exception exc)
        {
            System.err.println("Error loading " + laf);
        }
    }
    
    

15. Setting the Window Close Box



16. Setting the Window Close Box, Cont.



17. Making a Reusable ApplicationFrame Class



18. A Simple Two-Button Program



19. JFrame Revisited



20. Swing Layouts



21. Using Layout Managers



22. Border Layout



23. GridLayout and Radio Buttons



24. Menus and Actions



25. Menu Events



26. JDialog Input Dialogs



27. Custom Dialog Example