java

24
ABSTRACT WINDOW TOOLKIT

description

AWT

Transcript of java

Page 1: java

ABSTRACT WINDOW TOOLKIT

Page 2: java

COMPONENT: Is an abstract class which encapsulates all the

attributes of a visual components. Include almost 100 public methods in components. Are responsible for managing keyboard input,

mouse input and entry/exit etc.

CONTAINER: Is an abstract subclass of component, which has an

additional methods that allow other components to be nested inside it.

PANEL: is a concrete subclass of a component. We can give any kind of behavior and appearance

onto a canvas . Eg On a blank canvas we can paint any style

component we want.

Page 3: java

Label Subclass of Canvas that has an additional

functionality of knowing how to paint a particular string aligned inside the bound of label components.

These attributes may be manipulated using the getFont/setFont and getForeground/setForeground method pairs.

Three constants defined in Label to indicate alignment; LEFT, RIGHT and CENTER.

Page 4: java

Buttono Is a component use to invoke some action

when the user presses and releases it.o It is labeled with String which can’t be

aligned like Label object; (they are always centered inside the button.

Page 5: java

Checkboxo Is like a Label with a small button next to it

that you can click to toggle the state of a check mark.

o Is often used to select a boolean condition.o We can get/set current state of check mark

with getState/checkState methods.o While constructing checkbox we can use

String label and optionally Boolean to specify initial state of check mark.

Page 6: java

CheckboxGroupo Similar to Checkbox.o Allows u to create a group of choices which can only

be selected one at a time.o getCheckboxGroup/setCheckboxGroup method use to

set and get particular group.o getCurrent/setCurrent used to get/set currently

selected checkbox.o Last eg. Using checkboxGroup.

Page 7: java

Choice o Is used for creating a pop-up selection menu.o A choice component takes up only enough space to

show the currently selected item.o When user clicks on it, the whole menu of choices

pops up and a new selection can be made.o Each item in menu is a String which are left-justified

label in order they are added to choice object.o Method addItem is used to add new string to Choice.o Countitem- returns no of items in choice menu.o Getselecteditem method- to get currently selected

labelo getselectedIndex method- to get the zero based index

integer index.

Page 8: java
Page 9: java

List It provides a compact, multiple choice, scrolling

selection list. Its unlike choice object which always show the

single selected item in menu.

Page 10: java

Scrollbaro Is used to select a continuous values between

a specified minimum and maximum.o The scrollbar class has number of methods f

or different operations.o Constructor allows us to specify orientation

using constants HORIZANTAL/VERTICAL.o Methods getValue/setValue used to get /set

current value of a scrollbar.o getMinimum/getMaximum used to get

minimum/maximum values .

Page 11: java
Page 12: java

TextField It implements a single-line text-entry

area,often used for form and other typed user input.

TextField constructor allows us to create TextFields of specific character width and default value.

Methods setText/getText used to set/get its current value.

Method echoCharIsset is used to disable/enable echoing of character.

Page 13: java
Page 14: java

TextArea It is used when single line of text input is not

enough for given task. AWT includes a very simple ,plain text ,

multiline editor called TextArea. Constructor takes string value as a initial

text , no of rows and no of columns to be displayed.

3 methods to modify contentsi) AppendTextii) InsertTextiii)ReplaceText

Page 15: java
Page 16: java

Layout Means how all of the above discussed

components are arranged or laid out on panel.

Arrangement of components when size ie. Width or height of component is not available

Manual layout of all above discussed components is tedious.

So to overcome above problems, each class uses LayoutManager keps track of number of components.

Layoutmanager is notified each time a component is added to panel.

Whenever a panel is resized LayoutManager is consulted via minimumlayoutsize or prefferedlayoutsize.

Page 17: java

Different layout manager java includes arei) Flowlayout It implements simple layout style, similar to

how words flow in a text-editor. Components are laid out from the upper-left

corner, left to right and top to bottom. When no more components fit on the line,

the next one appears on the next line. Each line is either left , right or center

aligned using constants LEFT,RIGHT,CENER.

Page 18: java
Page 19: java

ii)Borderlayout It implements a common layout style for top

level windows which has four fixed width components at the edges and one large area in center that grows in two dimensions.

Each area named with areas North, South, East , West represents four sides and center is the middle area.

Page 20: java
Page 21: java

iii)GridLayout It arranges all the components in a simple

uniform grid Constructer is used to define number of rows

and columns in a panel layout. Eg 3 X 3 grid with 8 components.

Page 22: java

Insets It is used to inset a panel so that it has a

bored much like the horizantal and vertical gap in layout managers.

In order to cause a panel to have its edges inset, we should override the inset to return a new instance of Inset with four integer representing the width of the top, bottom, left and right edges.

public Insets insets(){ return new Insets(10,10,10,10); }

Page 23: java

CardLayout Is unique from other layout managers in that

it represents several different layouts that can be thought of as living on separate index cards that can be shuffled so that anyone card is on top at a given time.

Used for interfaces that have optional components which can be dynamically enabled and disabled upon user input.

Page 24: java

Thank you All