ADVANCED JAVA PROGRAMMING AJP Marks Distribution Online Exam
ADVANCED JAVA PROGRAMMING (AJP) Marks Distribution Online Exam : - 100 PR : - 50 TW : - 50 Total : -200
INTRODUCTION TO ABSTRACT WINDOW TOOLKIT (AWT) 24 Marks
Introduction to AWT l AWT Package l l A complete set of UI Support for UI containers An event system Techniques and code space for laying out UI components in such a way that permits platform independent UI design
Working with Windows and AWT l l l An applet is a window based program. An applet waits until an event occurs. AWT notifies the applet about an event by calling an event handler. Applet must perform specific actions in response to events.
AWT Classes
Window Fundamentals Q. Give the meaning of following terms 1. Frame 2. Panel Q. Give the meaning of following terms 1. Component 2. Panel
Working with Frame Window l Frame’s constructors: Frame( ) Frame(String title) l Setting the Frame’s Size void set. Size(int new. Width, int new. Height) void set. Size(Dimension new. Size) Dimension get. Size( ) l Hiding and Showing a Window void set. Visible(boolean visible. Flag)
Working with Frame Window (cont. . ) Q. What is frame ? How do you create a frame ? Show with an example ? Q. What is frame ? Write procedure to close frame void set. Title(String new. Title) with the help of example ? l Setting a Window’s Title l Closing a Frame Window set. Visible(false) To perform window-close event we must implement windows. Closing() method of Window. Listener Frame Example 1 Frame Example 3 Frame Example 2
Frame Window in an Applet Example HTML Page
Creating a Windowed Program l Example
Using AWT Controls, Layout Manager And Menus l Types of Control l l l l Text. Fields Push buttons Check boxes Choice lists Lists Scroll bars Text editing Adding and Removing Controls Component add(Component Obj) void remove(Component Obj)
Labels l l A Label is an object of type Label, and it contains a string, which it displays. Label defines the following constructors: l l Label( ) Label(String str, int how) Label. LEFT Label. RIGHT Label. CENTER These methods are shown here: l l void set. Text(String str) String get. Text( ) Program void set. Alignment(int how) int get. Alignment( ) HTML Page
Buttons l l A push button is a component that contains a label and that generates an event when it is pressed Button defines the following constructors: l l l Button( ) Button(String s Methods are shown here: l l void set. Label(String str) String get. Label( ) Program HTML Page
Text. Field l l Text fields allow the user to enter strings and to edit the text using the arrow keys, cut and paste keys, and mouse selections. Text. Field defines the following constructors: Text. Field( ) Text. Field(int num. Chars) Text. Field(String str, int num. Chars) l These methods are shown here: void set. Text(String str) String get. Text( ) String get. Selected. Text( ) Void set. Editable(boolean can. Edit) int set. Echo. Char(char ch ) Program HTML Page
Text. Area l Sometimes a single line of text input is not enough for a given task. To handle these situations, the AWT includes a simple multiline editor called Text. Area( ) Text. Area(int num. Lines, int num. Chars) Text. Area(String str, int num. Lines, int num. Chars, int s. Bars) SCROLLBARS_BOTH SCROLLBARS_NONE SCROLLBARS_HORIZONTAL_ONLY SCROLLBARS_VERTICAL_ONLY
Check Boxes l l A check box is a control that is used to turn an option on or off. Checkbox supports these constructors: Checkbox( ) Checkbox(String str, boolean on) l These methods are as follows: boolean get. State( ) void set. State(boolean on) String get. Label( ) void set. Label(String str) Program HTML Page
Check. Boxes Group l l It is possible to create a set of mutually exclusive check boxes in which one and only one check box in the group can be checked at any one time. These check boxes are often called radio buttons Constructor Checkbox(String str, boolean on, Checkbox. Group cb. Group) Checkbox(String str, Checkbox. Group cb. Group, boolean on) l Methods Program Checkbox get. Selected. Checkbox( ) HTML Page void set. Selected. Checkbox(Checkbox which)
Choice Controls l The Choice class is used to create a pop-up list of items from which the user may choose. Thus, a Choice control is a form of menu. l Methods void add(String name) String get. Selected. Item( ) int get. Selected. Index( ) int get. Item. Count( ) void select(int index) void select(String name) String get. Item(int index) Program HTML Page
Lists l The List class provides a compact, multiplechoice, scrolling selection list. l List provides these constructors: List( ) List(int num. Rows, boolean multiple. Select) l Methods void add(String name) void add(String name, int index) String get. Selected. Item( ) int get. Selected. Index( )
String[ ] get. Selected. Items( ) int[ ] get. Selected. Indexes( ) int get. Item. Count( ) void select(int index) String get. Item(int index) Program HTML Demo
Layout Manager l Layout Manager is set by set. Layout() l Default Layout Manager Pannel, Applet Flow Layout Frame Border Layout l General Form void set. Layout(Layout. Manager lay. Obj)
Flow Layout l Constructors l l l Flow. Layout() Flow. Layout(int how) i. e. LEFT, CENTER, RIGHT Flow. Layout(int how, int horz, int vert) Program HTML Page
Border Layout l Constructors defined by Border. Layout: Border. Layout( ) Border. Layout(int horz, int vert) Border. Layout defines the following constants that specify the regions: Border. Layout. CENTER Border. Layout. SOUTH Border. Layout. EAST Border. Layout. WEST Border. Layout. NORTH l void add(Component comp. Obj, Object region); Program HTML Page
Grid Layout l The constructors supported by Grid. Layout are shown here: Grid. Layout( ) Grid. Layout(int num. Rows, int num. Columns, int horz, int vert) Program HTML Page
Card Layout l Card. Layout provides these two constructors: Card. Layout( ) Card. Layout(int horz, int vert) void first(Container deck) void last(Container deck) void next(Container deck) void previous(Container deck) void show(Container deck, String card. Name) Program HTML Page
Dialog Boxes l l Dialog(Frame parent. Window, boolean mode) Dialog(Frame parent. Window, String title, boolean mode) Program HTML File
Menu Bars and Menu(String option. Name) Menu(String option. Name, boolean removable) Menu. Item(String item. Name) Checkbox. Menu. Item(String item. Name, boolean on) boolean get. State( ) void set. State(boolean checked) Program
- Slides: 28