SlideShare a Scribd company logo
JAVA
AWT
Prepared by
Miss. Arati A. Gadgil
•Java AWT (Abstract Windowing Toolkit) is an API to develop
GUI or window-based application in java.
•Java AWT components are platform-dependent i.e. components
are displayed according to the view of operating system. AWT is
heavyweight i.e. its components uses the resources of system.
•The java.awt package provides classes for AWT api such as
TextField, Label, TextArea, RadioButton, CheckBox, Choice,
List etc.
AWT
2
Java AWT
Hierarchy
3
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.
4
5
Useful Methods of Component class
public void add(Component c)
inserts a component on this component
public void setSize(int width,int height)
sets the size (width and height) of the component.
public void setLayout(LayoutManager m)
defines the layout manager for the component.
public void setVisible(boolean status)
changes the visibility of the component, by default false.
import java.awt.*;
class frm1 extends Frame
{
frm1(String s)
{
super(s);
setSize(400,400);
setVisible(true);
}
public static void main(String []ar)
{
frm1 a=new frm1("first
window");
}
}
First frame
Output
6
import java.awt.*;
class First extends Frame
{
First()
{
Button b=new Button("click me");
b.setBounds(30,100,80,30) ;// setting button position
add(b);//adding button into frame
setSize(300,300);//frame size 300 width and 300 height
setLayout(null);//no layout manager
setVisible(true);//now frame will be visible, by default not
visible
}
public static void main(String args[])
{
First f=new First();
}
} 7
Output
The setBounds(int xaxis, int yaxis, int width,
int height)
Method is used in the above example that sets
the position of the awt button.
b.setBounds(30,100,80,30)
8
Changing the state of an object is known as an
event. For example, click on button, dragging
mouse etc. The java.awt.event package provides
many event classes and Listener interfaces for
event handling.
Event Classes Listener Interfaces
ActionEvent ActionListener
MouseEvent MouseListener and
MouseMotionListener
MouseWheelEvent MouseWheelListener
KeyEvent KeyListener
ItemEvent ItemListener
TextEvent TextListener
AdjustmentEvent AdjustmentListener
WindowEvent WindowListener
ComponentEvent ComponentListener
ContainerEvent ContainerListener
FocusEvent FocusListener
Event and Listener (Java Event Handling)
9
import java.awt.*; import java.awt.event.*;
class eventi extends Frame implements
ActionListener
{ TextField tf;
eventi()
{
tf=new TextField();
tf.setBounds(60,50,170,20);
Button b=new Button("click me");
b.setBounds(100,120,80,30);
b.addActionListener(this);
add(b);add(tf);
setSize(300,300);
setLayout(null);
setVisible(true);
}
public void actionPerformed(ActionEvent
e)
{ tf.setText("Welcome");
}
public static void main(String args[])
{ new eventi();
}
10
AWT UI Elements
Label
constructors
Label() Constructs an empty label.
Label(String text) Constructs a new label with the specified
string of text, left justified.
Label(String text, int alignment)
Constructs a new label that presents the specified string of
text with the specified alignment.
static int CENTER -- Indicates that the label should be centered.
static int LEFT -- Indicates that the label should be left justified.
static int RIGHT -- Indicates that the label should be right justified
11
Methods
int getAlignment()
Gets the current alignment of this label.
String getText()
Gets the text of this label.
void setAlignment(int alignment)
Sets the alignment for this label to the specified alignment.
void setText(String text)
Sets the text for this label to the specified text
12
Button
Constructors
Button()
Constructs a button with an empty string for its
label.
Button(String text)
Constructs a new button with specified label.
13
Methods
void addActionListener(ActionListener l) Adds the specified action
listener to receive action events from this button.
String getActionCommand()
Returns the command name of the action event fired by this button.
String getLabel()
Gets the label of this button
void removeActionListener(ActionListener l)Removes the specified
action listener so that it no longer receives action events from this button
void setActionCommand(String command)
Sets the command name for the action event fired by this button.
void setLabel(String label)
Sets the button's label to be the specified string 14
CheckBox
Constructors
Checkbox()
Creates a check box with an empty string for its label.
Checkbox(String label, boolean state) Creates a check box with
the specified label and sets the specified state.
Checkbox(String label, boolean state, CheckboxGroup group)
Constructs a Checkbox with the specified label, set to the specified
state, and in the specified check box group.
Checkbox(String label, CheckboxGroup group, boolean state)
Creates a check box with the specified label, in the specified check
box group, and set to the specified state.
15
void addItemListener(ItemListener l)
Adds the specified item listener to receive item events from this
check box.
CheckboxGroup getCheckboxGroup()
Determines this check box's group.
String getLabel()
Gets the label of this check box
boolean getState()
Determines whether this check box is in the on or off state.
void setCheckboxGroup(CheckboxGroup g)
Sets this check box's group to the specified check box group.
void setState(boolean state)
Sets the state of this check box to the specified state. 16
List
The List represents a list of text items. The list can be configured to that
user can choose either one item or multiple items.
Constructors
List()
Creates a new scrolling list.
List(int rows) Creates a new scrolling list initialized with the specified
number of visible lines
List(int rows, boolean multipleMode)
Creates a new scrolling list initialized to display the specified
number of rows.
17
void add(String item)
Adds the specified item to the end of scrolling list.
void add(String item, int index) Adds the specified item to the the
scrolling list at the position indicated by the index.
void addActionListener(ActionListener l) Adds the specified
action listener to receive action events from this list
void clear()
Deprecated. As of JDK version 1.1, replaced by removeAll().
void delItem(int position)
Deprecated. replaced by remove(String) and remove(int).
void deselect(int index)
Deselects the item at the specified index.
18
String getItem(int index)
Gets the item associated with the specified index.
int getItemCount()
Gets the number of items in the list
String[] getItems()
Gets the items in the list.
int getRows()
Gets the number of visible lines in this list
int getSelectedIndex()
Gets the index of the selected item on the list
19
boolean isMultipleMode()
Determines whether this list allows multiple selections.
void remove(int position)
Removes the item at the specified position from this scrolling
list.
void remove(String item)
Removes the first occurrence of an item from the list
20
TextField
Constructor
TextField()
Constructs a new text field.
TextField(int columns)
Constructs a new empty text field with the specified number of
columns.
TextField(String text)
Constructs a new text field initialized with the specified text.
TextField(String text, int columns)
Constructs a new text field initialized with the specified text to be
displayed, and wide enough to hold the specified number of
columns. 21
void addActionListener(ActionListener l)
Adds the specified action listener to receive action
events from this text field.
int getColumns()
Gets the number of columns in this text field
void setColumns(int columns)
Sets the number of columns in this text field
void setText(String t)
Sets the text that is presented by this text component
to be the specified text.
22
Thank You
23

More Related Content

What's hot (20)

Java swing
Java swingJava swing
Java swing
Apurbo Datta
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
Elizabeth alexander
 
Awt controls ppt
Awt controls pptAwt controls ppt
Awt controls ppt
soumyaharitha
 
Java package
Java packageJava package
Java package
CS_GDRCST
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
CPD INDIA
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
Farooq Baloch
 
Java Streams
Java StreamsJava Streams
Java Streams
M Vishnuvardhan Reddy
 
History Of JAVA
History Of JAVAHistory Of JAVA
History Of JAVA
ARSLANAHMED107
 
Java Method, Static Block
Java Method, Static BlockJava Method, Static Block
Java Method, Static Block
Infoviaan Technologies
 
Synchronization.37
Synchronization.37Synchronization.37
Synchronization.37
myrajendra
 
Constants, Variables and Data Types in Java
Constants, Variables and Data Types in JavaConstants, Variables and Data Types in Java
Constants, Variables and Data Types in Java
Abhilash Nair
 
Wrapper class
Wrapper classWrapper class
Wrapper class
kamal kotecha
 
Unit-3 event handling
Unit-3 event handlingUnit-3 event handling
Unit-3 event handling
Amol Gaikwad
 
Java threads
Java threadsJava threads
Java threads
Prabhakaran V M
 
Packages in java
Packages in javaPackages in java
Packages in java
Elizabeth alexander
 
Thread model in java
Thread model in javaThread model in java
Thread model in java
AmbigaMurugesan
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
Abhilash Nair
 
Java multi threading
Java multi threadingJava multi threading
Java multi threading
Raja Sekhar
 
Inter thread communication
Inter thread communicationInter thread communication
Inter thread communication
subash andey
 

Similar to Java awt (20)

AWT New-3.pptx
AWT New-3.pptxAWT New-3.pptx
AWT New-3.pptx
SarthakSrivastava70
 
CORE JAVA-2
CORE JAVA-2CORE JAVA-2
CORE JAVA-2
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Unit-1 awt advanced java programming
Unit-1 awt advanced java programmingUnit-1 awt advanced java programming
Unit-1 awt advanced java programming
Amol Gaikwad
 
engineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptengineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.ppt
sharanyak0721
 
javaprogramming framework-ppt frame.pptx
javaprogramming framework-ppt frame.pptxjavaprogramming framework-ppt frame.pptx
javaprogramming framework-ppt frame.pptx
DrDGayathriDevi
 
Unit 4_1.pptx JDBC AND GUI FOR CLIENT SERVER
Unit 4_1.pptx JDBC AND GUI FOR CLIENT SERVERUnit 4_1.pptx JDBC AND GUI FOR CLIENT SERVER
Unit 4_1.pptx JDBC AND GUI FOR CLIENT SERVER
Salini P
 
java-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of appletjava-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of applet
raksharao
 
java- Abstract Window toolkit
java- Abstract Window toolkitjava- Abstract Window toolkit
java- Abstract Window toolkit
Jayant Dalvi
 
object oriented programming examples
object oriented programming examplesobject oriented programming examples
object oriented programming examples
Abdii Rashid
 
Swing
SwingSwing
Swing
Bharat17485
 
DSJ_Unit III.pdf
DSJ_Unit III.pdfDSJ_Unit III.pdf
DSJ_Unit III.pdf
Arumugam90
 
Advanced java programming
Advanced java programmingAdvanced java programming
Advanced java programming
Kaviya452563
 
Basic of Abstract Window Toolkit(AWT) in Java
Basic of Abstract Window Toolkit(AWT) in JavaBasic of Abstract Window Toolkit(AWT) in Java
Basic of Abstract Window Toolkit(AWT) in Java
suraj pandey
 
Jp notes
Jp notesJp notes
Jp notes
Sreedhar Chowdam
 
Java swing
Java swingJava swing
Java swing
ssuser3a47cb
 
Awt, Swing, Layout managers
Awt, Swing, Layout managersAwt, Swing, Layout managers
Awt, Swing, Layout managers
swapnac12
 
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKDPPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
chessvashisth
 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
nehakumari0xf
 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
kashyapneha2809
 
Lecture8 oopj
Lecture8 oopjLecture8 oopj
Lecture8 oopj
Dhairya Joshi
 
Unit-1 awt advanced java programming
Unit-1 awt advanced java programmingUnit-1 awt advanced java programming
Unit-1 awt advanced java programming
Amol Gaikwad
 
engineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptengineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.ppt
sharanyak0721
 
javaprogramming framework-ppt frame.pptx
javaprogramming framework-ppt frame.pptxjavaprogramming framework-ppt frame.pptx
javaprogramming framework-ppt frame.pptx
DrDGayathriDevi
 
Unit 4_1.pptx JDBC AND GUI FOR CLIENT SERVER
Unit 4_1.pptx JDBC AND GUI FOR CLIENT SERVERUnit 4_1.pptx JDBC AND GUI FOR CLIENT SERVER
Unit 4_1.pptx JDBC AND GUI FOR CLIENT SERVER
Salini P
 
java-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of appletjava-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of applet
raksharao
 
java- Abstract Window toolkit
java- Abstract Window toolkitjava- Abstract Window toolkit
java- Abstract Window toolkit
Jayant Dalvi
 
object oriented programming examples
object oriented programming examplesobject oriented programming examples
object oriented programming examples
Abdii Rashid
 
DSJ_Unit III.pdf
DSJ_Unit III.pdfDSJ_Unit III.pdf
DSJ_Unit III.pdf
Arumugam90
 
Advanced java programming
Advanced java programmingAdvanced java programming
Advanced java programming
Kaviya452563
 
Basic of Abstract Window Toolkit(AWT) in Java
Basic of Abstract Window Toolkit(AWT) in JavaBasic of Abstract Window Toolkit(AWT) in Java
Basic of Abstract Window Toolkit(AWT) in Java
suraj pandey
 
Awt, Swing, Layout managers
Awt, Swing, Layout managersAwt, Swing, Layout managers
Awt, Swing, Layout managers
swapnac12
 
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKDPPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
chessvashisth
 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
nehakumari0xf
 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
kashyapneha2809
 

More from Arati Gadgil (16)

Java adapter
Java adapterJava adapter
Java adapter
Arati Gadgil
 
Java swing
Java swingJava swing
Java swing
Arati Gadgil
 
Java applet
Java appletJava applet
Java applet
Arati Gadgil
 
Java layoutmanager
Java layoutmanagerJava layoutmanager
Java layoutmanager
Arati Gadgil
 
Java stream
Java streamJava stream
Java stream
Arati Gadgil
 
Java thread
Java threadJava thread
Java thread
Arati Gadgil
 
Java networking
Java networkingJava networking
Java networking
Arati Gadgil
 
Java jdbc
Java jdbcJava jdbc
Java jdbc
Arati Gadgil
 
Java package
Java packageJava package
Java package
Arati Gadgil
 
Java interface
Java interfaceJava interface
Java interface
Arati Gadgil
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
Arati Gadgil
 
Java eventhandling
Java eventhandlingJava eventhandling
Java eventhandling
Arati Gadgil
 
Java exception
Java exception Java exception
Java exception
Arati Gadgil
 
Java collection
Java collectionJava collection
Java collection
Arati Gadgil
 
Java class
Java classJava class
Java class
Arati Gadgil
 
Java basic
Java basicJava basic
Java basic
Arati Gadgil
 

Recently uploaded (20)

UNIT-2 606 - B : CROSS CULTURAL RELATIONSHIP - II.pptx
UNIT-2 606 - B : CROSS CULTURAL RELATIONSHIP - II.pptxUNIT-2 606 - B : CROSS CULTURAL RELATIONSHIP - II.pptx
UNIT-2 606 - B : CROSS CULTURAL RELATIONSHIP - II.pptx
MAYURI LONDHE
 
SPORTS QUIZ HQC'25 MANTHAN HINDU COLLEGE .pdf
SPORTS QUIZ HQC'25 MANTHAN HINDU COLLEGE .pdfSPORTS QUIZ HQC'25 MANTHAN HINDU COLLEGE .pdf
SPORTS QUIZ HQC'25 MANTHAN HINDU COLLEGE .pdf
MANTHAN THE QUIZZING SOCIETY OF HINDU COLLEGE
 
HIV: Acquired immunodeficiency syndrome (AIDS), is an ongoing, also called ch...
HIV: Acquired immunodeficiency syndrome (AIDS), is an ongoing, also called ch...HIV: Acquired immunodeficiency syndrome (AIDS), is an ongoing, also called ch...
HIV: Acquired immunodeficiency syndrome (AIDS), is an ongoing, also called ch...
DR .PALLAVI PATHANIA
 
History of Pala Dynasty, Rise of Pal NEP.pptx
History of Pala Dynasty, Rise of Pal NEP.pptxHistory of Pala Dynasty, Rise of Pal NEP.pptx
History of Pala Dynasty, Rise of Pal NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
401 ENTREPRENEURSHIP & SMALL BUSINESS MANAGEMENT QUESTION BANK.docx
401 ENTREPRENEURSHIP & SMALL BUSINESSMANAGEMENT QUESTION BANK.docx401 ENTREPRENEURSHIP & SMALL BUSINESSMANAGEMENT QUESTION BANK.docx
401 ENTREPRENEURSHIP & SMALL BUSINESS MANAGEMENT QUESTION BANK.docx
MAYURI LONDHE
 
ĐỀ CƯƠNG HK2 LỚP 7. cuoi ky 2 thcs hoa phu
ĐỀ CƯƠNG HK2 LỚP 7. cuoi ky 2 thcs hoa phuĐỀ CƯƠNG HK2 LỚP 7. cuoi ky 2 thcs hoa phu
ĐỀ CƯƠNG HK2 LỚP 7. cuoi ky 2 thcs hoa phu
NhiLinh58
 
Simple past tense quiz. Students reinforce this grammar topic
Simple past tense quiz. Students reinforce this grammar topicSimple past tense quiz. Students reinforce this grammar topic
Simple past tense quiz. Students reinforce this grammar topic
OlgaLeonorTorresSnch
 
Diode Demystified: From Ideal Assumptions to Specialty Applications
Diode Demystified: From Ideal Assumptions to Specialty ApplicationsDiode Demystified: From Ideal Assumptions to Specialty Applications
Diode Demystified: From Ideal Assumptions to Specialty Applications
GS Virdi
 
MYTHOLOGY, ETHYMOLOGY, CULTURE, CUISINE, ARCHITECTURE (MECCA) FILLER QUIZ.pdf
MYTHOLOGY, ETHYMOLOGY, CULTURE, CUISINE, ARCHITECTURE (MECCA) FILLER QUIZ.pdfMYTHOLOGY, ETHYMOLOGY, CULTURE, CUISINE, ARCHITECTURE (MECCA) FILLER QUIZ.pdf
MYTHOLOGY, ETHYMOLOGY, CULTURE, CUISINE, ARCHITECTURE (MECCA) FILLER QUIZ.pdf
MANTHAN THE QUIZZING SOCIETY OF HINDU COLLEGE
 
Crude Drugs in D. Pharm Syllabus: A Comprehensive Chart in Pharmacognosy
Crude Drugs in D. Pharm Syllabus: A Comprehensive Chart in PharmacognosyCrude Drugs in D. Pharm Syllabus: A Comprehensive Chart in Pharmacognosy
Crude Drugs in D. Pharm Syllabus: A Comprehensive Chart in Pharmacognosy
PAWAN KUMAR SAHU
 
Mehran University Newsletter Vol-XI, Issue-I, 2025
Mehran University Newsletter Vol-XI, Issue-I, 2025Mehran University Newsletter Vol-XI, Issue-I, 2025
Mehran University Newsletter Vol-XI, Issue-I, 2025
Mehran University of Engineering & Technology, Jamshoro
 
Some Common Errors that Generative AI Produces
Some Common Errors that Generative AI ProducesSome Common Errors that Generative AI Produces
Some Common Errors that Generative AI Produces
Damian T. Gordon
 
How to Add Customer Rating Mixin in the Odoo 18
How to Add Customer Rating Mixin in the Odoo 18How to Add Customer Rating Mixin in the Odoo 18
How to Add Customer Rating Mixin in the Odoo 18
Celine George
 
FINALS INDIA QUIZ MANTHAN HQC 2025 .pdf
FINALS INDIA QUIZ MANTHAN HQC 2025  .pdfFINALS INDIA QUIZ MANTHAN HQC 2025  .pdf
FINALS INDIA QUIZ MANTHAN HQC 2025 .pdf
MANTHAN THE QUIZZING SOCIETY OF HINDU COLLEGE
 
UNIT-3 606 - B : CROSS CULTURAL RELATIONSHIP - II.pptx
UNIT-3 606 - B : CROSS CULTURAL RELATIONSHIP - II.pptxUNIT-3 606 - B : CROSS CULTURAL RELATIONSHIP - II.pptx
UNIT-3 606 - B : CROSS CULTURAL RELATIONSHIP - II.pptx
MAYURI LONDHE
 
Using Deep Learning (DL) Approach in Teaching English Subject
Using Deep Learning (DL) Approach in Teaching English Subject Using Deep Learning (DL) Approach in Teaching English Subject
Using Deep Learning (DL) Approach in Teaching English Subject
Neny Isharyanti
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-23-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-23-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-23-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-23-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
How To Open The Form View Of Many2many Clicking Tag In Odoo 18
How To Open The Form View Of Many2many Clicking Tag In Odoo 18How To Open The Form View Of Many2many Clicking Tag In Odoo 18
How To Open The Form View Of Many2many Clicking Tag In Odoo 18
Celine George
 
p4.pdf فن خدمة الاغذية والمشروبات الجزء الرابع
p4.pdf فن خدمة الاغذية والمشروبات الجزء الرابعp4.pdf فن خدمة الاغذية والمشروبات الجزء الرابع
p4.pdf فن خدمة الاغذية والمشروبات الجزء الرابع
HanyAtef10
 
INDIA QUIZ PRELIMS MANTHAN HQC 2025.pdf
INDIA QUIZ PRELIMS MANTHAN HQC  2025.pdfINDIA QUIZ PRELIMS MANTHAN HQC  2025.pdf
INDIA QUIZ PRELIMS MANTHAN HQC 2025.pdf
MANTHAN THE QUIZZING SOCIETY OF HINDU COLLEGE
 
UNIT-2 606 - B : CROSS CULTURAL RELATIONSHIP - II.pptx
UNIT-2 606 - B : CROSS CULTURAL RELATIONSHIP - II.pptxUNIT-2 606 - B : CROSS CULTURAL RELATIONSHIP - II.pptx
UNIT-2 606 - B : CROSS CULTURAL RELATIONSHIP - II.pptx
MAYURI LONDHE
 
HIV: Acquired immunodeficiency syndrome (AIDS), is an ongoing, also called ch...
HIV: Acquired immunodeficiency syndrome (AIDS), is an ongoing, also called ch...HIV: Acquired immunodeficiency syndrome (AIDS), is an ongoing, also called ch...
HIV: Acquired immunodeficiency syndrome (AIDS), is an ongoing, also called ch...
DR .PALLAVI PATHANIA
 
401 ENTREPRENEURSHIP & SMALL BUSINESS MANAGEMENT QUESTION BANK.docx
401 ENTREPRENEURSHIP & SMALL BUSINESSMANAGEMENT QUESTION BANK.docx401 ENTREPRENEURSHIP & SMALL BUSINESSMANAGEMENT QUESTION BANK.docx
401 ENTREPRENEURSHIP & SMALL BUSINESS MANAGEMENT QUESTION BANK.docx
MAYURI LONDHE
 
ĐỀ CƯƠNG HK2 LỚP 7. cuoi ky 2 thcs hoa phu
ĐỀ CƯƠNG HK2 LỚP 7. cuoi ky 2 thcs hoa phuĐỀ CƯƠNG HK2 LỚP 7. cuoi ky 2 thcs hoa phu
ĐỀ CƯƠNG HK2 LỚP 7. cuoi ky 2 thcs hoa phu
NhiLinh58
 
Simple past tense quiz. Students reinforce this grammar topic
Simple past tense quiz. Students reinforce this grammar topicSimple past tense quiz. Students reinforce this grammar topic
Simple past tense quiz. Students reinforce this grammar topic
OlgaLeonorTorresSnch
 
Diode Demystified: From Ideal Assumptions to Specialty Applications
Diode Demystified: From Ideal Assumptions to Specialty ApplicationsDiode Demystified: From Ideal Assumptions to Specialty Applications
Diode Demystified: From Ideal Assumptions to Specialty Applications
GS Virdi
 
Crude Drugs in D. Pharm Syllabus: A Comprehensive Chart in Pharmacognosy
Crude Drugs in D. Pharm Syllabus: A Comprehensive Chart in PharmacognosyCrude Drugs in D. Pharm Syllabus: A Comprehensive Chart in Pharmacognosy
Crude Drugs in D. Pharm Syllabus: A Comprehensive Chart in Pharmacognosy
PAWAN KUMAR SAHU
 
Some Common Errors that Generative AI Produces
Some Common Errors that Generative AI ProducesSome Common Errors that Generative AI Produces
Some Common Errors that Generative AI Produces
Damian T. Gordon
 
How to Add Customer Rating Mixin in the Odoo 18
How to Add Customer Rating Mixin in the Odoo 18How to Add Customer Rating Mixin in the Odoo 18
How to Add Customer Rating Mixin in the Odoo 18
Celine George
 
UNIT-3 606 - B : CROSS CULTURAL RELATIONSHIP - II.pptx
UNIT-3 606 - B : CROSS CULTURAL RELATIONSHIP - II.pptxUNIT-3 606 - B : CROSS CULTURAL RELATIONSHIP - II.pptx
UNIT-3 606 - B : CROSS CULTURAL RELATIONSHIP - II.pptx
MAYURI LONDHE
 
Using Deep Learning (DL) Approach in Teaching English Subject
Using Deep Learning (DL) Approach in Teaching English Subject Using Deep Learning (DL) Approach in Teaching English Subject
Using Deep Learning (DL) Approach in Teaching English Subject
Neny Isharyanti
 
How To Open The Form View Of Many2many Clicking Tag In Odoo 18
How To Open The Form View Of Many2many Clicking Tag In Odoo 18How To Open The Form View Of Many2many Clicking Tag In Odoo 18
How To Open The Form View Of Many2many Clicking Tag In Odoo 18
Celine George
 
p4.pdf فن خدمة الاغذية والمشروبات الجزء الرابع
p4.pdf فن خدمة الاغذية والمشروبات الجزء الرابعp4.pdf فن خدمة الاغذية والمشروبات الجزء الرابع
p4.pdf فن خدمة الاغذية والمشروبات الجزء الرابع
HanyAtef10
 

Java awt

  • 2. •Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based application in java. •Java AWT components are platform-dependent i.e. components are displayed according to the view of operating system. AWT is heavyweight i.e. its components uses the resources of system. •The java.awt package provides classes for AWT api such as TextField, Label, TextArea, RadioButton, CheckBox, Choice, List etc. AWT 2
  • 4. 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. 4
  • 5. 5 Useful Methods of Component class public void add(Component c) inserts a component on this component public void setSize(int width,int height) sets the size (width and height) of the component. public void setLayout(LayoutManager m) defines the layout manager for the component. public void setVisible(boolean status) changes the visibility of the component, by default false.
  • 6. import java.awt.*; class frm1 extends Frame { frm1(String s) { super(s); setSize(400,400); setVisible(true); } public static void main(String []ar) { frm1 a=new frm1("first window"); } } First frame Output 6
  • 7. import java.awt.*; class First extends Frame { First() { Button b=new Button("click me"); b.setBounds(30,100,80,30) ;// setting button position add(b);//adding button into frame setSize(300,300);//frame size 300 width and 300 height setLayout(null);//no layout manager setVisible(true);//now frame will be visible, by default not visible } public static void main(String args[]) { First f=new First(); } } 7
  • 8. Output The setBounds(int xaxis, int yaxis, int width, int height) Method is used in the above example that sets the position of the awt button. b.setBounds(30,100,80,30) 8
  • 9. Changing the state of an object is known as an event. For example, click on button, dragging mouse etc. The java.awt.event package provides many event classes and Listener interfaces for event handling. Event Classes Listener Interfaces ActionEvent ActionListener MouseEvent MouseListener and MouseMotionListener MouseWheelEvent MouseWheelListener KeyEvent KeyListener ItemEvent ItemListener TextEvent TextListener AdjustmentEvent AdjustmentListener WindowEvent WindowListener ComponentEvent ComponentListener ContainerEvent ContainerListener FocusEvent FocusListener Event and Listener (Java Event Handling) 9
  • 10. import java.awt.*; import java.awt.event.*; class eventi extends Frame implements ActionListener { TextField tf; eventi() { tf=new TextField(); tf.setBounds(60,50,170,20); Button b=new Button("click me"); b.setBounds(100,120,80,30); b.addActionListener(this); add(b);add(tf); setSize(300,300); setLayout(null); setVisible(true); } public void actionPerformed(ActionEvent e) { tf.setText("Welcome"); } public static void main(String args[]) { new eventi(); } 10
  • 11. AWT UI Elements Label constructors Label() Constructs an empty label. Label(String text) Constructs a new label with the specified string of text, left justified. Label(String text, int alignment) Constructs a new label that presents the specified string of text with the specified alignment. static int CENTER -- Indicates that the label should be centered. static int LEFT -- Indicates that the label should be left justified. static int RIGHT -- Indicates that the label should be right justified 11
  • 12. Methods int getAlignment() Gets the current alignment of this label. String getText() Gets the text of this label. void setAlignment(int alignment) Sets the alignment for this label to the specified alignment. void setText(String text) Sets the text for this label to the specified text 12
  • 13. Button Constructors Button() Constructs a button with an empty string for its label. Button(String text) Constructs a new button with specified label. 13
  • 14. Methods void addActionListener(ActionListener l) Adds the specified action listener to receive action events from this button. String getActionCommand() Returns the command name of the action event fired by this button. String getLabel() Gets the label of this button void removeActionListener(ActionListener l)Removes the specified action listener so that it no longer receives action events from this button void setActionCommand(String command) Sets the command name for the action event fired by this button. void setLabel(String label) Sets the button's label to be the specified string 14
  • 15. CheckBox Constructors Checkbox() Creates a check box with an empty string for its label. Checkbox(String label, boolean state) Creates a check box with the specified label and sets the specified state. Checkbox(String label, boolean state, CheckboxGroup group) Constructs a Checkbox with the specified label, set to the specified state, and in the specified check box group. Checkbox(String label, CheckboxGroup group, boolean state) Creates a check box with the specified label, in the specified check box group, and set to the specified state. 15
  • 16. void addItemListener(ItemListener l) Adds the specified item listener to receive item events from this check box. CheckboxGroup getCheckboxGroup() Determines this check box's group. String getLabel() Gets the label of this check box boolean getState() Determines whether this check box is in the on or off state. void setCheckboxGroup(CheckboxGroup g) Sets this check box's group to the specified check box group. void setState(boolean state) Sets the state of this check box to the specified state. 16
  • 17. List The List represents a list of text items. The list can be configured to that user can choose either one item or multiple items. Constructors List() Creates a new scrolling list. List(int rows) Creates a new scrolling list initialized with the specified number of visible lines List(int rows, boolean multipleMode) Creates a new scrolling list initialized to display the specified number of rows. 17
  • 18. void add(String item) Adds the specified item to the end of scrolling list. void add(String item, int index) Adds the specified item to the the scrolling list at the position indicated by the index. void addActionListener(ActionListener l) Adds the specified action listener to receive action events from this list void clear() Deprecated. As of JDK version 1.1, replaced by removeAll(). void delItem(int position) Deprecated. replaced by remove(String) and remove(int). void deselect(int index) Deselects the item at the specified index. 18
  • 19. String getItem(int index) Gets the item associated with the specified index. int getItemCount() Gets the number of items in the list String[] getItems() Gets the items in the list. int getRows() Gets the number of visible lines in this list int getSelectedIndex() Gets the index of the selected item on the list 19
  • 20. boolean isMultipleMode() Determines whether this list allows multiple selections. void remove(int position) Removes the item at the specified position from this scrolling list. void remove(String item) Removes the first occurrence of an item from the list 20
  • 21. TextField Constructor TextField() Constructs a new text field. TextField(int columns) Constructs a new empty text field with the specified number of columns. TextField(String text) Constructs a new text field initialized with the specified text. TextField(String text, int columns) Constructs a new text field initialized with the specified text to be displayed, and wide enough to hold the specified number of columns. 21
  • 22. void addActionListener(ActionListener l) Adds the specified action listener to receive action events from this text field. int getColumns() Gets the number of columns in this text field void setColumns(int columns) Sets the number of columns in this text field void setText(String t) Sets the text that is presented by this text component to be the specified text. 22