SlideShare a Scribd company logo
Java AWT (Abstract Window Toolkit)
Elizabeth Alexander
Hindustan University
Java AWT
● Java AWT (Abstract Window Toolkit) is an API to develop GUI or window-
based applications in java.
● Java AWT components are platform-dependent i.e. components are displayed
according to the view of operating system.
● The java.awt package provides classes for AWT API such as TextField, Label,
TextArea, RadioButton, CheckBox, Choice, List etc.
● The AWT was designed to provide a common set of tools for graphical user
interface design that work on a variety of platforms.
Java AWT Controls
The hierarchy of Java AWT classes
Java AWT Controls
● Container : The Container is a component in AWT that can contain another
components like buttons, textfields, labels etc. The classes that extends Container
class are known as container such as Frame, Dialog and Panel.
● Window : The window is the container that have no borders and menu bars. You
must use frame, dialog or another window for creating a window.
● Panel : The Panel is the container that doesn't contain title bar and menu bars. It
can have other components like button, textfield etc.
● Frame : The Frame is the container that contain title bar and can have menu
bars. It can have other components like button, textfield etc.
AWT UI Elements
● Label - A Label object is a component for placing text in a container.
● Button - This class creates a labeled button.
● Check Box - A check box is a graphical component that can be in either an
on(true) or off (false) state.
● Check Box Group - The CheckboxGroup class is used to group the set of
checkbox.
● List - The List component presents the user with a scrolling list of text items.
● Text Field - A TextField object is a text component that allows for the editing of a
single line of text.
● Text Area - A TextArea object is a text component that allows for the editing of a
multiple lines of text.
● Choice - A Choice control is used to show pop up menu of choices. Selected
choice is shown on the top of the menu.
AWT UI Elements Cont...
● Canvas - A Canvas control represents a rectangular area where application can
draw something or can receive inputs created by user.
● Image - An Image control is superclass for all image classes representing
graphical images.
● Scroll Bar - A Scrollbar control represents a scroll bar component in order to
enable user to select from range of values.
● Dialog - A Dialog control represents a top-level window with a title and a border
used to take some form of input from the user.
● File Dialog - A FileDialog control represents a dialog window from which the user
can select a file.
Java Event Handling
Event
● Change in the state of an object is known as event i.e. event describes the
change in state of source.
● Events are generated as result of user interaction with the graphical user
interface components.
● For example, clicking on a button, moving the mouse, entering a character
through keyboard,selecting an item from list, scrolling the page are the activities
that causes an event to happen.
Types of Event
The events can be broadly classified into two categories:
● Foreground Events
● Background Events
Types of Event
Foreground Events - Those events which require the direct interaction of user.
● They are generated as consequences of a person interacting with the graphical
components in Graphical User Interface.
● For example, clicking on a button, moving the mouse, entering a character
through keyboard,selecting an item from list, scrolling the page etc.
Background Events - Those events that require the interaction of end user are known
as background events.
● Operating system interrupts, hardware or software failure, timer expires, an
operation completion are the example of background events.
Event Handling
● Event Handling is the mechanism that controls the event and decides what should
happen if an event occurs.
● This mechanism have the code which is known as event handler that is executed
when an event occurs.
● Java Uses the Delegation Event Model to handle the events. This model defines
the standard mechanism to generate and handle the events.
● The Delegation Event Model has the following key participants namely:
○ Source - The source is an object on which event occurs.
■ Source is responsible for providing information of the occurred event to
it's handler.
Event Handling
○ Listener - It is also known as event handler.
○ Listener is responsible for generating response to an event.
○ From java implementation point of view the listener is also an object.
○ Listener waits until it receives an event.
○ Once the event is received , the listener process the event and then
returns.
Steps involved in event handling
● The User clicks the button and the event is generated.
● Now the object of concerned event class is created automatically and information
about the source and the event get populated with in same object.
● Event object is forwarded to the method of registered listener class.
● The method is now get executed and returns.
Java Adapter Classes
● Java adapter classes provide the default implementation of listener interfaces.
● The adapter classes are found in java.awt.event, java.awt.dnd and
javax.swing.event packages.
Working with Color, and Font.
Working with Color
● Java supports color in a portable, device independent fashion
● The AWT color system allows you to specify any color you want
● Color is encapsulated by the Color class
● The most commonly used constructors are
■ Color(int red, int green, int blue)
■ Color(int rgbValue)
■ Color(float red, float green, float blue)
Working with Color
● The first constructor takes three integers that specify the color as a mix of red,
green, and blue •
● These values must be between 0 and 255
● Example : new Color(255, 100, 100); // light red
● The second color constructor takes a single integer that contains the mix of red,
green, and blue packed into an integer.
● The integer is organized with red in bits 16 to 23, green in bits 8 to 15, and blue in
bits 0 to 7
● Example : int newRed = (0xff000000 | (0xc0 << 16) | (0x00 << 8) | 0x00);
Color darkRed = new Color(newRed);
● The final constructor, Color(float, float, float), takes three float values (between 0.0
and 1.0) that specify the relative mix of red, green, and blue
Setting the Current Graphics Color
● By default, graphics objects are drawn in the current foreground color
● We can change this color by calling the Graphics method setColor( ) – void
setColor(Color newColor);
● Here, newColor specifies the new drawing color
● We can obtain the current color by calling getColor( ) – Color getColor( );
Working with Fonts
● The AWT supports multiple type fonts
● Fonts are encapsulated by the Font class
Creating and Selecting a Font
● To select a new font, you must first construct a Font object that describes that font
● One Font constructor has this general form – Font(String fontName, int
fontStyle, int pointSize) ;
■ Here, fontName specifies the name of the desired font
● To use a font that you have created, you must select it using setFont( ), which is
defined by Component
● It has this general form – void setFont(Font fontObj) ;
■ Here, fontObj is the object that contains the desired font
Ad

More Related Content

What's hot (20)

Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
Google
 
Packages in java
Packages in javaPackages in java
Packages in java
Elizabeth alexander
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
VINOTH R
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
Madishetty Prathibha
 
Applets in java
Applets in javaApplets in java
Applets in java
Wani Zahoor
 
Java package
Java packageJava package
Java package
CS_GDRCST
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
Raja Sekhar
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
Hamid Ghorbani
 
Java threads
Java threadsJava threads
Java threads
Prabhakaran V M
 
Static Members-Java.pptx
Static Members-Java.pptxStatic Members-Java.pptx
Static Members-Java.pptx
ADDAGIRIVENKATARAVIC
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
Operators in java
Operators in javaOperators in java
Operators in java
AbhishekMondal42
 
Event handling
Event handlingEvent handling
Event handling
swapnac12
 
Java Networking
Java NetworkingJava Networking
Java Networking
Sunil OS
 
Event handling
Event handlingEvent handling
Event handling
Shree M.L.Kakadiya MCA mahila college, Amreli
 
Java swing
Java swingJava swing
Java swing
Apurbo Datta
 
Java Tokens
Java  TokensJava  Tokens
Java Tokens
Madishetty Prathibha
 
JVM
JVMJVM
JVM
baabtra.com - No. 1 supplier of quality freshers
 
Method overloading
Method overloadingMethod overloading
Method overloading
Lovely Professional University
 

Similar to Java awt (abstract window toolkit) (20)

Ajp notes-chapter-01
Ajp notes-chapter-01Ajp notes-chapter-01
Ajp notes-chapter-01
Ankit Dubey
 
tL19 awt
tL19 awttL19 awt
tL19 awt
teach4uin
 
Ajp notes-chapter-01
Ajp notes-chapter-01Ajp notes-chapter-01
Ajp notes-chapter-01
JONDHLEPOLY
 
Creating GUI.pptx Gui graphical user interface
Creating GUI.pptx Gui graphical user interfaceCreating GUI.pptx Gui graphical user interface
Creating GUI.pptx Gui graphical user interface
pikachu02434
 
GUI.pdf
GUI.pdfGUI.pdf
GUI.pdf
Poornima E.G.
 
GUI.pdf
GUI.pdfGUI.pdf
GUI.pdf
AbuSufyan82
 
JAVA (UNIT 5)
JAVA (UNIT 5)JAVA (UNIT 5)
JAVA (UNIT 5)
Dr. SURBHI SAROHA
 
GUI Programming In Java
GUI Programming In JavaGUI Programming In Java
GUI Programming In Java
yht4ever
 
Swing and Graphical User Interface in Java
Swing and Graphical User Interface in JavaSwing and Graphical User Interface in Java
Swing and Graphical User Interface in Java
babak danyal
 
28-GUI application.pptx.pdf
28-GUI application.pptx.pdf28-GUI application.pptx.pdf
28-GUI application.pptx.pdf
NguynThiThanhTho
 
SWING USING JAVA WITH VARIOUS COMPONENTS
SWING USING  JAVA WITH VARIOUS COMPONENTSSWING USING  JAVA WITH VARIOUS COMPONENTS
SWING USING JAVA WITH VARIOUS COMPONENTS
bharathiv53
 
Graphical Programming in Python Using Tkinter
Graphical Programming in Python Using TkinterGraphical Programming in Python Using Tkinter
Graphical Programming in Python Using Tkinter
IndianInstituteofCom
 
graphical user interface using python easy
graphical user interface using python easygraphical user interface using python easy
graphical user interface using python easy
ravipati23phd7217
 
Python - gui programming (tkinter)
Python - gui programming (tkinter)Python - gui programming (tkinter)
Python - gui programming (tkinter)
Learnbay Datascience
 
AWT stands for Abstract Window Toolkit. AWT is collection of classes and int...
AWT stands for Abstract Window Toolkit.  AWT is collection of classes and int...AWT stands for Abstract Window Toolkit.  AWT is collection of classes and int...
AWT stands for Abstract Window Toolkit. AWT is collection of classes and int...
Prashant416351
 
Awt
AwtAwt
Awt
Rakesh Patil
 
Java Applet
Java AppletJava Applet
Java Applet
Shree M.L.Kakadiya MCA mahila college, Amreli
 
FlutterArchitecture FlutterDevelopement (1).pptx
FlutterArchitecture FlutterDevelopement (1).pptxFlutterArchitecture FlutterDevelopement (1).pptx
FlutterArchitecture FlutterDevelopement (1).pptx
hw813301
 
FlutterArchitecture FlutterArchitecture.ppt
FlutterArchitecture FlutterArchitecture.pptFlutterArchitecture FlutterArchitecture.ppt
FlutterArchitecture FlutterArchitecture.ppt
KevinNemo
 
unit3.3.pptx
unit3.3.pptxunit3.3.pptx
unit3.3.pptx
VeenaNaik23
 
Ajp notes-chapter-01
Ajp notes-chapter-01Ajp notes-chapter-01
Ajp notes-chapter-01
Ankit Dubey
 
Ajp notes-chapter-01
Ajp notes-chapter-01Ajp notes-chapter-01
Ajp notes-chapter-01
JONDHLEPOLY
 
Creating GUI.pptx Gui graphical user interface
Creating GUI.pptx Gui graphical user interfaceCreating GUI.pptx Gui graphical user interface
Creating GUI.pptx Gui graphical user interface
pikachu02434
 
GUI Programming In Java
GUI Programming In JavaGUI Programming In Java
GUI Programming In Java
yht4ever
 
Swing and Graphical User Interface in Java
Swing and Graphical User Interface in JavaSwing and Graphical User Interface in Java
Swing and Graphical User Interface in Java
babak danyal
 
28-GUI application.pptx.pdf
28-GUI application.pptx.pdf28-GUI application.pptx.pdf
28-GUI application.pptx.pdf
NguynThiThanhTho
 
SWING USING JAVA WITH VARIOUS COMPONENTS
SWING USING  JAVA WITH VARIOUS COMPONENTSSWING USING  JAVA WITH VARIOUS COMPONENTS
SWING USING JAVA WITH VARIOUS COMPONENTS
bharathiv53
 
Graphical Programming in Python Using Tkinter
Graphical Programming in Python Using TkinterGraphical Programming in Python Using Tkinter
Graphical Programming in Python Using Tkinter
IndianInstituteofCom
 
graphical user interface using python easy
graphical user interface using python easygraphical user interface using python easy
graphical user interface using python easy
ravipati23phd7217
 
Python - gui programming (tkinter)
Python - gui programming (tkinter)Python - gui programming (tkinter)
Python - gui programming (tkinter)
Learnbay Datascience
 
AWT stands for Abstract Window Toolkit. AWT is collection of classes and int...
AWT stands for Abstract Window Toolkit.  AWT is collection of classes and int...AWT stands for Abstract Window Toolkit.  AWT is collection of classes and int...
AWT stands for Abstract Window Toolkit. AWT is collection of classes and int...
Prashant416351
 
FlutterArchitecture FlutterDevelopement (1).pptx
FlutterArchitecture FlutterDevelopement (1).pptxFlutterArchitecture FlutterDevelopement (1).pptx
FlutterArchitecture FlutterDevelopement (1).pptx
hw813301
 
FlutterArchitecture FlutterArchitecture.ppt
FlutterArchitecture FlutterArchitecture.pptFlutterArchitecture FlutterArchitecture.ppt
FlutterArchitecture FlutterArchitecture.ppt
KevinNemo
 
Ad

More from Elizabeth alexander (10)

Java applet
Java appletJava applet
Java applet
Elizabeth alexander
 
Io streams
Io streamsIo streams
Io streams
Elizabeth alexander
 
Multithreading programming in java
Multithreading programming in javaMultithreading programming in java
Multithreading programming in java
Elizabeth alexander
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
Elizabeth alexander
 
Java interfaces
Java   interfacesJava   interfaces
Java interfaces
Elizabeth alexander
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
Elizabeth alexander
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
Elizabeth alexander
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
Elizabeth alexander
 
Quantitative Aptitude- Number System
Quantitative Aptitude- Number SystemQuantitative Aptitude- Number System
Quantitative Aptitude- Number System
Elizabeth alexander
 
Java Programming
Java ProgrammingJava Programming
Java Programming
Elizabeth alexander
 
Ad

Recently uploaded (20)

Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
IJCNCJournal
 
Design of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdfDesign of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdf
Kamel Farid
 
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdfML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
rameshwarchintamani
 
DED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedungDED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedung
nabilarizqifadhilah1
 
Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...
Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...
Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...
Journal of Soft Computing in Civil Engineering
 
Dynamics of Structures with Uncertain Properties.pptx
Dynamics of Structures with Uncertain Properties.pptxDynamics of Structures with Uncertain Properties.pptx
Dynamics of Structures with Uncertain Properties.pptx
University of Glasgow
 
A Survey of Personalized Large Language Models.pptx
A Survey of Personalized Large Language Models.pptxA Survey of Personalized Large Language Models.pptx
A Survey of Personalized Large Language Models.pptx
rutujabhaskarraopati
 
Building-Services-Introduction-Notes.pdf
Building-Services-Introduction-Notes.pdfBuilding-Services-Introduction-Notes.pdf
Building-Services-Introduction-Notes.pdf
Lawrence Omai
 
Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control
 
Machine Learning basics POWERPOINT PRESENETATION
Machine Learning basics POWERPOINT PRESENETATIONMachine Learning basics POWERPOINT PRESENETATION
Machine Learning basics POWERPOINT PRESENETATION
DarrinBright1
 
JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...
JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...
JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...
Reflections on Morality, Philosophy, and History
 
introduction technology technology tec.pptx
introduction technology technology tec.pptxintroduction technology technology tec.pptx
introduction technology technology tec.pptx
Iftikhar70
 
Control Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptxControl Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptx
vvsasane
 
Interfacing PMW3901 Optical Flow Sensor with ESP32
Interfacing PMW3901 Optical Flow Sensor with ESP32Interfacing PMW3901 Optical Flow Sensor with ESP32
Interfacing PMW3901 Optical Flow Sensor with ESP32
CircuitDigest
 
PRIZ Academy - Functional Modeling In Action with PRIZ.pdf
PRIZ Academy - Functional Modeling In Action with PRIZ.pdfPRIZ Academy - Functional Modeling In Action with PRIZ.pdf
PRIZ Academy - Functional Modeling In Action with PRIZ.pdf
PRIZ Guru
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
Nanometer Metal-Organic-Framework Literature Comparison
Nanometer Metal-Organic-Framework  Literature ComparisonNanometer Metal-Organic-Framework  Literature Comparison
Nanometer Metal-Organic-Framework Literature Comparison
Chris Harding
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
IJCNCJournal
 
Design of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdfDesign of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdf
Kamel Farid
 
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdfML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
rameshwarchintamani
 
DED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedungDED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedung
nabilarizqifadhilah1
 
Dynamics of Structures with Uncertain Properties.pptx
Dynamics of Structures with Uncertain Properties.pptxDynamics of Structures with Uncertain Properties.pptx
Dynamics of Structures with Uncertain Properties.pptx
University of Glasgow
 
A Survey of Personalized Large Language Models.pptx
A Survey of Personalized Large Language Models.pptxA Survey of Personalized Large Language Models.pptx
A Survey of Personalized Large Language Models.pptx
rutujabhaskarraopati
 
Building-Services-Introduction-Notes.pdf
Building-Services-Introduction-Notes.pdfBuilding-Services-Introduction-Notes.pdf
Building-Services-Introduction-Notes.pdf
Lawrence Omai
 
Machine Learning basics POWERPOINT PRESENETATION
Machine Learning basics POWERPOINT PRESENETATIONMachine Learning basics POWERPOINT PRESENETATION
Machine Learning basics POWERPOINT PRESENETATION
DarrinBright1
 
introduction technology technology tec.pptx
introduction technology technology tec.pptxintroduction technology technology tec.pptx
introduction technology technology tec.pptx
Iftikhar70
 
Control Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptxControl Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptx
vvsasane
 
Interfacing PMW3901 Optical Flow Sensor with ESP32
Interfacing PMW3901 Optical Flow Sensor with ESP32Interfacing PMW3901 Optical Flow Sensor with ESP32
Interfacing PMW3901 Optical Flow Sensor with ESP32
CircuitDigest
 
PRIZ Academy - Functional Modeling In Action with PRIZ.pdf
PRIZ Academy - Functional Modeling In Action with PRIZ.pdfPRIZ Academy - Functional Modeling In Action with PRIZ.pdf
PRIZ Academy - Functional Modeling In Action with PRIZ.pdf
PRIZ Guru
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
Nanometer Metal-Organic-Framework Literature Comparison
Nanometer Metal-Organic-Framework  Literature ComparisonNanometer Metal-Organic-Framework  Literature Comparison
Nanometer Metal-Organic-Framework Literature Comparison
Chris Harding
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 

Java awt (abstract window toolkit)

  • 1. Java AWT (Abstract Window Toolkit) Elizabeth Alexander Hindustan University
  • 2. Java AWT ● Java AWT (Abstract Window Toolkit) is an API to develop GUI or window- based applications in java. ● Java AWT components are platform-dependent i.e. components are displayed according to the view of operating system. ● The java.awt package provides classes for AWT API such as TextField, Label, TextArea, RadioButton, CheckBox, Choice, List etc. ● The AWT was designed to provide a common set of tools for graphical user interface design that work on a variety of platforms.
  • 3. Java AWT Controls The hierarchy of Java AWT classes
  • 4. Java AWT Controls ● Container : The Container is a component in AWT that can contain another components like buttons, textfields, labels etc. The classes that extends Container class are known as container such as Frame, Dialog and Panel. ● Window : The window is the container that have no borders and menu bars. You must use frame, dialog or another window for creating a window. ● Panel : The Panel is the container that doesn't contain title bar and menu bars. It can have other components like button, textfield etc. ● Frame : The Frame is the container that contain title bar and can have menu bars. It can have other components like button, textfield etc.
  • 5. AWT UI Elements ● Label - A Label object is a component for placing text in a container. ● Button - This class creates a labeled button. ● Check Box - A check box is a graphical component that can be in either an on(true) or off (false) state. ● Check Box Group - The CheckboxGroup class is used to group the set of checkbox. ● List - The List component presents the user with a scrolling list of text items. ● Text Field - A TextField object is a text component that allows for the editing of a single line of text. ● Text Area - A TextArea object is a text component that allows for the editing of a multiple lines of text. ● Choice - A Choice control is used to show pop up menu of choices. Selected choice is shown on the top of the menu.
  • 6. AWT UI Elements Cont... ● Canvas - A Canvas control represents a rectangular area where application can draw something or can receive inputs created by user. ● Image - An Image control is superclass for all image classes representing graphical images. ● Scroll Bar - A Scrollbar control represents a scroll bar component in order to enable user to select from range of values. ● Dialog - A Dialog control represents a top-level window with a title and a border used to take some form of input from the user. ● File Dialog - A FileDialog control represents a dialog window from which the user can select a file.
  • 7. Java Event Handling Event ● Change in the state of an object is known as event i.e. event describes the change in state of source. ● Events are generated as result of user interaction with the graphical user interface components. ● For example, clicking on a button, moving the mouse, entering a character through keyboard,selecting an item from list, scrolling the page are the activities that causes an event to happen. Types of Event The events can be broadly classified into two categories: ● Foreground Events ● Background Events
  • 8. Types of Event Foreground Events - Those events which require the direct interaction of user. ● They are generated as consequences of a person interacting with the graphical components in Graphical User Interface. ● For example, clicking on a button, moving the mouse, entering a character through keyboard,selecting an item from list, scrolling the page etc. Background Events - Those events that require the interaction of end user are known as background events. ● Operating system interrupts, hardware or software failure, timer expires, an operation completion are the example of background events.
  • 9. Event Handling ● Event Handling is the mechanism that controls the event and decides what should happen if an event occurs. ● This mechanism have the code which is known as event handler that is executed when an event occurs. ● Java Uses the Delegation Event Model to handle the events. This model defines the standard mechanism to generate and handle the events. ● The Delegation Event Model has the following key participants namely: ○ Source - The source is an object on which event occurs. ■ Source is responsible for providing information of the occurred event to it's handler.
  • 10. Event Handling ○ Listener - It is also known as event handler. ○ Listener is responsible for generating response to an event. ○ From java implementation point of view the listener is also an object. ○ Listener waits until it receives an event. ○ Once the event is received , the listener process the event and then returns. Steps involved in event handling ● The User clicks the button and the event is generated. ● Now the object of concerned event class is created automatically and information about the source and the event get populated with in same object. ● Event object is forwarded to the method of registered listener class. ● The method is now get executed and returns.
  • 11. Java Adapter Classes ● Java adapter classes provide the default implementation of listener interfaces. ● The adapter classes are found in java.awt.event, java.awt.dnd and javax.swing.event packages. Working with Color, and Font. Working with Color ● Java supports color in a portable, device independent fashion ● The AWT color system allows you to specify any color you want ● Color is encapsulated by the Color class ● The most commonly used constructors are ■ Color(int red, int green, int blue) ■ Color(int rgbValue) ■ Color(float red, float green, float blue)
  • 12. Working with Color ● The first constructor takes three integers that specify the color as a mix of red, green, and blue • ● These values must be between 0 and 255 ● Example : new Color(255, 100, 100); // light red ● The second color constructor takes a single integer that contains the mix of red, green, and blue packed into an integer. ● The integer is organized with red in bits 16 to 23, green in bits 8 to 15, and blue in bits 0 to 7 ● Example : int newRed = (0xff000000 | (0xc0 << 16) | (0x00 << 8) | 0x00); Color darkRed = new Color(newRed); ● The final constructor, Color(float, float, float), takes three float values (between 0.0 and 1.0) that specify the relative mix of red, green, and blue
  • 13. Setting the Current Graphics Color ● By default, graphics objects are drawn in the current foreground color ● We can change this color by calling the Graphics method setColor( ) – void setColor(Color newColor); ● Here, newColor specifies the new drawing color ● We can obtain the current color by calling getColor( ) – Color getColor( ); Working with Fonts ● The AWT supports multiple type fonts ● Fonts are encapsulated by the Font class
  • 14. Creating and Selecting a Font ● To select a new font, you must first construct a Font object that describes that font ● One Font constructor has this general form – Font(String fontName, int fontStyle, int pointSize) ; ■ Here, fontName specifies the name of the desired font ● To use a font that you have created, you must select it using setFont( ), which is defined by Component ● It has this general form – void setFont(Font fontObj) ; ■ Here, fontObj is the object that contains the desired font
  翻译: