SlideShare a Scribd company logo
JAVA PROGRAMMING - AWT
Prof. Navya Francis
Asst. Professor
Kristu Jayanti College
ABSTRACT WINDOW TOOL KIT
• Java AWT is an API that contains large number of classes and methods
to create and manage graphical user interface ( GUI ) applications.
• The AWT was designed to provide a common set of tools for GUI design
that could work on a variety of platforms.
• AWT was Java’s first GUI Framework.
• AWT is the foundation upon which Swing is made i.e Swing is a
improved GUI API that extends the AWT.
AWT
• Java AWT components are platform-dependent i.e. components are
displayed according to the view of operating system.
• AWT is heavy weight i.e. its components are using the resources of
underlying operating system (OS)
• 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.
JAVA AWT HIERARCHY
COMPONENTS
• All the elements like the button, text fields, scroll bars, etc. are called
components.
• In Java AWT, there are classes for each component as shown in above
diagram.
• In order to place every component in a particular position on a screen,
we need to add them to a container.
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.
• It is basically a screen where the components are placed at their specific
locations.
• Thus it contains and controls the layout of components.
TYPES OF CONTAINERS:
There are four types of containers in Java AWT:
• Window
• Panel
• Frame
• Dialog
TYPES OF CONTAINERS:
• 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. We need to create an instance of Window class to create
this container
• Panel
• The Panel is the container that doesn't contain title bar, border or menu bar. It is generic container
for holding the components. It can have other components like button, text field etc. An instance of
Panel class creates a container, in which we can add components.
TYPES OF CONTAINERS:
• Frame
• The Frame is the container that contain title bar and border and can have
menu bars.
• It can have other components like button, text field, scrollbar etc.
• Frame is most widely used container while developing an AWT application.
• Frame is a subclass of Window and have resizing canvas.
TYPES OF CONTAINERS:
• The Dialog control
• The Dialog control represents a top level window with a border and a
title used to take some form of input from the user.
• It inherits the Window class.
• Unlike Frame, it doesn't have maximize and minimize buttons.
• Frame and Dialog both inherits Window class.
• Frame has maximize and minimize buttons but Dialog doesn't have.
CREATING A FRAME
There are two ways to create a Frame. They are,
• By Instantiating Frame class
• By extending Frame class
POINTS TO REMEMBER:
• While creating a frame (either by instantiating or extending Frame class),
Following two attributes are must for visibility of the frame:
• setSize(int width, int height);
• setVisible(true);
• When you create other components like Buttons, TextFields, etc. Then
you need to add it to the frame by using the method -
add(Component's Object);
• You can add the following method also for resizing the frame -
setResizable(true);
BY INSTANTIATING FRAME CLASS
BY EXTENDING FRAME CLASS
BY EXTENDING FRAME CLASS
UNDERSTANDING LAYOUT MANAGERS
• The layout manager automatically positions all the components within
the container. If we do not use layout manager then also the
components are positioned by the default layout manager.
• Each Container object has a layout manager associated with it.
• A layout manager is an instance of any class that implements the
LayoutManagerinterface.
UNDERSTANDING LAYOUT MANAGERS
• The layout manager is set by the setLayout( ) method.
• If no call to setLayout( ) is made,then the default layout manager is
used.
• Whenever a container is resized (or sized for the first time), the layout
manager is used to position each of the components within it.
• The setLayout( ) method has the following general form:
• void setLayout(LayoutManager layoutObj)
FLOWLAYOUT
• It is the default layout manager.
• FlowLayout implements a simple layout style, which is similar to how words flow in a text editor.
• FlowLayout.LEFT
• FlowLayout.CENTER
• FlowLayout.RIGHT
• FlowLayout.LEADING
• FlowLayout.TRAILING
• These values specify left, center, right, leading edge, and trailing edge alignment, respectively
BORDERLAYOUT
• The BorderLayout class implements a common layout style for top-level windows.
• It has four narrow, fixed-width components at the edges and one large area in the center.
• The four sides are referred to as north, south, east, and west. The middle area is called the center.
BorderLayout defines the following constants that specify the regions:
• BorderLayout.CENTER
• BorderLayout.SOUTH
• BorderLayout.EAST
• BorderLayout.WEST
• BorderLayout.NORTH
AWT CONTROL FUNDAMENTALS
• The AWT supports the following types of controls:
• These controls are subclasses of Component.
• Labels
• Buttons
• Check boxes
• Check box groups
• Choice control
• Lists
• Scroll bar
• Text field
• Text area
ADDING AND REMOVING CONTROLS
• In order to include a control in a window, we must add it to the window.
• So, we must first create an instance of the desired control and then add
it to a window by calling add( ), which is defined by Container.
• Component add(Component compObj)
ADDING AND REMOVING CONTROLS
• Once a control has been added, it will automatically be visible whenever
its parent window is displayed.
• Sometimes we will want to remove a control from a window when the
control is no longer needed.
• For doing this, call remove( ).
• This method is also defined by Container.
• It has this general form: void remove(Component obj) Here, obj is a
reference to the control that we want to remove.
• We can remove all controls by calling removeAll( )
LABEL
• A label is a user for placing text inside the container.
• A label is used only for inputting text.
• The label does not imply that the text can be altered or it can be used as
a button which can be further worked upon.
Label n=new Label("Name:",Label.CENTER);
LABEL
BUTTON
• This command generates a button in the User Interface.
• Clicking on the button would move the command to another page or
another web server which is used to show several other outputs in the
user interface page.
a1=new Button("submit");
a2=new Button("cancel");
BUTTON
CHECK BOXES
• A check box is a control that is used to turn an option on or off. It
consists of a small box that can either contain a check mark or not.
• There is a label associated with each check box that describes what
option the box represents.
• We change the state of a check box by clicking on it. Check boxes can be
used individually or as part of a group.
• Check boxes are objects of the Checkbox class
• Checkbox checkbox1 = new Checkbox("Hello World");
CHECK BOXES
CHECKBOX GROUP
• 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 are often called radio buttons.
• For creating a set of mutually exclusive check boxes, we must first define the
group to which they will belong and then specify that group when we
construct the check boxes.
• Check box groups are objects of type CheckBoxGroup.
CheckboxGroup cb = new CheckboxGroup();
Checkbox checkBox1 = new Checkbox("Hello", cb, true);
checkBox1.setBounds (100,100, 50,50);
CHECKBOX GROUP
MANAGING SCROLL BARS
• Scroll bars are used to select continuous values between a specified
minimum and maximum. Scroll bars may be oriented horizontally or
vertically.
• Each end has an arrow that you can click to move the current value of
the scroll bar one unit in the direction of the arrow.
Scrollbar s=new Scrollbar();
s.setBounds(100,100, 50,100);
MANAGING SCROLL BARS
TEXTFIELD
• The TextField class implements a single-line text-entry area, usually
called an edit control.
• Text fields allow the user to enter strings and to edit the text using the
arrow keys, cut and paste keys, and mouse selections.
na=new TextField(“my name”);
TEXTFIELD
TEXTAREA
• 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 TextArea.
TextArea area=new TextArea("Welcome to the
universe");
area.setBounds(10,30, 300,300);
TEXTAREA
CHOICE CONTROLS
• 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.
• When inactive, a Choice component takes up only enough space to show
the currently selected item. When the user clicks on it, the whole list of
choices pops up, and a new selection can be made.
Choice c=new Choice();
c.setBounds(100,100, 75,75);
c.add("Subject 1");
c.add("Subject 2");
c.add("Subject 3");
CHOICE CONTROLS
LISTS
• The List class provides a compact, multiple-choice, scrolling selection
list.
• Unlike the Choice object, which shows only the single selected item in
the menu, a List object can be constructed to show any number of
choices in the visible Window.
• It can also be created to allow multiple selections.
LISTS
MENU BARS AND MENUS
• A top-level window can have a menu bar associated with it.
• A menu bar displays a list of top-level menu choices.
• Each choice is associated with a drop-down menu.
• This concept is implemented in the AWT by the following classes:
MenuBar, Menu,and MenuItem.
MENU BARS AND MENUS
• In general, a menu bar contains one or more Menu objects. Each Menu
object contains a list of MenuItem objects.
• Each MenuItem object represents something that can be selected by the
user.
• Since Menu is a subclass of MenuItem, a hierarchy of nested submenus
can be created.
• It is also possible to include checkable menu items.
• These are menu options of type CheckboxMenuItem and will have a
check mark next to them when they are selected.
MENU BARS AND MENUS
MENU BARS AND MENUS
• Creating Menubar
MenuBar mb=new MenuBar();
• Menu a creation
Menu mnu1=new Menu("BCA");
Menu mnu2=new Menu("BBA");
• sm1 and sm2 will be treated as submenus
Menu sm1=new Menu("Semester");
Menu sm2=new Menu("Year");
• adding items and submenus to menu
mnu1.add(sm1);
mnu1.add(sm2);
• //adding items to submenu
sm1.add(i1);
sm1.add(i2);
sm2.add(i3);
• //adding menu to menubar
mb.add(mnu1);
mb.add(mnu2);
• Creating menu items
MenuItem i1,i2,i3;
i1=new MenuItem("I");
i2=new MenuItem("II");
i3=new MenuItem("2023");
DIALOG BOXES
• Dialog boxes are primarily used to obtain user input and are often child
windows of a top-level window.
• Dialog boxes don’t have menu bars, but in other respects, they function
like frame windows. (You can add controls to them, for example, in the
same way that you add controls to a frame window.)
• When a modal dialog box is active, all input is directed to it until it is
closed.
DIALOG BOXES
• This means that you cannot access other parts of your program until you
have closed the dialog box.
• When a modeless dialog box is active, input focus can be directed to
another window in your program.
• Thus, other parts of your program remain active and accessible. In the
AWT, dialog boxes are of type Dialog
DIALOG BOXES
FILEDIALOG
• Java provides a built-in dialog box that lets the user specify a file.
• To create a file dialog box, instantiate an object of type FileDialog. This
causes a file dialog box to be displayed.
• Usually, this is the standard file dialog box provided by the operating
system.
FILEDIALOG
HANDLING EVENTS BY EXTENDING AWT
COMPONENTS
• Handling events by extending AWT components.
• The delegation event model was introduced in Event handling, and all of
the programs in this book so far have used that design. But Java also
allows you to handle events by subclassing AWT components.
• Doing so allows you to handle events in much the same way as they
were handled under the original 1.0 version of Java. Of course, this
technique is discouraged, because it has the same disadvantages of the
Java 1.0 event model, the main one being inefficiency.
• To extend an AWT component, you must call the enableEvents( ) method
of Component. Its general form is shown here:
Ad

Recommended

Html forms
Html forms
Er. Nawaraj Bhandari
 
regular expression
regular expression
RohitKumar596173
 
android menus
android menus
Deepa Rani
 
Lecture 5 html table
Lecture 5 html table
AliMUSSA3
 
java programming - applets
java programming - applets
HarshithaAllu
 
Continuations
Continuations
openbala
 
Tail Recursion in data structure
Tail Recursion in data structure
Rumman Ansari
 
Pumping lemma for cfl
Pumping lemma for cfl
Muhammad Zohaib Chaudhary
 
The Switch Statement in java
The Switch Statement in java
Talha Saleem
 
Lecture 7
Lecture 7
shah zeb
 
Regular expressions
Regular expressions
Shiraz316
 
Pumping lemma for regular set h1
Pumping lemma for regular set h1
Rajendran
 
Form Handling using PHP
Form Handling using PHP
Nisa Soomro
 
Aplicaciones con Listas
Aplicaciones con Listas
Fernando Solis
 
Linked list
Linked list
Md. Afif Al Mamun
 
Lecture 8
Lecture 8
shah zeb
 
stacks and queues
stacks and queues
DurgaDeviCbit
 
Hashing
Hashing
VARSHAKUMARI49
 
Cheat Sheet for Machine Learning in Python: Scikit-learn
Cheat Sheet for Machine Learning in Python: Scikit-learn
Karlijn Willems
 
Regular Expression Examples.pptx
Regular Expression Examples.pptx
GhulamRabani9
 
Tree - Data Structure
Tree - Data Structure
Ashim Lamichhane
 
Java script dialog boxes
Java script dialog boxes
AbhishekMondal42
 
Tuples in Python
Tuples in Python
DPS Ranipur Haridwar UK
 
Oracle SQL Advanced
Oracle SQL Advanced
Dhananjay Goel
 
Literals,variables,datatype in C#
Literals,variables,datatype in C#
Prasanna Kumar SM
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
Hashing in datastructure
Hashing in datastructure
rajshreemuthiah
 
NFA and DFA
NFA and DFA
Rup Chowdhury
 
UNIT-I.pptx awt advance java abstract windowing toolkit and swing
UNIT-I.pptx awt advance java abstract windowing toolkit and swing
utkarshabhope
 
tL19 awt
tL19 awt
teach4uin
 

More Related Content

What's hot (20)

The Switch Statement in java
The Switch Statement in java
Talha Saleem
 
Lecture 7
Lecture 7
shah zeb
 
Regular expressions
Regular expressions
Shiraz316
 
Pumping lemma for regular set h1
Pumping lemma for regular set h1
Rajendran
 
Form Handling using PHP
Form Handling using PHP
Nisa Soomro
 
Aplicaciones con Listas
Aplicaciones con Listas
Fernando Solis
 
Linked list
Linked list
Md. Afif Al Mamun
 
Lecture 8
Lecture 8
shah zeb
 
stacks and queues
stacks and queues
DurgaDeviCbit
 
Hashing
Hashing
VARSHAKUMARI49
 
Cheat Sheet for Machine Learning in Python: Scikit-learn
Cheat Sheet for Machine Learning in Python: Scikit-learn
Karlijn Willems
 
Regular Expression Examples.pptx
Regular Expression Examples.pptx
GhulamRabani9
 
Tree - Data Structure
Tree - Data Structure
Ashim Lamichhane
 
Java script dialog boxes
Java script dialog boxes
AbhishekMondal42
 
Tuples in Python
Tuples in Python
DPS Ranipur Haridwar UK
 
Oracle SQL Advanced
Oracle SQL Advanced
Dhananjay Goel
 
Literals,variables,datatype in C#
Literals,variables,datatype in C#
Prasanna Kumar SM
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
Hashing in datastructure
Hashing in datastructure
rajshreemuthiah
 
NFA and DFA
NFA and DFA
Rup Chowdhury
 

Similar to JAVA Programming: Topic -AWT(Abstract Window Tool ) (20)

UNIT-I.pptx awt advance java abstract windowing toolkit and swing
UNIT-I.pptx awt advance java abstract windowing toolkit and swing
utkarshabhope
 
tL19 awt
tL19 awt
teach4uin
 
events,key,life cycle-abstract window tool kit,abstract class
events,key,life cycle-abstract window tool kit,abstract class
Rohit Kumar
 
AWT.pptx
AWT.pptx
FAHMIDAASEEZ1
 
object oriented programming examples
object oriented programming examples
Abdii Rashid
 
13457272.ppt
13457272.ppt
aptechaligarh
 
17625-1.pptx
17625-1.pptx
BhaskarDharmadhikari
 
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
 
MODULE 5.pptx gui programming and applets
MODULE 5.pptx gui programming and applets
LIKITHLIKITH7
 
The Concept of Abstract Window Took Kit In Java
The Concept of Abstract Window Took Kit In Java
simmis5
 
The Concept of Abstract Window Took Kit In Java
The Concept of Abstract Window Took Kit In Java
simmis5
 
Unit 1- awt(Abstract Window Toolkit) .ppt
Unit 1- awt(Abstract Window Toolkit) .ppt
Deepgaichor1
 
introduction to JAVA awt programmin .ppt
introduction to JAVA awt programmin .ppt
bgvthm
 
Ajp notes-chapter-01
Ajp notes-chapter-01
Ankit Dubey
 
Gui programming
Gui programming
manikanta361
 
fdtrdrtttxxxtrtrctctrttrdredrerrrrrrawt.ppt
fdtrdrtttxxxtrtrctctrttrdredrerrrrrrawt.ppt
havalneha2121
 
awdrdtfffyfyfyfyfyfyfyfyfyfyfyfyyfyt.ppt
awdrdtfffyfyfyfyfyfyfyfyfyfyfyfyyfyt.ppt
SulbhaBhivsane
 
1.Abstract windowing toolkit.ppt of AJP sub
1.Abstract windowing toolkit.ppt of AJP sub
YugandharaNalavade
 
Chapter iii(building a simple user interface)
Chapter iii(building a simple user interface)
Chhom Karath
 
Visual Basic IDE Introduction
Visual Basic IDE Introduction
Ahllen Javier
 
UNIT-I.pptx awt advance java abstract windowing toolkit and swing
UNIT-I.pptx awt advance java abstract windowing toolkit and swing
utkarshabhope
 
events,key,life cycle-abstract window tool kit,abstract class
events,key,life cycle-abstract window tool kit,abstract class
Rohit Kumar
 
object oriented programming examples
object oriented programming examples
Abdii Rashid
 
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
 
MODULE 5.pptx gui programming and applets
MODULE 5.pptx gui programming and applets
LIKITHLIKITH7
 
The Concept of Abstract Window Took Kit In Java
The Concept of Abstract Window Took Kit In Java
simmis5
 
The Concept of Abstract Window Took Kit In Java
The Concept of Abstract Window Took Kit In Java
simmis5
 
Unit 1- awt(Abstract Window Toolkit) .ppt
Unit 1- awt(Abstract Window Toolkit) .ppt
Deepgaichor1
 
introduction to JAVA awt programmin .ppt
introduction to JAVA awt programmin .ppt
bgvthm
 
Ajp notes-chapter-01
Ajp notes-chapter-01
Ankit Dubey
 
fdtrdrtttxxxtrtrctctrttrdredrerrrrrrawt.ppt
fdtrdrtttxxxtrtrctctrttrdredrerrrrrrawt.ppt
havalneha2121
 
awdrdtfffyfyfyfyfyfyfyfyfyfyfyfyyfyt.ppt
awdrdtfffyfyfyfyfyfyfyfyfyfyfyfyyfyt.ppt
SulbhaBhivsane
 
1.Abstract windowing toolkit.ppt of AJP sub
1.Abstract windowing toolkit.ppt of AJP sub
YugandharaNalavade
 
Chapter iii(building a simple user interface)
Chapter iii(building a simple user interface)
Chhom Karath
 
Visual Basic IDE Introduction
Visual Basic IDE Introduction
Ahllen Javier
 
Ad

More from Navya Francis (11)

Data Warehosuing & Data Mining: Apriori Algorithm
Data Warehosuing & Data Mining: Apriori Algorithm
Navya Francis
 
Data Warehosuing & Data Mining: FP Growth
Data Warehosuing & Data Mining: FP Growth
Navya Francis
 
C Programming: Looping Statements in C Pgm
C Programming: Looping Statements in C Pgm
Navya Francis
 
C Programming: Control Statements in C Pgm
C Programming: Control Statements in C Pgm
Navya Francis
 
Data Warehousing & Data Mining: Introduction
Data Warehousing & Data Mining: Introduction
Navya Francis
 
C Programming: Basic Structure of C Program
C Programming: Basic Structure of C Program
Navya Francis
 
Data Structures: Introduction to Data Structures
Data Structures: Introduction to Data Structures
Navya Francis
 
JAVA Programming : Topic JAVA Programming Swing
JAVA Programming : Topic JAVA Programming Swing
Navya Francis
 
Data Structures: Classification of Data Structures
Data Structures: Classification of Data Structures
Navya Francis
 
Software Engineering Topic: Risk Management
Software Engineering Topic: Risk Management
Navya Francis
 
Software Engineering: Topic: Waterfall Model
Software Engineering: Topic: Waterfall Model
Navya Francis
 
Data Warehosuing & Data Mining: Apriori Algorithm
Data Warehosuing & Data Mining: Apriori Algorithm
Navya Francis
 
Data Warehosuing & Data Mining: FP Growth
Data Warehosuing & Data Mining: FP Growth
Navya Francis
 
C Programming: Looping Statements in C Pgm
C Programming: Looping Statements in C Pgm
Navya Francis
 
C Programming: Control Statements in C Pgm
C Programming: Control Statements in C Pgm
Navya Francis
 
Data Warehousing & Data Mining: Introduction
Data Warehousing & Data Mining: Introduction
Navya Francis
 
C Programming: Basic Structure of C Program
C Programming: Basic Structure of C Program
Navya Francis
 
Data Structures: Introduction to Data Structures
Data Structures: Introduction to Data Structures
Navya Francis
 
JAVA Programming : Topic JAVA Programming Swing
JAVA Programming : Topic JAVA Programming Swing
Navya Francis
 
Data Structures: Classification of Data Structures
Data Structures: Classification of Data Structures
Navya Francis
 
Software Engineering Topic: Risk Management
Software Engineering Topic: Risk Management
Navya Francis
 
Software Engineering: Topic: Waterfall Model
Software Engineering: Topic: Waterfall Model
Navya Francis
 
Ad

Recently uploaded (20)

HistoPathology Ppt. Arshita Gupta for Diploma
HistoPathology Ppt. Arshita Gupta for Diploma
arshitagupta674
 
NSUMD_M1 Library Orientation_June 11, 2025.pptx
NSUMD_M1 Library Orientation_June 11, 2025.pptx
Julie Sarpy
 
How to Manage Different Customer Addresses in Odoo 18 Accounting
How to Manage Different Customer Addresses in Odoo 18 Accounting
Celine George
 
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
sumadsadjelly121997
 
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
Kweku Zurek
 
Gladiolous Cultivation practices by AKL.pdf
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
Q1_ENGLISH_PPT_WEEK 1 power point grade 3 Quarter 1 week 1
Q1_ENGLISH_PPT_WEEK 1 power point grade 3 Quarter 1 week 1
jutaydeonne
 
Paper 106 | Ambition and Corruption: A Comparative Analysis of ‘The Great Gat...
Paper 106 | Ambition and Corruption: A Comparative Analysis of ‘The Great Gat...
Rajdeep Bavaliya
 
A Visual Introduction to the Prophet Jeremiah
A Visual Introduction to the Prophet Jeremiah
Steve Thomason
 
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
Ronisha Das
 
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
Ultimatewinner0342
 
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
Mayvel Nadal
 
CRYPTO TRADING COURSE BY FINANCEWORLD.IO
CRYPTO TRADING COURSE BY FINANCEWORLD.IO
AndrewBorisenko3
 
List View Components in Odoo 18 - Odoo Slides
List View Components in Odoo 18 - Odoo Slides
Celine George
 
Vitamin and Nutritional Deficiencies.pptx
Vitamin and Nutritional Deficiencies.pptx
Vishal Chanalia
 
LDMMIA Shop & Student News Summer Solstice 25
LDMMIA Shop & Student News Summer Solstice 25
LDM & Mia eStudios
 
Hurricane Helene Application Documents Checklists
Hurricane Helene Application Documents Checklists
Mebane Rash
 
2025 June Year 9 Presentation: Subject selection.pptx
2025 June Year 9 Presentation: Subject selection.pptx
mansk2
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
June 2025 Progress Update With Board Call_In process.pptx
June 2025 Progress Update With Board Call_In process.pptx
International Society of Service Innovation Professionals
 
HistoPathology Ppt. Arshita Gupta for Diploma
HistoPathology Ppt. Arshita Gupta for Diploma
arshitagupta674
 
NSUMD_M1 Library Orientation_June 11, 2025.pptx
NSUMD_M1 Library Orientation_June 11, 2025.pptx
Julie Sarpy
 
How to Manage Different Customer Addresses in Odoo 18 Accounting
How to Manage Different Customer Addresses in Odoo 18 Accounting
Celine George
 
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
sumadsadjelly121997
 
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
Kweku Zurek
 
Gladiolous Cultivation practices by AKL.pdf
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
Q1_ENGLISH_PPT_WEEK 1 power point grade 3 Quarter 1 week 1
Q1_ENGLISH_PPT_WEEK 1 power point grade 3 Quarter 1 week 1
jutaydeonne
 
Paper 106 | Ambition and Corruption: A Comparative Analysis of ‘The Great Gat...
Paper 106 | Ambition and Corruption: A Comparative Analysis of ‘The Great Gat...
Rajdeep Bavaliya
 
A Visual Introduction to the Prophet Jeremiah
A Visual Introduction to the Prophet Jeremiah
Steve Thomason
 
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
Ronisha Das
 
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
Ultimatewinner0342
 
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
Mayvel Nadal
 
CRYPTO TRADING COURSE BY FINANCEWORLD.IO
CRYPTO TRADING COURSE BY FINANCEWORLD.IO
AndrewBorisenko3
 
List View Components in Odoo 18 - Odoo Slides
List View Components in Odoo 18 - Odoo Slides
Celine George
 
Vitamin and Nutritional Deficiencies.pptx
Vitamin and Nutritional Deficiencies.pptx
Vishal Chanalia
 
LDMMIA Shop & Student News Summer Solstice 25
LDMMIA Shop & Student News Summer Solstice 25
LDM & Mia eStudios
 
Hurricane Helene Application Documents Checklists
Hurricane Helene Application Documents Checklists
Mebane Rash
 
2025 June Year 9 Presentation: Subject selection.pptx
2025 June Year 9 Presentation: Subject selection.pptx
mansk2
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 

JAVA Programming: Topic -AWT(Abstract Window Tool )

  • 1. JAVA PROGRAMMING - AWT Prof. Navya Francis Asst. Professor Kristu Jayanti College
  • 2. ABSTRACT WINDOW TOOL KIT • Java AWT is an API that contains large number of classes and methods to create and manage graphical user interface ( GUI ) applications. • The AWT was designed to provide a common set of tools for GUI design that could work on a variety of platforms. • AWT was Java’s first GUI Framework. • AWT is the foundation upon which Swing is made i.e Swing is a improved GUI API that extends the AWT.
  • 3. AWT • Java AWT components are platform-dependent i.e. components are displayed according to the view of operating system. • AWT is heavy weight i.e. its components are using the resources of underlying operating system (OS) • 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.
  • 5. COMPONENTS • All the elements like the button, text fields, scroll bars, etc. are called components. • In Java AWT, there are classes for each component as shown in above diagram. • In order to place every component in a particular position on a screen, we need to add them to a container.
  • 6. 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. • It is basically a screen where the components are placed at their specific locations. • Thus it contains and controls the layout of components.
  • 7. TYPES OF CONTAINERS: There are four types of containers in Java AWT: • Window • Panel • Frame • Dialog
  • 8. TYPES OF CONTAINERS: • 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. We need to create an instance of Window class to create this container • Panel • The Panel is the container that doesn't contain title bar, border or menu bar. It is generic container for holding the components. It can have other components like button, text field etc. An instance of Panel class creates a container, in which we can add components.
  • 9. TYPES OF CONTAINERS: • Frame • The Frame is the container that contain title bar and border and can have menu bars. • It can have other components like button, text field, scrollbar etc. • Frame is most widely used container while developing an AWT application. • Frame is a subclass of Window and have resizing canvas.
  • 10. TYPES OF CONTAINERS: • The Dialog control • The Dialog control represents a top level window with a border and a title used to take some form of input from the user. • It inherits the Window class. • Unlike Frame, it doesn't have maximize and minimize buttons. • Frame and Dialog both inherits Window class. • Frame has maximize and minimize buttons but Dialog doesn't have.
  • 11. CREATING A FRAME There are two ways to create a Frame. They are, • By Instantiating Frame class • By extending Frame class
  • 12. POINTS TO REMEMBER: • While creating a frame (either by instantiating or extending Frame class), Following two attributes are must for visibility of the frame: • setSize(int width, int height); • setVisible(true); • When you create other components like Buttons, TextFields, etc. Then you need to add it to the frame by using the method - add(Component's Object); • You can add the following method also for resizing the frame - setResizable(true);
  • 16. UNDERSTANDING LAYOUT MANAGERS • The layout manager automatically positions all the components within the container. If we do not use layout manager then also the components are positioned by the default layout manager. • Each Container object has a layout manager associated with it. • A layout manager is an instance of any class that implements the LayoutManagerinterface.
  • 17. UNDERSTANDING LAYOUT MANAGERS • The layout manager is set by the setLayout( ) method. • If no call to setLayout( ) is made,then the default layout manager is used. • Whenever a container is resized (or sized for the first time), the layout manager is used to position each of the components within it. • The setLayout( ) method has the following general form: • void setLayout(LayoutManager layoutObj)
  • 18. FLOWLAYOUT • It is the default layout manager. • FlowLayout implements a simple layout style, which is similar to how words flow in a text editor. • FlowLayout.LEFT • FlowLayout.CENTER • FlowLayout.RIGHT • FlowLayout.LEADING • FlowLayout.TRAILING • These values specify left, center, right, leading edge, and trailing edge alignment, respectively
  • 19. BORDERLAYOUT • The BorderLayout class implements a common layout style for top-level windows. • It has four narrow, fixed-width components at the edges and one large area in the center. • The four sides are referred to as north, south, east, and west. The middle area is called the center. BorderLayout defines the following constants that specify the regions: • BorderLayout.CENTER • BorderLayout.SOUTH • BorderLayout.EAST • BorderLayout.WEST • BorderLayout.NORTH
  • 20. AWT CONTROL FUNDAMENTALS • The AWT supports the following types of controls: • These controls are subclasses of Component. • Labels • Buttons • Check boxes • Check box groups • Choice control • Lists • Scroll bar • Text field • Text area
  • 21. ADDING AND REMOVING CONTROLS • In order to include a control in a window, we must add it to the window. • So, we must first create an instance of the desired control and then add it to a window by calling add( ), which is defined by Container. • Component add(Component compObj)
  • 22. ADDING AND REMOVING CONTROLS • Once a control has been added, it will automatically be visible whenever its parent window is displayed. • Sometimes we will want to remove a control from a window when the control is no longer needed. • For doing this, call remove( ). • This method is also defined by Container. • It has this general form: void remove(Component obj) Here, obj is a reference to the control that we want to remove. • We can remove all controls by calling removeAll( )
  • 23. LABEL • A label is a user for placing text inside the container. • A label is used only for inputting text. • The label does not imply that the text can be altered or it can be used as a button which can be further worked upon. Label n=new Label("Name:",Label.CENTER);
  • 24. LABEL
  • 25. BUTTON • This command generates a button in the User Interface. • Clicking on the button would move the command to another page or another web server which is used to show several other outputs in the user interface page. a1=new Button("submit"); a2=new Button("cancel");
  • 27. CHECK BOXES • A check box is a control that is used to turn an option on or off. It consists of a small box that can either contain a check mark or not. • There is a label associated with each check box that describes what option the box represents. • We change the state of a check box by clicking on it. Check boxes can be used individually or as part of a group. • Check boxes are objects of the Checkbox class • Checkbox checkbox1 = new Checkbox("Hello World");
  • 29. CHECKBOX GROUP • 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 are often called radio buttons. • For creating a set of mutually exclusive check boxes, we must first define the group to which they will belong and then specify that group when we construct the check boxes. • Check box groups are objects of type CheckBoxGroup. CheckboxGroup cb = new CheckboxGroup(); Checkbox checkBox1 = new Checkbox("Hello", cb, true); checkBox1.setBounds (100,100, 50,50);
  • 31. MANAGING SCROLL BARS • Scroll bars are used to select continuous values between a specified minimum and maximum. Scroll bars may be oriented horizontally or vertically. • Each end has an arrow that you can click to move the current value of the scroll bar one unit in the direction of the arrow. Scrollbar s=new Scrollbar(); s.setBounds(100,100, 50,100);
  • 33. TEXTFIELD • The TextField class implements a single-line text-entry area, usually called an edit control. • Text fields allow the user to enter strings and to edit the text using the arrow keys, cut and paste keys, and mouse selections. na=new TextField(“my name”);
  • 35. TEXTAREA • 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 TextArea. TextArea area=new TextArea("Welcome to the universe"); area.setBounds(10,30, 300,300);
  • 37. CHOICE CONTROLS • 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. • When inactive, a Choice component takes up only enough space to show the currently selected item. When the user clicks on it, the whole list of choices pops up, and a new selection can be made. Choice c=new Choice(); c.setBounds(100,100, 75,75); c.add("Subject 1"); c.add("Subject 2"); c.add("Subject 3");
  • 39. LISTS • The List class provides a compact, multiple-choice, scrolling selection list. • Unlike the Choice object, which shows only the single selected item in the menu, a List object can be constructed to show any number of choices in the visible Window. • It can also be created to allow multiple selections.
  • 40. LISTS
  • 41. MENU BARS AND MENUS • A top-level window can have a menu bar associated with it. • A menu bar displays a list of top-level menu choices. • Each choice is associated with a drop-down menu. • This concept is implemented in the AWT by the following classes: MenuBar, Menu,and MenuItem.
  • 42. MENU BARS AND MENUS • In general, a menu bar contains one or more Menu objects. Each Menu object contains a list of MenuItem objects. • Each MenuItem object represents something that can be selected by the user. • Since Menu is a subclass of MenuItem, a hierarchy of nested submenus can be created. • It is also possible to include checkable menu items. • These are menu options of type CheckboxMenuItem and will have a check mark next to them when they are selected.
  • 43. MENU BARS AND MENUS
  • 44. MENU BARS AND MENUS
  • 45. • Creating Menubar MenuBar mb=new MenuBar(); • Menu a creation Menu mnu1=new Menu("BCA"); Menu mnu2=new Menu("BBA");
  • 46. • sm1 and sm2 will be treated as submenus Menu sm1=new Menu("Semester"); Menu sm2=new Menu("Year"); • adding items and submenus to menu mnu1.add(sm1); mnu1.add(sm2);
  • 47. • //adding items to submenu sm1.add(i1); sm1.add(i2); sm2.add(i3); • //adding menu to menubar mb.add(mnu1); mb.add(mnu2);
  • 48. • Creating menu items MenuItem i1,i2,i3; i1=new MenuItem("I"); i2=new MenuItem("II"); i3=new MenuItem("2023");
  • 49. DIALOG BOXES • Dialog boxes are primarily used to obtain user input and are often child windows of a top-level window. • Dialog boxes don’t have menu bars, but in other respects, they function like frame windows. (You can add controls to them, for example, in the same way that you add controls to a frame window.) • When a modal dialog box is active, all input is directed to it until it is closed.
  • 50. DIALOG BOXES • This means that you cannot access other parts of your program until you have closed the dialog box. • When a modeless dialog box is active, input focus can be directed to another window in your program. • Thus, other parts of your program remain active and accessible. In the AWT, dialog boxes are of type Dialog
  • 52. FILEDIALOG • Java provides a built-in dialog box that lets the user specify a file. • To create a file dialog box, instantiate an object of type FileDialog. This causes a file dialog box to be displayed. • Usually, this is the standard file dialog box provided by the operating system.
  • 54. HANDLING EVENTS BY EXTENDING AWT COMPONENTS • Handling events by extending AWT components. • The delegation event model was introduced in Event handling, and all of the programs in this book so far have used that design. But Java also allows you to handle events by subclassing AWT components. • Doing so allows you to handle events in much the same way as they were handled under the original 1.0 version of Java. Of course, this technique is discouraged, because it has the same disadvantages of the Java 1.0 event model, the main one being inefficiency.
  • 55. • To extend an AWT component, you must call the enableEvents( ) method of Component. Its general form is shown here: