AWT Control Fundamentals Labels • Push buttons • Check boxes • Choice lists • Lists • Scroll bars • Text Editing These controls are subclasses of Component
Previous PDF | Next PDF |
[PDF] Using AWT controls, Layout Managers, and Menus
AWT Control Fundamentals Labels • Push buttons • Check boxes • Choice lists • Lists • Scroll bars • Text Editing These controls are subclasses of Component
[PDF] Preview AWT Tutorial - Tutorialspoint
Abstract Window Toolkit (AWT) is a set of APIs used by Java programmers GUI offers a lot of controls of file system and the operating system while in CUI, you
[PDF] Unit - 2 Abstract Window Toolkit
21 avr 2018 · AWT is heavyweight Its components use the resources of system • The java awt package provides classes for AWT API such as TextField, Label,
[PDF] AWT Components
1: // $Id: LabelDemo java,v 1 2 2004/03/14 15:42:14 justb Exp $ 2: import java awt *; 3: import java applet Applet; 4: 5: //{init 6: public class LabelDemo extends
[PDF] Java Control Fundamentals
Controls are components that allow a user to interact with your application in various ways—for example; a commonly used control is the push button The AWT
[PDF] AWT - WordPresscom
Chapter 01 Introduction to AWT Advanced Java Programming by Mr Kute T B - 2 - Abstract Window Toolkit: The AWT contains numerous classes and
[PDF] javaawt Reference - OReilly
In this way a single event can be sent to many listeners Static methods make it easy to implement event multicasting in component sub- classes Each time an add
[PDF] Unit 4: Using AWT controls, Layout Managers, and - Genuine Notes
Unit-4/ Java Programming-II 1 Collected by Bipin Timalsina Unit 4: Using AWT controls, Layout Managers, and Menus • Controls are components that allow a
[PDF] azure devops command line
[PDF] azure fortigate pricing
[PDF] a^nb^n is not regular
[PDF] baby bar essays
[PDF] baby boom 1950
[PDF] baby boom chart?
[PDF] baby boom france 1945
[PDF] baby boom france 2000
[PDF] baby boom france 2018
[PDF] baby boom france 2019
[PDF] baby boom france date
[PDF] baby boom france graphique
[PDF] baby boom france insee
[PDF] baby boom statistics
Using AWT controls, Layout Managers, and Menus
Controlsarecomponentsthatallowauserto
interactwithyourapplicationegpushbutton.Layoutmanagerautomaticallypositions
componentswithinacontainer.Thus,the appearanceofawindowisdeterminedbya thelayoutmanagerusedtopositionthem.Menubar:Eachentryinamenubaractivatesa
drop-downmenuofoptionsfromwhichtheuser canchoose.Thisconstitutesthemainmenuofan application.Asageneralrule,amenubaris positionedatthetopofawindow.AWT Control Fundamentals
The AWT supports the following types of
controls:ͻ Labels
ͻ Push buttons
ͻ Check bodžes
ͻ Choice lists
ͻ Lists
ͻ Scroll bars
ͻ Tedžt Editing
These controls are subclasses of Component.
Continued..
To add a control in a window, create an instance of the desired control and then add it to a window by calling add( ), which is defined by Component class. One of the form is -Component add(Component compRef)
compRefis a reference to an instance of the control that you want to add. A reference to the object is returned. To remove a control from a window call remove( ). This method is also defined by Container. void remove(Component compRef) compRefis a reference to the control you want to remove.To remove all controls, call
removeAll( )Responding to Controls
Whentheuserclicksonapushbutton,aneventis
generatedthatidentifiesthepushbutton.Theprogramsimplyimplementstheappropriate
controlthatareneededtomonitor.Labels
A label is an object of type Label, and it contains a string, which it displays. Label defines the following constructors:
Label( ) throws HeadlessException
Label(String str) throws HeadlessException
Label(String str, inthow) throws HeadlessExceptionThe first version creates a blank label.
The second version creates a label that contains the string specified by str. This string is left-justified.
The third version creates a label that contains the string specified by strusing the alignment specified by how. The value of how must be one of these three constants: Label.LEFT, Label.RIGHT, or Label.CENTER
Continued..
To set or change the text in a label call
void setText(String str)To return the current label
String getText( )
To set the alignment of the string within the label call void setAlignment(inthow) how must be one of the alignment constants.To get the current alignment call
intgetAlignment( )Example
Create three Labels and add them to Applet-
// Demonstrate Labels import java.awt.*; import java.applet.*; public class LabelDemoextends Applet { public void init() {Label one = new Label("One");
Label two = new Label("Two");
Label three = new Label("Three");
Continued..
// add labels to applet window add(one); add(two); add(three); Note: The labels are organized in the window by the default layout manager.Using Buttons
A push button is a component that contains a label and that generates an event when it is pressed. Push buttons are objects of type Button. Button defines these two constructors:Button( ) throws HeadlessException
Button(String str) throws HeadlessException
The first version creates an empty button. The second creates a button that contains stras a label. After a button has been created, one can set its label by void setLabel(String str)Here, strbecomes the new label for the button.
To retrieve label of a button call
String getLabel( )
Handling ButtonsEach time a button is pressed, an action event is generated.This is sent to any listeners that previously registered an interest in receiving action event notifications from that component.
Each listener implements the ActionListenerinterface. That interface defines the actionPerformed( )method, which is called when an event occurs.
An ActionEventobject is supplied as the argument to this method. It contains both a reference to the button that generated the event and a reference to the action command string associated with the button.
By default, the action command string is the label of the button.