Docsity

Programming Basics - Business Application Programming - Lecture Slides, Slides of Applications of Computer Sciences

Partial preview of the text

Download Programming Basics - Business Application Programming - Lecture Slides and more Slides Applications of Computer Sciences in PDF only on Docsity!

Chapter 9: Visual

Programming Basics

Object-Oriented Program

Development Using Java: A

Class-Centered Approach

Objectives

  • Event-Based Programming
  • Creating a Swing-Based Window
  • Adding a Window Closing Event Handler
  • Adding a Button Component
  • Common Programming Errors

Event-Based Programming

(continued)

  • Actions that trigger events include:
    • Placing the mouse pointer over a button and clicking the left mouse button
    • Using the TAB key until the desired button is highlighted with a dotted line then pushing the Enter key
    • Pressing an accelerator key
  • The sequence of events in a program are

controlled by the user

The Event-Based Model

  • Operating system:
    • Has total control of computer
    • Never relinquishes control to any executing programs
  • Most executing programs spend the majority of

their time in a sleep type of mode

  • When an event occurs:
    • The operating system passes event information to the appropriate application
    • Permits the application to take action

Containment Hierarchy

(continued)

  • A content pane is an internal component provided

by each top-level container

  • All of the visible components displayed by a GUI

must be placed on a content pane

  • Menu bar:
    • Can also be added to a top-level container
    • Placed outside of a content pane

Containment Hierarchy

(continued)

  • Layout manager:
    • Defines how components are positioned and sized within a container’s content pane
    • Default placement can always be changed
      • By explicitly specifying another layout manager
  • Lightweight components:
    • Intermediate containers and atomic components
    • Do not interface with the operating system

Creating a Swing-Based

Window (continued)

  • Create JFrame:
    • JFrame mainFrame = new JFrame("First GUI Window");
  • Setting size:
    • mainFrame.setSize(300,150);

Look and Feel

  • Refers to:
    • How a GUI appears on screen
    • How a user interacts with it
  • Swing package:
    • Supports four look and feel types
    • If no look and feel is specified, the default Java look and feel is used