SlideShare a Scribd company logo
1 of 28
GUI(Graphical User Interface)
Rishi Ram Khanal
BIM (TU)
Introduction to GUI
• Graphical user interface is a type of user interface
that allows users to interact with the screen using
graphical components(Visual Indicators) rather
than text commands.
• There are two sets of Java APIs(Application
Programming Interface) for graphics
Programming:
1.AWT(Abstract Windowing Toolkit)
2.Swing
AWT
• It consist of 12 packages
• Only 2 packages-java.awt and java.awt.event
are commonly used
• The java.awt package contains the core AWT
graphics classes
• GUI component classes(such as Button, Textfield ,label)
• GUI container classes(frame ,panel,Dialog)
• Layout mananger(flowlayout,Borderlayout,Gridlayout)
• Custom graphic classes(Graphic,Color,Font)
AWT Events
• The java .awt.event package supports event
handling
• Event classes (ActionEvent,
MouseEvent,KeyEvent and WindowEvent)
• Event Listener Interfaces(Such as
ActionListener,Mouselistener,
WindowsListener)
Container
• A frame is the top –level container of an AWT
GUI program
• A panel is a rectangular area(or portion) used
to group related GUI components
• In a GUI program , a component must be kept
in a container
• Every container has a method called
add(Component c)
APPLET
• An applet is a java program that runs in a Web browser
• Applet is a container class like Frame
• An applet is a java class that extends the
java.applet.Applet class
• Applets are designed to be embedded within an HTML
page
• When a user views an Html page that contains an
applet ,the code for the applet is downloaded to the
user’s machine
• A JVM is required to view an applet
PRATICAL
• How to make an applet Program?
• How a programmer can compile and run an
applet code?
• How applet can be embedded in the HTML
code?
LIFE CYCLE OF APPLET
• JVM on the user’s machine creates an instance of
the applet class and invokes various methods
during the applet’s life time
• Four method in the Applet class give you the
framework on which you can build any applet
Application
• Init()
• Start()
• Stop()
• Destroy()
• Paint()(important function but not a part of Lifecycle)
How to set Components in Applet
• Component
• Button
• Textfield
• Label
• CheckBox
• List
• We need to design GUI so that user can
interact with the applet
• We have to place component on the applet
container , to meet this requirement
For pratical
• Basic Skeleton of an applet
• Creating Component reference variables
• Initialize Components
• Adding Components to the applet
• Setting layout
Event Handling in an Applet In java
• Event
Changing the state of an object is knows
as Event. For example click on button,
dragging mouse, minimizing window etc
The java.awt.event package provides many
event classes and Listener interfaces for event
handling
Event handling is to make java code ready to
respond any particular event
Feeling of a button
Hey , I am button
class object. user can
click me, but I don’t
know what to run
when he does that
Feeling of the programmer(you)
I am the programmer , I have to write code that
should be executed on click of a button
Public void someFunction()
{
write some code
}
Struggling phase:
But do my function get to know that
button has just clicked?
Two Ends Of Story
Hey programmer , I have method to
register to register your code with me
Ok that means
button.addActionListener();
Communication can solve the issue
Yes , but you have to pass an object to
function
Button.addActionListener(here?);
But object of which class?
See prototype defined in Button class
Public void addActionListener(ActionListener,
actionlistener)
But ActionListener ia an interface, which I have to
pass an object of class which implements
ActionLIstener.
Button.addActionListener(object);
Ok, then I have to make a class which implements
ActionListener
Class Myhandler implements ActionListener
{
Public void someFunction (ActionEvent e)
{
write some code
}
}
Button.addActionListener(new MyHandler());
This is the way I can register my
handler with my Button object
Now I have an object
of Myhandler
referenced by
actionListener(a
reference variable of
ActionListener)
Parameter Passing in an Applet
<param> tag
• Parameter are passed to applets in Name=Value
pairs in <param> tags betweeen the opening and
closing applet tags
• Inside the applet , you read the values passed
through the param tags with the getParameter()
method of the java.applet.Applet class
Import java.applet.Applet;
Import java.awt.*;
/*<applet code=“Myapplet” width=“300” height=“500”
<param name=“saroj” value=“paras”></param></applet>
Public class Myapplet extends Applet
{
String message=“hello”;
Public void paint(Graphics s)
{
String s1=this.getParameter(“saroj”);
if(s1==null)
s1=message;
s.drawString(s1,150,150);
}
}
Introduction to AWT
• Java Awt(Abstract Windowing Toolkit) is an
API to develop GUI or window-based
application in java.
• AWT classes
• GUI component classes(such as Button, Textfield ,label)
• GUI container classes(frame ,panel,DialogBoxes)
• Layout mananger(flowlayout,Borderlayout,Gridlayout)
• Custom graphic classes(Graphic,Color,Font)
• Event Handling
classes(AWTEvent,AwteEventMultiCaster)
Hierarchy of java AWT classes
Frame
• The Frame is the container that contain title bar
and can have menu bars. It can have other
components like button, textfield etc.
• The window is the container that have no borders
and menu bars. You must use frame, dialog or
another window for creating a window.
• The Panel is the container that doesn't contain
title bar and menu bars. It can have other
components like button, textfield etc.
Working with Frame Window
• Setting the window’s Dimensions
Void setSize(init newWidth, init newHeight)
void setSize(Dimension newSize)
getSize() method is used to obtain current size
of a window.
• Hiding and showing a window
void setVisible(boolean visibleFlag)
Setting a window’s Title
void setTitle(String newTitle)
Example of AWT frame
Import java.awt.*;
Class MyFrame extends Frame
{
MyFrame()
{
setTitle(“Myfirst Frame”);
setSize(200,200);
Button b=new Button(“click Me”);
setLayout(null);
b.setBounds(50,50,50,50);
add(b);
setVisible(true);
}
}
Practical

More Related Content

What's hot

What's hot (20)

GUI Programming with Java
GUI Programming with JavaGUI Programming with Java
GUI Programming with Java
 
Awt
AwtAwt
Awt
 
Event Handling in Java
Event Handling in JavaEvent Handling in Java
Event Handling in Java
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
Advance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handlingAdvance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handling
 
Event handling
Event handlingEvent handling
Event handling
 
Event Handling in JAVA
Event Handling in JAVAEvent Handling in JAVA
Event Handling in JAVA
 
GUI components in Java
GUI components in JavaGUI components in Java
GUI components in Java
 
Event handling
Event handlingEvent handling
Event handling
 
GUI Programming in JAVA (Using Netbeans) - A Review
GUI Programming in JAVA (Using Netbeans) -  A ReviewGUI Programming in JAVA (Using Netbeans) -  A Review
GUI Programming in JAVA (Using Netbeans) - A Review
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
 
Swing
SwingSwing
Swing
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1
 
Java awt tutorial javatpoint
Java awt tutorial   javatpointJava awt tutorial   javatpoint
Java awt tutorial javatpoint
 
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
 
java swing
java swingjava swing
java swing
 
Event handling
Event handlingEvent handling
Event handling
 
tL19 awt
tL19 awttL19 awt
tL19 awt
 
Dr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWTDr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWT
 
GUI programming
GUI programmingGUI programming
GUI programming
 

Similar to GUI (graphical user interface) (20)

object oriented programming examples
object oriented programming examplesobject oriented programming examples
object oriented programming examples
 
Java Applets
Java AppletsJava Applets
Java Applets
 
Unit 7 Java
Unit 7 JavaUnit 7 Java
Unit 7 Java
 
JAVA (UNIT 5)
JAVA (UNIT 5)JAVA (UNIT 5)
JAVA (UNIT 5)
 
Java Applet
Java AppletJava Applet
Java Applet
 
Applet in java
Applet in javaApplet in java
Applet in java
 
Chap1 1 1
Chap1 1 1Chap1 1 1
Chap1 1 1
 
Chap1 1.1
Chap1 1.1Chap1 1.1
Chap1 1.1
 
GUI.pdf
GUI.pdfGUI.pdf
GUI.pdf
 
17625-1.pptx
17625-1.pptx17625-1.pptx
17625-1.pptx
 
AWT.pptx
AWT.pptxAWT.pptx
AWT.pptx
 
applet.pptx
applet.pptxapplet.pptx
applet.pptx
 
engineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptengineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.ppt
 
27 applet programming
27  applet programming27  applet programming
27 applet programming
 
Ingles 2do parcial
Ingles   2do parcialIngles   2do parcial
Ingles 2do parcial
 
Awt event
Awt eventAwt event
Awt event
 
Java applet
Java appletJava applet
Java applet
 
Ajp notes-chapter-01
Ajp notes-chapter-01Ajp notes-chapter-01
Ajp notes-chapter-01
 
java- Abstract Window toolkit
java- Abstract Window toolkitjava- Abstract Window toolkit
java- Abstract Window toolkit
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Applets
 

More from rishi ram khanal

Measurement of gdp under product method
Measurement of gdp under product methodMeasurement of gdp under product method
Measurement of gdp under product methodrishi ram khanal
 
Major social problem in nepal child labour socilology
Major social problem in nepal child labour socilologyMajor social problem in nepal child labour socilology
Major social problem in nepal child labour socilologyrishi ram khanal
 
Introduction to artificial intelligence
Introduction to artificial intelligenceIntroduction to artificial intelligence
Introduction to artificial intelligencerishi ram khanal
 
Interview method in research
Interview method in researchInterview method in research
Interview method in researchrishi ram khanal
 
Presentation on kurtosis statistics
Presentation on kurtosis statisticsPresentation on kurtosis statistics
Presentation on kurtosis statisticsrishi ram khanal
 
Importance of double entry accounting system for public limited company (basi...
Importance of double entry accounting system for public limited company (basi...Importance of double entry accounting system for public limited company (basi...
Importance of double entry accounting system for public limited company (basi...rishi ram khanal
 
Implementation issues software engineering
Implementation issues software engineeringImplementation issues software engineering
Implementation issues software engineeringrishi ram khanal
 
Effect of migration in developing country
Effect of migration in developing countryEffect of migration in developing country
Effect of migration in developing countryrishi ram khanal
 
Goals of firm business finance
Goals of firm business financeGoals of firm business finance
Goals of firm business financerishi ram khanal
 
General register organization (computer organization)
General register organization  (computer organization)General register organization  (computer organization)
General register organization (computer organization)rishi ram khanal
 
GDP and trends economics .rishi
GDP and trends economics .rishiGDP and trends economics .rishi
GDP and trends economics .rishirishi ram khanal
 
Final internship-report on the networking department of the internet service ...
Final internship-report on the networking department of the internet service ...Final internship-report on the networking department of the internet service ...
Final internship-report on the networking department of the internet service ...rishi ram khanal
 
Field study of crystal finance share broker
Field study of crystal finance share brokerField study of crystal finance share broker
Field study of crystal finance share brokerrishi ram khanal
 
Database management system
Database management systemDatabase management system
Database management systemrishi ram khanal
 
Credential reuse cyber security
Credential reuse cyber securityCredential reuse cyber security
Credential reuse cyber securityrishi ram khanal
 
Cisco packet tracer router
Cisco packet tracer  routerCisco packet tracer  router
Cisco packet tracer routerrishi ram khanal
 

More from rishi ram khanal (20)

Measurement of gdp under product method
Measurement of gdp under product methodMeasurement of gdp under product method
Measurement of gdp under product method
 
Major social problem in nepal child labour socilology
Major social problem in nepal child labour socilologyMajor social problem in nepal child labour socilology
Major social problem in nepal child labour socilology
 
Light source ooad
Light source ooadLight source ooad
Light source ooad
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Introduction to artificial intelligence
Introduction to artificial intelligenceIntroduction to artificial intelligence
Introduction to artificial intelligence
 
Interview method in research
Interview method in researchInterview method in research
Interview method in research
 
Presentation on kurtosis statistics
Presentation on kurtosis statisticsPresentation on kurtosis statistics
Presentation on kurtosis statistics
 
Importance of double entry accounting system for public limited company (basi...
Importance of double entry accounting system for public limited company (basi...Importance of double entry accounting system for public limited company (basi...
Importance of double entry accounting system for public limited company (basi...
 
Implementation issues software engineering
Implementation issues software engineeringImplementation issues software engineering
Implementation issues software engineering
 
Effect of migration in developing country
Effect of migration in developing countryEffect of migration in developing country
Effect of migration in developing country
 
Goals of firm business finance
Goals of firm business financeGoals of firm business finance
Goals of firm business finance
 
General register organization (computer organization)
General register organization  (computer organization)General register organization  (computer organization)
General register organization (computer organization)
 
GDP and trends economics .rishi
GDP and trends economics .rishiGDP and trends economics .rishi
GDP and trends economics .rishi
 
Final internship-report on the networking department of the internet service ...
Final internship-report on the networking department of the internet service ...Final internship-report on the networking department of the internet service ...
Final internship-report on the networking department of the internet service ...
 
Field study of crystal finance share broker
Field study of crystal finance share brokerField study of crystal finance share broker
Field study of crystal finance share broker
 
Dijkstra algorithm
Dijkstra algorithmDijkstra algorithm
Dijkstra algorithm
 
Computer virus and worms
Computer virus and wormsComputer virus and worms
Computer virus and worms
 
Database management system
Database management systemDatabase management system
Database management system
 
Credential reuse cyber security
Credential reuse cyber securityCredential reuse cyber security
Credential reuse cyber security
 
Cisco packet tracer router
Cisco packet tracer  routerCisco packet tracer  router
Cisco packet tracer router
 

Recently uploaded

EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIkoyaldeepu123
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 

Recently uploaded (20)

EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AI
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 

GUI (graphical user interface)

  • 2. Introduction to GUI • Graphical user interface is a type of user interface that allows users to interact with the screen using graphical components(Visual Indicators) rather than text commands. • There are two sets of Java APIs(Application Programming Interface) for graphics Programming: 1.AWT(Abstract Windowing Toolkit) 2.Swing
  • 3. AWT • It consist of 12 packages • Only 2 packages-java.awt and java.awt.event are commonly used • The java.awt package contains the core AWT graphics classes • GUI component classes(such as Button, Textfield ,label) • GUI container classes(frame ,panel,Dialog) • Layout mananger(flowlayout,Borderlayout,Gridlayout) • Custom graphic classes(Graphic,Color,Font)
  • 4. AWT Events • The java .awt.event package supports event handling • Event classes (ActionEvent, MouseEvent,KeyEvent and WindowEvent) • Event Listener Interfaces(Such as ActionListener,Mouselistener, WindowsListener)
  • 5. Container • A frame is the top –level container of an AWT GUI program • A panel is a rectangular area(or portion) used to group related GUI components • In a GUI program , a component must be kept in a container • Every container has a method called add(Component c)
  • 6.
  • 7. APPLET • An applet is a java program that runs in a Web browser • Applet is a container class like Frame • An applet is a java class that extends the java.applet.Applet class • Applets are designed to be embedded within an HTML page • When a user views an Html page that contains an applet ,the code for the applet is downloaded to the user’s machine • A JVM is required to view an applet
  • 8. PRATICAL • How to make an applet Program? • How a programmer can compile and run an applet code? • How applet can be embedded in the HTML code?
  • 9. LIFE CYCLE OF APPLET • JVM on the user’s machine creates an instance of the applet class and invokes various methods during the applet’s life time • Four method in the Applet class give you the framework on which you can build any applet Application • Init() • Start() • Stop() • Destroy() • Paint()(important function but not a part of Lifecycle)
  • 10. How to set Components in Applet • Component • Button • Textfield • Label • CheckBox • List • We need to design GUI so that user can interact with the applet • We have to place component on the applet container , to meet this requirement
  • 11. For pratical • Basic Skeleton of an applet • Creating Component reference variables • Initialize Components • Adding Components to the applet • Setting layout
  • 12. Event Handling in an Applet In java • Event Changing the state of an object is knows as Event. For example click on button, dragging mouse, minimizing window etc The java.awt.event package provides many event classes and Listener interfaces for event handling Event handling is to make java code ready to respond any particular event
  • 13. Feeling of a button Hey , I am button class object. user can click me, but I don’t know what to run when he does that
  • 14. Feeling of the programmer(you) I am the programmer , I have to write code that should be executed on click of a button Public void someFunction() { write some code } Struggling phase: But do my function get to know that button has just clicked?
  • 15. Two Ends Of Story Hey programmer , I have method to register to register your code with me Ok that means button.addActionListener();
  • 16. Communication can solve the issue Yes , but you have to pass an object to function Button.addActionListener(here?); But object of which class?
  • 17. See prototype defined in Button class Public void addActionListener(ActionListener, actionlistener) But ActionListener ia an interface, which I have to pass an object of class which implements ActionLIstener. Button.addActionListener(object);
  • 18. Ok, then I have to make a class which implements ActionListener Class Myhandler implements ActionListener { Public void someFunction (ActionEvent e) { write some code } }
  • 19. Button.addActionListener(new MyHandler()); This is the way I can register my handler with my Button object
  • 20. Now I have an object of Myhandler referenced by actionListener(a reference variable of ActionListener)
  • 21. Parameter Passing in an Applet <param> tag • Parameter are passed to applets in Name=Value pairs in <param> tags betweeen the opening and closing applet tags • Inside the applet , you read the values passed through the param tags with the getParameter() method of the java.applet.Applet class
  • 22. Import java.applet.Applet; Import java.awt.*; /*<applet code=“Myapplet” width=“300” height=“500” <param name=“saroj” value=“paras”></param></applet> Public class Myapplet extends Applet { String message=“hello”; Public void paint(Graphics s) { String s1=this.getParameter(“saroj”); if(s1==null) s1=message; s.drawString(s1,150,150); } }
  • 23. Introduction to AWT • Java Awt(Abstract Windowing Toolkit) is an API to develop GUI or window-based application in java. • AWT classes • GUI component classes(such as Button, Textfield ,label) • GUI container classes(frame ,panel,DialogBoxes) • Layout mananger(flowlayout,Borderlayout,Gridlayout) • Custom graphic classes(Graphic,Color,Font) • Event Handling classes(AWTEvent,AwteEventMultiCaster)
  • 24. Hierarchy of java AWT classes
  • 25. Frame • The Frame is the container that contain title bar and can have menu bars. It can have other components like button, textfield etc. • The window is the container that have no borders and menu bars. You must use frame, dialog or another window for creating a window. • The Panel is the container that doesn't contain title bar and menu bars. It can have other components like button, textfield etc.
  • 26. Working with Frame Window • Setting the window’s Dimensions Void setSize(init newWidth, init newHeight) void setSize(Dimension newSize) getSize() method is used to obtain current size of a window. • Hiding and showing a window void setVisible(boolean visibleFlag) Setting a window’s Title void setTitle(String newTitle)
  • 27. Example of AWT frame Import java.awt.*; Class MyFrame extends Frame { MyFrame() { setTitle(“Myfirst Frame”); setSize(200,200); Button b=new Button(“click Me”); setLayout(null); b.setBounds(50,50,50,50); add(b); setVisible(true); } }