Presentation is loading. Please wait.

Presentation is loading. Please wait.

Provision for GUIs in Java

Similar presentations


Presentation on theme: "Provision for GUIs in Java"— Presentation transcript:

1 Provision for GUIs in Java
CSC 202

2 Evolution of GUI Capabilities in Java

3 Java 1.0 Abstract Window Toolkit (AWT)
Called “Abominable” or “Awful Window Toolkit”. Done in 30 days. Last minute add-on. Java 1.1 Significantly improved, But GUI not finished.

4 Java 2 - Swing Much improved from AWT.
Part of Java Foundation Classes (JFC). Very easy to add: Accelerators Tool Tips Graphics Pluggable look and feel.

5 AWT vs Swing AWT approach Swing approach
Implement common elements of various operating environments. Swing approach Departure from AWT effort. Swing only needs to know how to write a pixel on a screen in a particular environment. AWT classes are extended in Swing. Example: AWT Button became Swing JButton.

6 The Operating System GUI Interface

7 Multitask operating system (Windows, UNIX, Linux, etc.)
When the o.s. detects an event such as a mouse click, It determines what the event was; It determines in which application window it occurred.

8 Operating System Interface
The operating system Passes event info as a message to the appropriate application, and Permits the app to take action. May interrupt the subsequent action if another event is detected.

9 Java Containment Hierarchy - 1
One and only one top-level container. May contain any number of intermediate-level and atomic components. Swing: almost always a Jframe (see Fig. 12.1, Table 12.2) See MyFrame.java (Listing 12.1) Note the method calls.

10 Containment Hierarchy - 2
Next important level: “content pane.” Internal component of the top-level container. All visible components other than menu bar go here. (See Listing 12.2). Lower levels (lightweight components) See Figure 12.1.

11 Creation of a Basic GUI Create a frame. Add components.
Instantiate a frame object. Establish characteristics of the frame. Example: MyFrame.java (Listing 12.1) Add components. Example: MyFrameWithComponents.java (Listing 12.2)

12 Layout Managers Each top-level and intermediate container has a default layout manager. JFrame, JDialog, and JPanel – BorderLayout JWindow – FlowLayout Defines how components are sized and positioned within the container's content pane. (See pp , 8th ed.; pp , 9th ed.)

13 Creating a Swing-Based Window - Two Approaches:
Construct a GUI object using Swing components from within a main() method without first creating a separate GUI class. Sometimes used to introduce Swing components and to create extremely simple GUIs. This is how our first example was done. (See FirstGUI.java) Construct the GUI as a separate class using Swing components. (See FirstWindow.java) In general this is preferred (adheres more closely to accepted OO practice).

14 Reading Chapter 12 – Introduction to GUIs Chapter 13 – Reference
Chapter 16 – Read to understand how to handle event-driven programming.


Download ppt "Provision for GUIs in Java"

Similar presentations


Ads by Google