0% found this document useful (0 votes)
31 views37 pages

Oop Ii-Introduction

This document provides information about an Object-Oriented Programming II course taught by John Sospeter at Ruaha Catholic University. It outlines how students will be graded, with coursework and assignments counting for 40% and a final exam counting for 60%. It also provides the instructor's office location and contact details, as well as information about prerequisites, reference books, and an introduction to graphical user interfaces (GUIs) using Java GUI libraries like AWT and Swing. GUI components, containers, and examples of building basic GUIs with frames, panels, and dialog boxes are discussed.

Uploaded by

Elisante David
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views37 pages

Oop Ii-Introduction

This document provides information about an Object-Oriented Programming II course taught by John Sospeter at Ruaha Catholic University. It outlines how students will be graded, with coursework and assignments counting for 40% and a final exam counting for 60%. It also provides the instructor's office location and contact details, as well as information about prerequisites, reference books, and an introduction to graphical user interfaces (GUIs) using Java GUI libraries like AWT and Swing. GUI components, containers, and examples of building basic GUIs with frames, panels, and dialog boxes are discussed.

Uploaded by

Elisante David
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 37

RUCU

Object-Oriented Programming II
RCS 212

John Sospeter
Assistant Lecturer
Faculty of Information and Communication Technology
Department of Computer Science
Ruaha Catholic University
How You Will be Graded

• Course work 40%


Assignments
Placticals
Quiz
Test
• Final Exam 60%
• Please note. I do not accept late assignments.
You get zero for anything past the due date,
unless you have a strong excuse.
Office & Contact Policy

• Office
ICT Office No_02
• Email address
[email protected]
[email protected]
• Contact
Mobile no +255763160096
Whatsapp no: +8615524573830

• I don’t answer questions about course content or the assignments by email.


• I will read short and to the point email.
• Come to my office hours, talk to me before or after class
• If you have an unavoidable scheduling conflict we can arrange a mutually
acceptable alternative meeting time.
Reference Book
Deitel, Paul J.
Java : how to program / P.J. Deitel, H.M. Deitel. -- 9th ed.

Recommended but not required.


– Older editions are also useable---but you will have to search the text for
the relevant sections
Prerequisites
• The knowledge of Object Oriented Programming I
[RCS 102] is useful .
• This year the course will use JAVA as programming
language to learn.
• If you don’t have these prerequisites you will be
responsible for learning any needed background
material.
– I will not have time to help you with that, and you
will not be given any special consideration for not
having had the proper background.(study hard)
OOP II

Introduction to GUI
[Graphical User Interface]
Introduction to GUI
GUI
•  Is a type of computer human interface on a
computer
• A computer human interface is a "means by which
people and computers communicate with each other
• Presents a user-friendly mechanism for interacting
within application.
• A GUI (pronounced “GOO-ee”) gives an application a
distinctive “look and feel.”
Introduction to GUI
• A GUI allows a computer user to move from application to application.

• A good GUI makes an application easy, practical, and efficient to use,


and the marketplace success of today's software programs depends
on good GUI design

• When a GUI program is running, the user can click any of the buttons
and interact with any of the other on screen components in any order.
Because the program’s execution is driven by the series of events that
occur, we say that programs with GUIs are event-driven
Example of GUI
Example of GUI
JAVA GUI Libraries
• GUI-related classes are defined primarily in the java.awt and the javax.swing packages

• The Abstract Windowing Toolkit (AWT) was the original Java GUI package.
Problems: Limited to lowest common denominator (limited set of UI widgets); clunky to
use.

• The Swing package provides additional and more versatile components.


Benefits: Features; cross-platform compatibility; OO design
Paints GUI controls itself pixel-by-pixel
Does not delegate to OS’s window system

• Both packages are needed to create a Java GUI-based program


Advice: Use Swing. You occasionally have to use AWT (Swing is built on top of AWT).
Beware: it’s easy to get them mixed up.

• Distinguish Swing versions from AWT versions with “J” prefix


Comparison of AWT & Swing
AWT Swing

AWT stands for Abstract Window Toolkit AWT is the foundation of Swing and it implements GUI
components which was built on AWT.

AWT GUI components are heavy weight. Because Swing components are light weight Graphical User
components consumes comparatively high System Interface toolkit that includes a rich set of widgets
Resources than Swing. Components are depend on the
underlying operating System

AWT consumes comparatively high System Resources Swing consumes less System Resources.
than Swing.

AWT produces platform dependent components. i.e. the Swing will produce platform independent components.
program is dependent on the current Operating System. i.e. you can use it on any Operating System that
supports Java.

It requires javax.awt package. It requires javax.swing package.


GUI elements
[Swing]
GUI elements can be categorize into two types

1. Component
2. Container
GUI Components
• A GUI component is an object that represents a screen
element such as a button or a text field.

• GUIs are built from GUI components. A GUI


component is an object with which the user interact
via the mouse , the keyboard or another form of
input, such as voice recognition.

• GUI components are also called controls


GUI Components
• In general, Swing components are derived from the JComponent class. (The
only exceptions to this are the four top-level containers, described in the next
section.) 

• JComponent provides the functionality that is common to all components.


For example, JComponent supports the pluggable look and feel.

•  JComponent inherits the AWT classes Container and Component.

• Thus, a Swing component is built on and compatible with an AWT component.

• All of Swing’s components are represented by classes defined within the


package javax.swing.
Java swing class Hierarchy Diagram

All components in swing are JComponent


which can be added to container classes.
 
GUI Container
• A GUI container is a component that is used to hold and organize
other components

• A frame is a container displayed as a separate window with a title


bar. It can be repositioned and resized on the screen as needed

• A panel is a container that cannot be displayed on its own but is


used to organize other components

• A panel must be added to another container (like a frame or


another panel) to be displayed
GUI Components Vs GUI Containers
GUI Container
• A GUI container can be classified as either heavyweight or
lightweight

• A heavyweight container is one that is managed by the underlying


operating system

• A lightweight container is managed by the Java program itself

• Occasionally this distinction is important

• A frame is a heavyweight container and a panel is a lightweight


container
GUI Container
Container classes are classes that can have other components on it.
So for creating a GUI, we need at least one container object. There
are 3 types of containers.

• Panel: It is a pure container and is not a window in itself. The sole


purpose of a Panel is to organize the components on to a window.

• Frame: It is a fully functioning window with its title and icons.

• Dialog: It can be thought of like a pop-up window that pops out when
a message has to be displayed. It is not a fully functioning window
like the Frame.
Identify Components and Containers
Answers
Building a GUI
• A GUI is built in layers.

• Bottom most layer is the window (Container)


– Contains all other components
– Can provide basic features like maximise/minimise buttons, title bar, menu bar,
etc

• On top of this are layered (Component)


– Components, e.g. buttons, text fields
– or intermediate containers, e.g. Panels

• Layout manager Is used to layout [or arrange] the GUI java components
inside a container
– Its job is to instruct components on how to arrange themselves so the GUI is
drawn correctly. Eg. BorderLayout, FlowLayout, GridLayout
Building a GUI

Simple Application X

OK A Label

Cancel Text field…


The Containment hierarchy
• This layered GUI can be viewed as a hierarchy
of components
– NOT an inheritance hierarchy,
– It just describes how components are nested one
within another
The Containment hierarchy

JFrame

JButton JButton JPanel

JLabel JTextField
The Containment hierarchy
Draw the Containment hierarchy
Swing Top Level Containers
• JWindow
– Basic no frills window, just a square on the screen
– WindowExample.java
• JFrame
– The basic Swing window. Offers basic window controls,
resizable
– FrameExample.java
• JDialog
– For building dialog boxes, e.g. File open/save
– DialogExample.java
• JApplet
– For building applets, embedded into a web page
– To be covered later
Simple Dialogs

• A dialog is a special window to convey a


message or provides a special function
• Every dialog is dependent on a frame – when
that frame is destroyed, so are its dependent
dialogs
• A modal dialog blocks user input to all other
windows in the program
Dialog Boxes
• Used by applications to interact with the
user
• Provided by Java’s JOptionPane class
– Contains message dialogs , choice dialogs and
input dialogs

• Example1: HelloWorld.java
• Example2: Addition.java
• Example3: Choice.java
Example
Simple GUI program [Hallo world]

• Example1: HelloWorld.java
Java Swing
The remaining of our class Lectures is all about
Java Swing toolkit
Do not miss any of the class
Get prepared
DEDICATED
JOKE
“I will do later…..”
TIME
THANK YOU~~~

You might also like