SlideShare a Scribd company logo
M.SUJITHA,
II-M.SC(CS&IT),
Nadar Saraswathi College Of Arts and Science, Theni
 Java includes libraries to provide multi-platform
support for Graphic User Interface objects.
 Java's GUI components include labels, text fields,
text areas, buttons.
 The Abstract Windowing Toolkit (AWT) also
includes containers which includes these
components.
 Containers include frames (windows), canvases
which are used to draw and panels which are used
to group components.
 Panels and canvases are contained in frames while
buttons and other components can be placed either
directly on frames or in panels inside the frames.
 These GUI components are automatically drawn
whenever the window is drawn.
 These GUI components are handled using Java's
event model.
 When a user interacts with a component, an event is
generated by the component that you interact with.
 For each component of your program, the
programmer is required to designate one or more
objects to "listen" for events from that component.
 If the program has a button labelled "start" you
must assign one or more objects which will be notified
when a user clicks on the button.
BUTTONS
 Button is a class in package java.awt which
represents buttons on the screen.
 The constructor is: public Button(String label)
which, when executed, creates a button with "label"
printed on it.
 The button is large enough to display the label.
 There is also a parameter less constructor that
creates an unlabeled button.
 Buttons respond to a variety of messages.
 "Action Listener" to a button with the method:
public void addActionListener(ActionListener
listener);
ADDING BUTTONS TO A FRAME OR PANEL
 A command to add a button to a frame or panel:
 my Frame .add(start Button);
 This code is used in the constructor for the frame or
panel. add(start Button) or simply add(start Button).
 The class extends Frame, which is part of java.awt.
 The constructor for Frame takes a String parameter and
creates a window with the string in the title bar.
 The constructor for Button Demo calls the super class
constructor, and then sets the size of the new Frame to be 400
x 200.
 The set Layout command tells the new Frame that new
components should be added from left to right across the panel.
EXAMPLE CODING:
import java.awt.*;
public class Button Demo extends Frame
{
protected Button start Button, stop Button;
// Constructor sets features of the frame, creates
buttons, //
public Button Demo()
{
super("Button demo");
// calls Frame constructor //
which adds title to window setSize(400,200);
// sets the size of the window //
Grid Layout. setLayout(new FlowLayout());
// create two new buttons
labels start and stop startButton = new Button("Start");
stopButton = new Button("Stop");
add(startButton); //
add buttons to frame add(stopButton);
// create an object to listen to both buttons:
ButtonListener myButtonListener = new
ButtonListener();
startButton.addActionListener(myButtonListener);
stopButton.addActionListener(myButtonListener);
setVisible(true);
// Show the window on the screen. //
Trivial main program associated with ButtonDemo //
public static void main(String args[])
{
// Create an instance of Buttons ButtonDemo app = new
ButtonDemo()
}
}
ACTION LISTENERS FOR BUTTONS
 Objects which implement the Action Listener
interface are required to implement a method action
Performed which takes a parameter of type Action
Event.
 When an action occurs to a button, all objects
which have been added as Action Listener's for that
button are notified by calling their action Performed
method with a parameter with information on the
exact event that occurred.
 The system automatically creates the ActionEvent
object and sends it along to the listener.
 It is need to manually create an ActionEvent
object in this course.The most useful methods of
ActionEvent are
INNER CLASSES
A bit heavy to have to create a completely
separate class in order to create a listener for the
two buttons in our Button Demo class.
 Two alternatives are possible.
 1.One is to let the frame itself be the
Action Listener for the button.
 2.public class Button Demo extends Frame
implements Action Listener .
 This is the style suggested in Core Java for
handling action events in simple cases.
 There is another style which is almost as simple,
but more general. It involves the use of what are
called "inner classes".
EXAMPLE SOURCE CODE:
import java.awt.*;
import java.awt.event.*;
public class ButtonDemo extends Frame
{
protected Button startButton, stopButton; public ButtonDemo()
{
startButton.addActionListener(myButtonListener);
stopButton.addActionListener(myButtonListener);
}
public static void main(String args[])
{
{
if (source == startButton) System.out.println("Start button");
else if (source == stopButton) System.out.println("Stop button");
} } }
 ThetButton Listener is declared to be protected, it
can only be used inside the containing class, Button
Demo. The method Performed is still public. If it is
declared as protected.
 These nested classes would now be contained within
a single file named ButtonDemo.java.
 Another advantage of using nested classes is that
all of the instance variables (and methods) of the
outer class are visible inside the inner class.
 This can be handy for picking up information from
other components of the outer class.
OTHER GUI COMPONENTS
LABELS
 A Label is a very simple component which contains a
string.
 The constructors are public Label()
 // creates label with no text public Label//
 The methods available are public String getText()
 The return label text public void setText(String s)
 It sets the label text the user can change the text
in Labels.
TEXT FIELDS
 A TextField is a single line area that the user can
type into.
 It is a good way of getting text input from the
user.
 The constructors are public Text Field () .
 When the user types into a text field and then
hits the return or enter key, it generates an event
which can be handled by the same kind of Action
Listener used with Buttons.
 If for some reason the user likes to be notified
every time any change is made to the Text Field one
can associate a Text Listener to the field.
TEXT AREAS
 Text Area is a class that provides an area to hold
multiple lines of text.
 It is fairly similar to Text Field except that no
special event is generated by hitting the return key.
 The constructors are
public Text Area(int rows, int columns)
// create text area with rows, columns, and displaying s
Methods public void set Editable(booleans)
// if false the Text Area is not user editable public
String get Text() //
return text in Text Area public void set Text(String s)
// sets the text

More Related Content

What's hot

Graphical User Interface in JAVA
Graphical User Interface in JAVAGraphical User Interface in JAVA
Graphical User Interface in JAVA
suraj pandey
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
Tareq Hasan
 
Event handling
Event handlingEvent handling
Event handling
swapnac12
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
Google
 
Event handling
Event handlingEvent handling
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
Manisha Keim
 
Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
Abhilash Nair
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Applets
amitksaha
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in java
Adil Mehmoood
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
shanmuga rajan
 
Collaboration diagram- UML diagram
Collaboration diagram- UML diagram Collaboration diagram- UML diagram
Collaboration diagram- UML diagram
Ramakant Soni
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
Vikas Jagtap
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
Abhilash Nair
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
VINOTH R
 
Java package
Java packageJava package
Java package
CS_GDRCST
 
Operators and expression in c#
Operators and expression in c#Operators and expression in c#
Operators and expression in c#
Dr.Neeraj Kumar Pandey
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
pm2214
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
ShahDhruv21
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
kamal kotecha
 
Sequence diagram
Sequence diagramSequence diagram
Sequence diagram
Rahul Pola
 

What's hot (20)

Graphical User Interface in JAVA
Graphical User Interface in JAVAGraphical User Interface in JAVA
Graphical User Interface in JAVA
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
 
Event handling
Event handlingEvent handling
Event handling
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
Event handling
Event handlingEvent handling
Event handling
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
 
Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Applets
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in java
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 
Collaboration diagram- UML diagram
Collaboration diagram- UML diagram Collaboration diagram- UML diagram
Collaboration diagram- UML diagram
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
 
Java package
Java packageJava package
Java package
 
Operators and expression in c#
Operators and expression in c#Operators and expression in c#
Operators and expression in c#
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
 
Sequence diagram
Sequence diagramSequence diagram
Sequence diagram
 

Similar to GUI components in Java

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 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
 
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
 
AWT information
AWT informationAWT information
AWT information
Unit Nexus Pvt. Ltd.
 
engineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptengineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.ppt
sharanyak0721
 
Ajp notes-chapter-01
Ajp notes-chapter-01Ajp notes-chapter-01
Ajp notes-chapter-01
Ankit Dubey
 
Lecture8 oopj
Lecture8 oopjLecture8 oopj
Lecture8 oopj
Dhairya Joshi
 
Swingpre 150616004959-lva1-app6892
Swingpre 150616004959-lva1-app6892Swingpre 150616004959-lva1-app6892
Swingpre 150616004959-lva1-app6892
renuka gavli
 
CORE JAVA-2
CORE JAVA-2CORE JAVA-2
Ingles 2do parcial
Ingles   2do parcialIngles   2do parcial
Ingles 2do parcial
Harry Ostaiza
 
Ajp notes-chapter-01
Ajp notes-chapter-01Ajp notes-chapter-01
Ajp notes-chapter-01
JONDHLEPOLY
 
Abstract Window Toolkit
Abstract Window ToolkitAbstract Window Toolkit
Abstract Window Toolkit
RutvaThakkar1
 
UNIT-2-AJAVA.pdf
UNIT-2-AJAVA.pdfUNIT-2-AJAVA.pdf
UNIT-2-AJAVA.pdf
PriyanshiPrajapati27
 
Chap 1 - Introduction GUI.pptx
Chap 1 - Introduction GUI.pptxChap 1 - Introduction GUI.pptx
Chap 1 - Introduction GUI.pptx
TadeseBeyene
 
Advance Java Programming (CM5I) 1.AWT
Advance Java Programming (CM5I) 1.AWTAdvance Java Programming (CM5I) 1.AWT
Advance Java Programming (CM5I) 1.AWT
Payal Dungarwal
 
13457272.ppt
13457272.ppt13457272.ppt
13457272.ppt
aptechaligarh
 
Swing
SwingSwing
Swing
Nataraj Dg
 
Awt and swing in java
Awt and swing in javaAwt and swing in java
Awt and swing in java
Shehrevar Davierwala
 
Android User Interface: Basic Form Widgets
Android User Interface: Basic Form WidgetsAndroid User Interface: Basic Form Widgets
Android User Interface: Basic Form Widgets
Ahsanul Karim
 
Windows Programming with AWT
Windows Programming with AWTWindows Programming with AWT
Windows Programming with AWT
backdoor
 

Similar to GUI components in Java (20)

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 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
 
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
 
AWT information
AWT informationAWT information
AWT information
 
engineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptengineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.ppt
 
Ajp notes-chapter-01
Ajp notes-chapter-01Ajp notes-chapter-01
Ajp notes-chapter-01
 
Lecture8 oopj
Lecture8 oopjLecture8 oopj
Lecture8 oopj
 
Swingpre 150616004959-lva1-app6892
Swingpre 150616004959-lva1-app6892Swingpre 150616004959-lva1-app6892
Swingpre 150616004959-lva1-app6892
 
CORE JAVA-2
CORE JAVA-2CORE JAVA-2
CORE JAVA-2
 
Ingles 2do parcial
Ingles   2do parcialIngles   2do parcial
Ingles 2do parcial
 
Ajp notes-chapter-01
Ajp notes-chapter-01Ajp notes-chapter-01
Ajp notes-chapter-01
 
Abstract Window Toolkit
Abstract Window ToolkitAbstract Window Toolkit
Abstract Window Toolkit
 
UNIT-2-AJAVA.pdf
UNIT-2-AJAVA.pdfUNIT-2-AJAVA.pdf
UNIT-2-AJAVA.pdf
 
Chap 1 - Introduction GUI.pptx
Chap 1 - Introduction GUI.pptxChap 1 - Introduction GUI.pptx
Chap 1 - Introduction GUI.pptx
 
Advance Java Programming (CM5I) 1.AWT
Advance Java Programming (CM5I) 1.AWTAdvance Java Programming (CM5I) 1.AWT
Advance Java Programming (CM5I) 1.AWT
 
13457272.ppt
13457272.ppt13457272.ppt
13457272.ppt
 
Swing
SwingSwing
Swing
 
Awt and swing in java
Awt and swing in javaAwt and swing in java
Awt and swing in java
 
Android User Interface: Basic Form Widgets
Android User Interface: Basic Form WidgetsAndroid User Interface: Basic Form Widgets
Android User Interface: Basic Form Widgets
 
Windows Programming with AWT
Windows Programming with AWTWindows Programming with AWT
Windows Programming with AWT
 

More from kirupasuchi1996

Rotor machine,subsitution technique
Rotor machine,subsitution techniqueRotor machine,subsitution technique
Rotor machine,subsitution technique
kirupasuchi1996
 
rotor machine
rotor machinerotor machine
rotor machine
kirupasuchi1996
 
DVI,FRACTAL IMAGE,SUB BAND IMAGE,VIDEO CODING AND WAVELET BASED COMPRESSION
DVI,FRACTAL IMAGE,SUB BAND IMAGE,VIDEO CODING AND WAVELET BASED COMPRESSIONDVI,FRACTAL IMAGE,SUB BAND IMAGE,VIDEO CODING AND WAVELET BASED COMPRESSION
DVI,FRACTAL IMAGE,SUB BAND IMAGE,VIDEO CODING AND WAVELET BASED COMPRESSION
kirupasuchi1996
 
Cyper crime
Cyper crimeCyper crime
Cyper crime
kirupasuchi1996
 
DS ppt
DS pptDS ppt
Image compression standards
Image compression standardsImage compression standards
Image compression standards
kirupasuchi1996
 
Language and Processors for Requirements Specification
Language and Processors for Requirements SpecificationLanguage and Processors for Requirements Specification
Language and Processors for Requirements Specification
kirupasuchi1996
 
Software Cost Factor
Software Cost FactorSoftware Cost Factor
Software Cost Factor
kirupasuchi1996
 
Designing Techniques in Software Engineering
Designing Techniques in Software EngineeringDesigning Techniques in Software Engineering
Designing Techniques in Software Engineering
kirupasuchi1996
 
Dmppt 180312092027
Dmppt 180312092027Dmppt 180312092027
Dmppt 180312092027
kirupasuchi1996
 
Datatransferandmanipulation 180214044522
Datatransferandmanipulation 180214044522Datatransferandmanipulation 180214044522
Datatransferandmanipulation 180214044522
kirupasuchi1996
 
Filesharing 180214044607
Filesharing 180214044607Filesharing 180214044607
Filesharing 180214044607
kirupasuchi1996
 
B tree-180214044656
B tree-180214044656B tree-180214044656
B tree-180214044656
kirupasuchi1996
 
Addressingmodes
Addressingmodes Addressingmodes
Addressingmodes
kirupasuchi1996
 
Managing,working with files
Managing,working with filesManaging,working with files
Managing,working with files
kirupasuchi1996
 

More from kirupasuchi1996 (15)

Rotor machine,subsitution technique
Rotor machine,subsitution techniqueRotor machine,subsitution technique
Rotor machine,subsitution technique
 
rotor machine
rotor machinerotor machine
rotor machine
 
DVI,FRACTAL IMAGE,SUB BAND IMAGE,VIDEO CODING AND WAVELET BASED COMPRESSION
DVI,FRACTAL IMAGE,SUB BAND IMAGE,VIDEO CODING AND WAVELET BASED COMPRESSIONDVI,FRACTAL IMAGE,SUB BAND IMAGE,VIDEO CODING AND WAVELET BASED COMPRESSION
DVI,FRACTAL IMAGE,SUB BAND IMAGE,VIDEO CODING AND WAVELET BASED COMPRESSION
 
Cyper crime
Cyper crimeCyper crime
Cyper crime
 
DS ppt
DS pptDS ppt
DS ppt
 
Image compression standards
Image compression standardsImage compression standards
Image compression standards
 
Language and Processors for Requirements Specification
Language and Processors for Requirements SpecificationLanguage and Processors for Requirements Specification
Language and Processors for Requirements Specification
 
Software Cost Factor
Software Cost FactorSoftware Cost Factor
Software Cost Factor
 
Designing Techniques in Software Engineering
Designing Techniques in Software EngineeringDesigning Techniques in Software Engineering
Designing Techniques in Software Engineering
 
Dmppt 180312092027
Dmppt 180312092027Dmppt 180312092027
Dmppt 180312092027
 
Datatransferandmanipulation 180214044522
Datatransferandmanipulation 180214044522Datatransferandmanipulation 180214044522
Datatransferandmanipulation 180214044522
 
Filesharing 180214044607
Filesharing 180214044607Filesharing 180214044607
Filesharing 180214044607
 
B tree-180214044656
B tree-180214044656B tree-180214044656
B tree-180214044656
 
Addressingmodes
Addressingmodes Addressingmodes
Addressingmodes
 
Managing,working with files
Managing,working with filesManaging,working with files
Managing,working with files
 

Recently uploaded

Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
flufftailshop
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
Intelisync
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
GDSC PJATK
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 

Recently uploaded (20)

Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 

GUI components in Java

  • 2.  Java includes libraries to provide multi-platform support for Graphic User Interface objects.  Java's GUI components include labels, text fields, text areas, buttons.  The Abstract Windowing Toolkit (AWT) also includes containers which includes these components.  Containers include frames (windows), canvases which are used to draw and panels which are used to group components.  Panels and canvases are contained in frames while buttons and other components can be placed either directly on frames or in panels inside the frames.
  • 3.  These GUI components are automatically drawn whenever the window is drawn.  These GUI components are handled using Java's event model.  When a user interacts with a component, an event is generated by the component that you interact with.  For each component of your program, the programmer is required to designate one or more objects to "listen" for events from that component.  If the program has a button labelled "start" you must assign one or more objects which will be notified when a user clicks on the button.
  • 4. BUTTONS  Button is a class in package java.awt which represents buttons on the screen.  The constructor is: public Button(String label) which, when executed, creates a button with "label" printed on it.  The button is large enough to display the label.  There is also a parameter less constructor that creates an unlabeled button.  Buttons respond to a variety of messages.  "Action Listener" to a button with the method: public void addActionListener(ActionListener listener);
  • 5. ADDING BUTTONS TO A FRAME OR PANEL  A command to add a button to a frame or panel:  my Frame .add(start Button);  This code is used in the constructor for the frame or panel. add(start Button) or simply add(start Button).  The class extends Frame, which is part of java.awt.  The constructor for Frame takes a String parameter and creates a window with the string in the title bar.  The constructor for Button Demo calls the super class constructor, and then sets the size of the new Frame to be 400 x 200.  The set Layout command tells the new Frame that new components should be added from left to right across the panel.
  • 6. EXAMPLE CODING: import java.awt.*; public class Button Demo extends Frame { protected Button start Button, stop Button; // Constructor sets features of the frame, creates buttons, // public Button Demo() { super("Button demo"); // calls Frame constructor // which adds title to window setSize(400,200); // sets the size of the window //
  • 7. Grid Layout. setLayout(new FlowLayout()); // create two new buttons labels start and stop startButton = new Button("Start"); stopButton = new Button("Stop"); add(startButton); // add buttons to frame add(stopButton); // create an object to listen to both buttons: ButtonListener myButtonListener = new ButtonListener();
  • 8. startButton.addActionListener(myButtonListener); stopButton.addActionListener(myButtonListener); setVisible(true); // Show the window on the screen. // Trivial main program associated with ButtonDemo // public static void main(String args[]) { // Create an instance of Buttons ButtonDemo app = new ButtonDemo() } }
  • 9. ACTION LISTENERS FOR BUTTONS  Objects which implement the Action Listener interface are required to implement a method action Performed which takes a parameter of type Action Event.  When an action occurs to a button, all objects which have been added as Action Listener's for that button are notified by calling their action Performed method with a parameter with information on the exact event that occurred.  The system automatically creates the ActionEvent object and sends it along to the listener.  It is need to manually create an ActionEvent object in this course.The most useful methods of ActionEvent are
  • 10. INNER CLASSES A bit heavy to have to create a completely separate class in order to create a listener for the two buttons in our Button Demo class.  Two alternatives are possible.  1.One is to let the frame itself be the Action Listener for the button.  2.public class Button Demo extends Frame implements Action Listener .  This is the style suggested in Core Java for handling action events in simple cases.  There is another style which is almost as simple, but more general. It involves the use of what are called "inner classes".
  • 11. EXAMPLE SOURCE CODE: import java.awt.*; import java.awt.event.*; public class ButtonDemo extends Frame { protected Button startButton, stopButton; public ButtonDemo() { startButton.addActionListener(myButtonListener); stopButton.addActionListener(myButtonListener); } public static void main(String args[]) { { if (source == startButton) System.out.println("Start button"); else if (source == stopButton) System.out.println("Stop button"); } } }
  • 12.  ThetButton Listener is declared to be protected, it can only be used inside the containing class, Button Demo. The method Performed is still public. If it is declared as protected.  These nested classes would now be contained within a single file named ButtonDemo.java.  Another advantage of using nested classes is that all of the instance variables (and methods) of the outer class are visible inside the inner class.  This can be handy for picking up information from other components of the outer class.
  • 13. OTHER GUI COMPONENTS LABELS  A Label is a very simple component which contains a string.  The constructors are public Label()  // creates label with no text public Label//  The methods available are public String getText()  The return label text public void setText(String s)  It sets the label text the user can change the text in Labels.
  • 14. TEXT FIELDS  A TextField is a single line area that the user can type into.  It is a good way of getting text input from the user.  The constructors are public Text Field () .  When the user types into a text field and then hits the return or enter key, it generates an event which can be handled by the same kind of Action Listener used with Buttons.  If for some reason the user likes to be notified every time any change is made to the Text Field one can associate a Text Listener to the field.
  • 15. TEXT AREAS  Text Area is a class that provides an area to hold multiple lines of text.  It is fairly similar to Text Field except that no special event is generated by hitting the return key.  The constructors are public Text Area(int rows, int columns) // create text area with rows, columns, and displaying s Methods public void set Editable(booleans) // if false the Text Area is not user editable public String get Text() // return text in Text Area public void set Text(String s) // sets the text