Anda di halaman 1dari 24

BITS Pilani

BITS Pilani
Hyderabad Campus

Dr.Aruna Malapati Asst Professor Department of CSIS

BITS Pilani
Hyderabad Campus

Event Handling Programming

Todays Agenda
The Abstract Windowing Toolkit (AWT) AWT Class Hierarchy The Component class and its methods The GUI components

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

The Abstract Windowing Toolkit (AWT)


AWT stands for Abstract Window Toolkit. It is a Java package that can be imported as java.awt.* It consists of platform-independent windowing, graphics, and user interface tools for programmers to use when building up applets and/or stand-alone Java applications.

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Abstract Windowing Toolkit (AWT)


AWT classes form 3 categories:
Graphics
colors, fonts, images, polygons, draws stuff, defines events

Components
GUI components: buttons, menus, frames (window), panel (w/o window), dialog (window)

Layout Managers
Container class contains components, layout managers Gives rule for graphical layout of components in a container Ex: layout components in a grid

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

AWT Class Hierarchy (partial)

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Component
Component is an abstract class. All other classes are non-abstract (concrete). Component class is superclass of all the non-menu related user interface classes. It provides support for event handling, drawing of components etc. Some of the methods of Component class are void setForeground(Color c) void setBackground(Color c)
CS/IS F213 First Semester 2012-13 BITS Pilani, Hyderabad Campus

Lifecycle resources of the Component class.

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Physical appearance resources of the Component class.

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Size and location resources of the Component class.

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Event handling resources of the Component class.

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Painting resources of the Component class.

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Miscellaneous methods of the Component class.

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Containers
The AWT provides four container classes. Window Frame(MyFrame1.java, MyFrame2.java, MyFrame3.java, MyFrameClose.java, demo.java) Dialogue Panel

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Button class

CLICK

button.java

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Labels and Text Fields

lab_txt.java
CS/IS F213 First Semester 2012-13 BITS Pilani, Hyderabad Campus

GUI Components
Button Canvas
Roll your own GUI components

CLICK

Checkbox
Maintains boolean state

Checkboxgroup
Combines checkboxes into radio buttons

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

GUI Components (cont.)


Choice
Menu of options drops down from button Currently selected option is button label

Label
Displays 1 line of text (read-only)

Enter name:

Scrollbar
You specify orientation (horz, vert, and min/max range) Event returned specifies

#lines or pages to scroll, or


absolute position to scroll to

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

GUI Components (cont.)


List
Displays list of strings as N rows Adds scrollbar if necessary Allows single and multiple selection Method to return selected item indexes

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

GUI Components (cont.)


TextComponent
Displays text Can be editable (getText() returns text) Can be selectable

TextField
One line TextComponent setEchoCharacter() allows password entry

TextArea
Multiline TextComponent

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

GUI Components (cont.)


Window Top level window without borders, Menubar show() makes window visible toFront(), toBack() pack() resizes window to fit components in it dispose() frees resources when window is not needed Example use: pop-up menu

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

GUI Components (cont.)


Dialog
A window for dialog box Can be modal

Frame
A window with title, menubar, icon, cursor

Panel
Alternative to window e.g., for display of Applet in Web browser

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Summary

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Anda mungkin juga menyukai