JAVA GUI Graphical user interface Eng Amr Nagy

  • Slides: 13
Download presentation
JAVA GUI Graphical user interface Eng. Amr Nagy

JAVA GUI Graphical user interface Eng. Amr Nagy

Introduction • GUI presents a user-friendly mechanism for interacting with an application. • GUI

Introduction • GUI presents a user-friendly mechanism for interacting with an application. • GUI (pronounced “GOO-ee”) gives an application a distinctive “look” and “feel. ” Providing different applications with consistent, intuitive user interface components allows users to be somewhat familiar with an application, so that they can learn it more quickly and use it more productively.

Simple GUI-Based Input/Output with JOption. Pane

Simple GUI-Based Input/Output with JOption. Pane

Simple GUI-Based Input/Output with JOption. Pane // obtain user input from JOption. Pane input

Simple GUI-Based Input/Output with JOption. Pane // obtain user input from JOption. Pane input dialogs String first. Number = JOption. Pane. show. Input. Dialog( "Enter first integer" ); // display result in a JOption. Pane message dialog JOption. Pane. show. Message. Dialog( null, "The sum is " + sum, "Sum of Two Integers", JOption. Pane. PLAIN_MESSAGE );

Example

Example

Some basic GUI components

Some basic GUI components

Event-Driven Programming • Code is executed upon activation of events. • An event can

Event-Driven Programming • Code is executed upon activation of events. • An event can be defined as a type of signal to the program that something has happened. • The event is generated by external user actions such as mouse movements, mouse clicks, and keystrokes, or by the operating system, such as a timer.

The Delegation Model An event is triggered by user actions on the source object;

The Delegation Model An event is triggered by user actions on the source object; the source object generates the event object and invokes the handler of the listener object to process the event.

The Delegation Model Example

The Delegation Model Example

Selected User Actions User Action Source Object Event Type Generated Click a button Press

Selected User Actions User Action Source Object Event Type Generated Click a button Press return on a text field JButton JText. Field Action. Event Select a new item JCombo. Box Item. Event, Action. Event Select item(s) Click a check box JList JCheck. Box List. Selection. Event Item. Event, Action. Event Click a radio button JRadio. Button Item. Event, Action. Event Select a menu item Move the scroll bar Window opened, closed, etc. JMenu. Item JScroll. Bar Window Action. Event Adjustment. Event Windo. Event Component added or removed from the container Container. Event Component moved, resized, etc. Component. Event Component gained or lost focus Component Focus. Event Key released or pressed Component Key. Event Mouse pressed, released, clicked, etc. Component Mouse. Event Mouse moved or dragged Component Mouse. Event

Selected Event Handlers

Selected Event Handlers

Exercise

Exercise

Questions 13

Questions 13