Skip to content

Latest commit

 

History

History

09_AWT_Swing

AWT & Swing in Java

In this section, you'll learn how to create graphical user interfaces (GUIs) using AWT (Abstract Window Toolkit) and Swing. AWT provides basic building blocks for creating windows, while Swing extends AWT to provide more advanced features and components.

Topics Covered:

  1. AWT Basics - Creating simple applets and handling user input.
  2. Swing Basics - Creating windows, adding controls, and handling events.
  3. Layouts - Managing component positioning with different layout managers like BorderLayout.
  4. RGB Colors - Working with colors using scroll bars.

Example Programs:

AWT:

  1. LoginApplet.java - An applet that creates a simple login window with username and password fields.

    • Concepts: Using TextField and Button in an applet.
  2. FontApplet.java - A program that lets the user change the font of text using control boxes for font name, size, and style.

    • Concepts: Working with Choice boxes and font manipulation.
  3. CalculatorApplet.java - A 3-function calculator (addition, subtraction, multiplication) implemented as an applet.

    • Concepts: Handling button click events in applets.
  4. RGBApplet.java - A program that uses scrollbars to adjust RGB color combinations and change the background color.

    • Concepts: Working with Scrollbar and Color in applets.

Swing:

  1. SwingLogin.java - A Swing version of the login window with username and password fields.

    • Concepts: Using JTextField and JButton in Swing.
  2. SwingFont.java - A Swing application that lets the user change the font of the text using control boxes.

    • Concepts: Handling events and changing styles in Swing.
  3. SwingCalculator.java - A 3-function calculator created using Swing components.

    • Concepts: Handling basic arithmetic operations with JButton and JTextField.
  4. SwingRGB.java - A program that uses scrollbars in Swing to display color combinations of RGB values.

    • Concepts: Handling JScrollBar events in Swing.
  5. SwingBorderLayout.java - A demonstration of using the BorderLayout layout manager in Swing.

    • Concepts: Arranging components with BorderLayout.

Exercises:

  1. Create a simple login applet that checks if the username and password match predefined values.
  2. Write an applet that uses scrollbars to change the background color of the window.
  3. Create a Swing application with three control boxes to select a font, size, and style, and apply the selected settings to a text label.
  4. Write a Swing application that uses at least five different controls, such as buttons, text fields, checkboxes, etc.

Moving Forward:

After learning AWT and Swing basics, you can dive into more advanced topics like custom painting, event-driven programming, and integrating GUI with backend data using JDBC.


Files

  • CalculatorApplet.java: Implements a 3-function calculator using applet.
  • LoginApplet.java: Applet login window with text fields and buttons.
  • FontApplet.java: Applet with control boxes for font name, size, and style.
  • RGBApplet.java: Applet to display RGB combination using scrollbars.
  • SwingControls.java: Swing application using at least 5 controls.
  • BorderLayoutApplet.java: Implements border layout using applet.
  • SwingCalculator.java: Implements a 3-function calculator using Swing.
  • SwingLogin.java: Swing login window with text fields and buttons.
  • SwingFont.java: Swing application with control boxes for font name, size, and style.
  • SwingRGB.java: Swing application to display RGB combination using scrollbars.
  • SwingBorderLayout.java: Implements border layout using Swing.