0% found this document useful (0 votes)
96 views11 pages

GUI Continued: SEED Infotech Pvt. LTD

This document discusses GUI components in Java. It explains that dialog boxes can be modal or modeless, and describes the Dialog class and how to create dialogs. It also discusses the MVC architecture and how it separates a component's model, view, and controller. Finally, it explains the Graphics class for drawing, and important methods like paint(), repaint(), and paintComponent() for updating the display.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
0% found this document useful (0 votes)
96 views11 pages

GUI Continued: SEED Infotech Pvt. LTD

This document discusses GUI components in Java. It explains that dialog boxes can be modal or modeless, and describes the Dialog class and how to create dialogs. It also discusses the MVC architecture and how it separates a component's model, view, and controller. Finally, it explains the Graphics class for drawing, and important methods like paint(), repaint(), and paintComponent() for updating the display.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
You are on page 1/ 11

GUI continued

SEED Infotech Pvt. Ltd. 1


Objectives of This Session

Demonstrate the usage of Dialog class

Demonstrate the use of frequently used swing


components

Distinguish between AWT & Swing

Explain the MVC architecture using an example

Explain the Graphics context and the use of repaint ()


and paint Component()

SEED Infotech Pvt. Ltd. 2


Dialog Boxes

A dialog box is a window with a title bar.


class Dialog inherits from class Window.
Dialog boxes can be modal or modeless.
Modal dialogs - doesn’t allow any other window
in the application to be accessed till Dialog is
closed.
Modeless dialogs - allows other windows in the
application to be accessed while dialog is
displayed.

SEED Infotech Pvt. Ltd. 3


Class Dialog

Constructors -
Dialog(Frame parent, String title)
Dialog(Frame parent, String title, boolean
modal)

Some methods -
isModal() - indicates if the dialog is modal.
show() shows the dialog.

SEED Infotech Pvt. Ltd. 4


Dialogs

Steps to create a Dialog box -


Extend a class from Dialog.
In the constructor of extended class call the
constructor of super class Dialog.
In this constructor, pass parent window, title
& modal/modeless option for dialog.
Add controls to the dialog.
Call dialog’s show() or setVisible() method.

SEED Infotech Pvt. Ltd. 5


MVC architecture

Model : describes the contents of a component.


View : describes the visual appearance of a component
Controller: describes the behavior (reaction to events) of a
component.

SEED Infotech Pvt. Ltd. 6


MVC architecture

Principle:
Don’t make one object responsible for too much.
Instead, associate the look & feel of component with one
object & store the contents in another object.
The controller functions are responsible for connecting user
actions to the model & views.
Allows the programmer to change the look & feel of an
interface without changing the behavior of the underlying
model.

SEED Infotech Pvt. Ltd. 7


Graphics Class

Graphics is an abstract class.


A graphics context enables drawing on screen in
Java.
A Graphics object encapsulates state info needed for
the basic rendering options that java supports.
It remembers a collection of settings for drawing
images &text.
All drawing in Java must go thru a Graphics object.

SEED Infotech Pvt. Ltd. 8


paint() method

This method of the Component class does nothing


by default – it must be overridden by the
programmer.
Should not be called directly by programmer,
because drawing graphics is a event-driven
process.
Even if called directly, the programmer should
ensure that he obtains a graphics handle for the
component & passes this handle as a parameter to
the paint() method.

SEED Infotech Pvt. Ltd. 9


repaint() method

Frequently called by programmer to force a paint()


operation.
Should not be overridden because it performs some
system-dependent tasks.
Eg. Obtaining a graphics context to pass on.
repaint() calls the update() method.
update() clears the components background of any previous
drawing & calls paint() directly.

SEED Infotech Pvt. Ltd. 10


paintComponent() method

This method is on similar lines to the paint() method of awt.

SEED Infotech Pvt. Ltd. 11

You might also like