SlideShare a Scribd company logo
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)
GUI (graphical user interface)
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
Ad

More Related Content

What's hot (20)

GUI Programming with Java
GUI Programming with JavaGUI Programming with Java
GUI Programming with Java
Jussi Pohjolainen
 
Awt
AwtAwt
Awt
Rakesh Patil
 
Event Handling in Java
Event Handling in JavaEvent Handling in Java
Event Handling in Java
Ayesha Kanwal
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
Google
 
Advance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handlingAdvance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handling
Payal Dungarwal
 
Event handling
Event handlingEvent handling
Event handling
Anand Grewal
 
Event Handling in JAVA
Event Handling in JAVAEvent Handling in JAVA
Event Handling in JAVA
Srajan Shukla
 
GUI components in Java
GUI components in JavaGUI components in Java
GUI components in Java
kirupasuchi1996
 
Event handling
Event handlingEvent handling
Event handling
Shree M.L.Kakadiya MCA mahila college, Amreli
 
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
Fernando Torres
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
Tareq Hasan
 
Swing
SwingSwing
Swing
Jaydeep Viradiya
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1
PRN USM
 
Java awt tutorial javatpoint
Java awt tutorial   javatpointJava awt tutorial   javatpoint
Java awt tutorial javatpoint
Ricardo Garcia
 
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
 
java swing
java swingjava swing
java swing
Waheed Warraich
 
Event handling
Event handlingEvent handling
Event handling
Ravi_Kant_Sahu
 
tL19 awt
tL19 awttL19 awt
tL19 awt
teach4uin
 
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
DrRajeshreeKhande
 
GUI programming
GUI programmingGUI programming
GUI programming
Vineeta Garg
 

Similar to GUI (graphical user interface) (20)

object oriented programming examples
object oriented programming examplesobject oriented programming examples
object oriented programming examples
Abdii Rashid
 
Java Applets
Java AppletsJava Applets
Java Applets
Dr. Jasmine Beulah Gnanadurai
 
Unit 7 Java
Unit 7 JavaUnit 7 Java
Unit 7 Java
arnold 7490
 
JAVA (UNIT 5)
JAVA (UNIT 5)JAVA (UNIT 5)
JAVA (UNIT 5)
Dr. SURBHI SAROHA
 
Java Applet
Java AppletJava Applet
Java Applet
Shree M.L.Kakadiya MCA mahila college, Amreli
 
Applet in java
Applet in javaApplet in java
Applet in java
Jancypriya M
 
Chap1 1 1
Chap1 1 1Chap1 1 1
Chap1 1 1
Hemo Chella
 
Chap1 1.1
Chap1 1.1Chap1 1.1
Chap1 1.1
Hemo Chella
 
GUI.pdf
GUI.pdfGUI.pdf
GUI.pdf
Poornima E.G.
 
introduction to JAVA awt programmin .ppt
introduction to JAVA awt programmin .pptintroduction to JAVA awt programmin .ppt
introduction to JAVA awt programmin .ppt
bgvthm
 
17625-1.pptx
17625-1.pptx17625-1.pptx
17625-1.pptx
BhaskarDharmadhikari
 
AWT.pptx
AWT.pptxAWT.pptx
AWT.pptx
FAHMIDAASEEZ1
 
Unit 1- awt(Abstract Window Toolkit) .ppt
Unit 1- awt(Abstract Window Toolkit) .pptUnit 1- awt(Abstract Window Toolkit) .ppt
Unit 1- awt(Abstract Window Toolkit) .ppt
Deepgaichor1
 
applet.pptx
applet.pptxapplet.pptx
applet.pptx
SachinBhosale73
 
engineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptengineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.ppt
sharanyak0721
 
MSBTE Computer Engineering Java applet.pptx
MSBTE Computer Engineering Java applet.pptxMSBTE Computer Engineering Java applet.pptx
MSBTE Computer Engineering Java applet.pptx
kunalgaikwad1705
 
27 applet programming
27  applet programming27  applet programming
27 applet programming
Ravindra Rathore
 
Ingles 2do parcial
Ingles   2do parcialIngles   2do parcial
Ingles 2do parcial
Harry Ostaiza
 
Creating GUI.pptx Gui graphical user interface
Creating GUI.pptx Gui graphical user interfaceCreating GUI.pptx Gui graphical user interface
Creating GUI.pptx Gui graphical user interface
pikachu02434
 
Awt event
Awt eventAwt event
Awt event
Vijay Kumar
 
Ad

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
rishi 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 socilology
rishi ram khanal
 
Light source ooad
Light source ooadLight source ooad
Light source ooad
rishi ram khanal
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
rishi ram khanal
 
Introduction to artificial intelligence
Introduction to artificial intelligenceIntroduction to artificial intelligence
Introduction to artificial intelligence
rishi ram khanal
 
Interview method in research
Interview method in researchInterview method in research
Interview method in research
rishi ram khanal
 
Presentation on kurtosis statistics
Presentation on kurtosis statisticsPresentation on kurtosis statistics
Presentation on kurtosis statistics
rishi 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 engineering
rishi ram khanal
 
Effect of migration in developing country
Effect of migration in developing countryEffect of migration in developing country
Effect of migration in developing country
rishi ram khanal
 
Goals of firm business finance
Goals of firm business financeGoals of firm business finance
Goals of firm business finance
rishi 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 .rishi
rishi 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 broker
rishi ram khanal
 
Dijkstra algorithm
Dijkstra algorithmDijkstra algorithm
Dijkstra algorithm
rishi ram khanal
 
Computer virus and worms
Computer virus and wormsComputer virus and worms
Computer virus and worms
rishi ram khanal
 
Database management system
Database management systemDatabase management system
Database management system
rishi ram khanal
 
Credential reuse cyber security
Credential reuse cyber securityCredential reuse cyber security
Credential reuse cyber security
rishi ram khanal
 
Cisco packet tracer router
Cisco packet tracer  routerCisco packet tracer  router
Cisco packet tracer router
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 method
rishi 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 socilology
rishi ram khanal
 
Introduction to artificial intelligence
Introduction to artificial intelligenceIntroduction to artificial intelligence
Introduction to artificial intelligence
rishi ram khanal
 
Interview method in research
Interview method in researchInterview method in research
Interview method in research
rishi ram khanal
 
Presentation on kurtosis statistics
Presentation on kurtosis statisticsPresentation on kurtosis statistics
Presentation on kurtosis statistics
rishi 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 engineering
rishi ram khanal
 
Effect of migration in developing country
Effect of migration in developing countryEffect of migration in developing country
Effect of migration in developing country
rishi ram khanal
 
Goals of firm business finance
Goals of firm business financeGoals of firm business finance
Goals of firm business finance
rishi 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 .rishi
rishi 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 broker
rishi ram khanal
 
Database management system
Database management systemDatabase management system
Database management system
rishi ram khanal
 
Credential reuse cyber security
Credential reuse cyber securityCredential reuse cyber security
Credential reuse cyber security
rishi ram khanal
 
Cisco packet tracer router
Cisco packet tracer  routerCisco packet tracer  router
Cisco packet tracer router
rishi ram khanal
 
Ad

Recently uploaded (20)

Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...
Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...
Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...
Journal of Soft Computing in Civil Engineering
 
introduction technology technology tec.pptx
introduction technology technology tec.pptxintroduction technology technology tec.pptx
introduction technology technology tec.pptx
Iftikhar70
 
Working with USDOT UTCs: From Conception to Implementation
Working with USDOT UTCs: From Conception to ImplementationWorking with USDOT UTCs: From Conception to Implementation
Working with USDOT UTCs: From Conception to Implementation
Alabama Transportation Assistance Program
 
Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control
 
Design of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdfDesign of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdf
Kamel Farid
 
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Journal of Soft Computing in Civil Engineering
 
Slide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptxSlide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptx
vvsasane
 
Nanometer Metal-Organic-Framework Literature Comparison
Nanometer Metal-Organic-Framework  Literature ComparisonNanometer Metal-Organic-Framework  Literature Comparison
Nanometer Metal-Organic-Framework Literature Comparison
Chris Harding
 
hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .
NABLAS株式会社
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
Evonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdfEvonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdf
szhang13
 
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdfSmart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
PawachMetharattanara
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
AI Publications
 
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning ModelsMode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Journal of Soft Computing in Civil Engineering
 
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic AlgorithmDesign Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Journal of Soft Computing in Civil Engineering
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdfLittle Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
gori42199
 
David Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry - Specializes In AWS, Microservices And Python.pdfDavid Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry
 
Uses of drones in civil construction.pdf
Uses of drones in civil construction.pdfUses of drones in civil construction.pdf
Uses of drones in civil construction.pdf
surajsen1729
 
introduction technology technology tec.pptx
introduction technology technology tec.pptxintroduction technology technology tec.pptx
introduction technology technology tec.pptx
Iftikhar70
 
Design of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdfDesign of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdf
Kamel Farid
 
Slide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptxSlide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptx
vvsasane
 
Nanometer Metal-Organic-Framework Literature Comparison
Nanometer Metal-Organic-Framework  Literature ComparisonNanometer Metal-Organic-Framework  Literature Comparison
Nanometer Metal-Organic-Framework Literature Comparison
Chris Harding
 
hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .
NABLAS株式会社
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
Evonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdfEvonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdf
szhang13
 
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdfSmart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
PawachMetharattanara
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
AI Publications
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdfLittle Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
gori42199
 
David Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry - Specializes In AWS, Microservices And Python.pdfDavid Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry
 
Uses of drones in civil construction.pdf
Uses of drones in civil construction.pdfUses of drones in civil construction.pdf
Uses of drones in civil construction.pdf
surajsen1729
 

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)
  • 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); } }
  翻译: