Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Java GUI Components and Event Handling: Swing vs AWT, Slides of Network security

An introduction to java's graphical user interface (gui) features, focusing on swing and awt components, layout managers, and event handling. It covers the differences between lightweight and heavyweight components, the disadvantages of awt, and the three main steps to creating a gui. The document also demonstrates how to create an application window, add components, and register event listeners using swing.

Typology: Slides

2012/2013

Uploaded on 04/22/2013

sathaye
sathaye 🇮🇳

4.8

(8)

106 documents

1 / 60

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Objectives
use an image viewer application to
introduce Java's GUI features
11. Introducing
Java's GUI Features
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c

Partial preview of the text

Download Java GUI Components and Event Handling: Swing vs AWT and more Slides Network security in PDF only on Docsity!

Objectives

  • use an image viewer application to introduce Java's GUI features

11. Introducing

Java's GUI Features

Topics

    1. GUI Principles
    1. Background
    1. Three Steps to GUIs
    1. An Applicaton Window
    1. Adding Menus
    1. Event Handling
    1. ImageViewer as a Listener

continued Docsity.com

1. GUI Principles

listeners (waiting code)

events (info. objects) components

layout manager

1. GUI Principles

  • GUIs are built from components
    • buttons, menus, sliders, etc.
  • The positioning of GUI components in a

window is done with layout managers

  • User actions are converted into events
    • button presses, menu selections, etc.
  • Events are processed by listeners.

2.1. Swing and AWT

  • In older Java programs, the AWT (Abstract Window Toolkit) GUI components are used - Swing has replaced AWT GUIs - never mix Swing and AWT components in a single program
  • Some parts of AWT are still used
    • e.g. its layout managers (see later)

continued Docsity.com

use Swing

  • AWT supports heavyweight GUI components
    • each Java GUI component is actually a simple layer hiding the OSes GUI component - the OS component is called a peer component
    • e.g. on Windows, a Java button in AWT is implemented using a Windows' button

continued Docsity.com

2.2. Disadvantages of AWT

  • Java does not have complete control over the AWT GUI components - some AWT GUIs do not work well because of problems with the underlying OS (e.g. file choosing in Windows)
  • The "look and feel" of Java GUIs in AWT vary between OSes.

Some Java"Look and Feel"s

Using the Substance L&F add-on library (https://substance.dev.java.net/)

4. An Application Window

title

content pane

window controls

Implemented by subclassing JFrame

Coding an Application

public class ImageViewer extends JFrame { public ImageViewer() { super("ImageViewer 0.1");

// create the GUI Container c = getContentPane(); JLabel label = new JLabel ("I am a label. I can display some text."); c.add(label); :

JLabel is a GUI component

Version 0.

Sizing the Application

  • Replace setSize() by pack():

5. Adding Menus

  • JMenuBar
    • contains the menus
  • JMenu
    • contains the menu items
  • JMenuItem
    • individual items in a menu