尊敬的 微信汇率:1円 ≈ 0.046166 元 支付宝汇率:1円 ≈ 0.046257元 [退出登录]
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

Java package
Java packageJava package
Java package
CS_GDRCST
 
Event Handling in JAVA
Event Handling in JAVAEvent Handling in JAVA
Event Handling in JAVA
Srajan Shukla
 
Window to viewport transformation
Window to viewport transformationWindow to viewport transformation
Window to viewport transformation
Ankit Garg
 
Cohen sutherland line clipping
Cohen sutherland line clippingCohen sutherland line clipping
Cohen sutherland line clipping
Mani Kanth
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
VINOTH R
 
Unit 3
Unit 3Unit 3
Unit 3
ypnrao
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Composite transformations
Composite transformationsComposite transformations
Composite transformations
Mohd Arif
 
Command line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorialCommand line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorial
Kuntal Bhowmick
 
Method overloading and constructor overloading in java
Method overloading and constructor overloading in javaMethod overloading and constructor overloading in java
Method overloading and constructor overloading in java
baabtra.com - No. 1 supplier of quality freshers
 
Attributes of Output Primitives
Attributes of Output PrimitivesAttributes of Output Primitives
Attributes of Output Primitives
Renita Santhmayora
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.
Mohd Arif
 
sutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingsutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clipping
Arvind Kumar
 
Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
Pranali Chaudhari
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Abhilash Nair
 
Event handling
Event handlingEvent handling
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)
Timbal Mayank
 
GUI Programming In Java
GUI Programming In JavaGUI Programming In Java
GUI Programming In Java
yht4ever
 
Life cycle-of-a-thread
Life cycle-of-a-threadLife cycle-of-a-thread
Life cycle-of-a-thread
javaicon
 
Classical problem of synchronization
Classical problem of synchronizationClassical problem of synchronization
Classical problem of synchronization
Shakshi Ranawat
 

What's hot (20)

Java package
Java packageJava package
Java package
 
Event Handling in JAVA
Event Handling in JAVAEvent Handling in JAVA
Event Handling in JAVA
 
Window to viewport transformation
Window to viewport transformationWindow to viewport transformation
Window to viewport transformation
 
Cohen sutherland line clipping
Cohen sutherland line clippingCohen sutherland line clipping
Cohen sutherland line clipping
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
 
Unit 3
Unit 3Unit 3
Unit 3
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Composite transformations
Composite transformationsComposite transformations
Composite transformations
 
Command line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorialCommand line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorial
 
Method overloading and constructor overloading in java
Method overloading and constructor overloading in javaMethod overloading and constructor overloading in java
Method overloading and constructor overloading in java
 
Attributes of Output Primitives
Attributes of Output PrimitivesAttributes of Output Primitives
Attributes of Output Primitives
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.
 
sutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingsutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clipping
 
Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Event handling
Event handlingEvent handling
Event handling
 
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)
 
GUI Programming In Java
GUI Programming In JavaGUI Programming In Java
GUI Programming In Java
 
Life cycle-of-a-thread
Life cycle-of-a-threadLife cycle-of-a-thread
Life cycle-of-a-thread
 
Classical problem of synchronization
Classical problem of synchronizationClassical problem of synchronization
Classical problem of synchronization
 

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
nehakumari0xf
 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
kashyapneha2809
 
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
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in java
Adil Mehmoood
 
javaprogramming framework-ppt frame.pptx
javaprogramming framework-ppt frame.pptxjavaprogramming framework-ppt frame.pptx
javaprogramming framework-ppt frame.pptx
DrDGayathriDevi
 
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
 

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
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in java
 
javaprogramming framework-ppt frame.pptx
javaprogramming framework-ppt frame.pptxjavaprogramming framework-ppt frame.pptx
javaprogramming framework-ppt frame.pptx
 
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
 

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

TrustArc Webinar - Your Guide for Smooth Cross-Border Data Transfers and Glob...
TrustArc Webinar - Your Guide for Smooth Cross-Border Data Transfers and Glob...TrustArc Webinar - Your Guide for Smooth Cross-Border Data Transfers and Glob...
TrustArc Webinar - Your Guide for Smooth Cross-Border Data Transfers and Glob...
TrustArc
 
From NCSA to the National Research Platform
From NCSA to the National Research PlatformFrom NCSA to the National Research Platform
From NCSA to the National Research Platform
Larry Smarr
 
Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!
Tobias Schneck
 
MongoDB to ScyllaDB: Technical Comparison and the Path to Success
MongoDB to ScyllaDB: Technical Comparison and the Path to SuccessMongoDB to ScyllaDB: Technical Comparison and the Path to Success
MongoDB to ScyllaDB: Technical Comparison and the Path to Success
ScyllaDB
 
New ThousandEyes Product Features and Release Highlights: June 2024
New ThousandEyes Product Features and Release Highlights: June 2024New ThousandEyes Product Features and Release Highlights: June 2024
New ThousandEyes Product Features and Release Highlights: June 2024
ThousandEyes
 
Guidelines for Effective Data Visualization
Guidelines for Effective Data VisualizationGuidelines for Effective Data Visualization
Guidelines for Effective Data Visualization
UmmeSalmaM1
 
DynamoDB to ScyllaDB: Technical Comparison and the Path to Success
DynamoDB to ScyllaDB: Technical Comparison and the Path to SuccessDynamoDB to ScyllaDB: Technical Comparison and the Path to Success
DynamoDB to ScyllaDB: Technical Comparison and the Path to Success
ScyllaDB
 
Facilitation Skills - When to Use and Why.pptx
Facilitation Skills - When to Use and Why.pptxFacilitation Skills - When to Use and Why.pptx
Facilitation Skills - When to Use and Why.pptx
Knoldus Inc.
 
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdfLee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
leebarnesutopia
 
CTO Insights: Steering a High-Stakes Database Migration
CTO Insights: Steering a High-Stakes Database MigrationCTO Insights: Steering a High-Stakes Database Migration
CTO Insights: Steering a High-Stakes Database Migration
ScyllaDB
 
Fuxnet [EN] .pdf
Fuxnet [EN]                                   .pdfFuxnet [EN]                                   .pdf
Fuxnet [EN] .pdf
Overkill Security
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
Enterprise Knowledge
 
An All-Around Benchmark of the DBaaS Market
An All-Around Benchmark of the DBaaS MarketAn All-Around Benchmark of the DBaaS Market
An All-Around Benchmark of the DBaaS Market
ScyllaDB
 
ThousandEyes New Product Features and Release Highlights: June 2024
ThousandEyes New Product Features and Release Highlights: June 2024ThousandEyes New Product Features and Release Highlights: June 2024
ThousandEyes New Product Features and Release Highlights: June 2024
ThousandEyes
 
Introduction to ThousandEyes AMER Webinar
Introduction  to ThousandEyes AMER WebinarIntroduction  to ThousandEyes AMER Webinar
Introduction to ThousandEyes AMER Webinar
ThousandEyes
 
Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...
Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...
Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...
anilsa9823
 
Building a Semantic Layer of your Data Platform
Building a Semantic Layer of your Data PlatformBuilding a Semantic Layer of your Data Platform
Building a Semantic Layer of your Data Platform
Enterprise Knowledge
 
Elasticity vs. State? Exploring Kafka Streams Cassandra State Store
Elasticity vs. State? Exploring Kafka Streams Cassandra State StoreElasticity vs. State? Exploring Kafka Streams Cassandra State Store
Elasticity vs. State? Exploring Kafka Streams Cassandra State Store
ScyllaDB
 
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
manji sharman06
 
Radically Outperforming DynamoDB @ Digital Turbine with SADA and Google Cloud
Radically Outperforming DynamoDB @ Digital Turbine with SADA and Google CloudRadically Outperforming DynamoDB @ Digital Turbine with SADA and Google Cloud
Radically Outperforming DynamoDB @ Digital Turbine with SADA and Google Cloud
ScyllaDB
 

Recently uploaded (20)

TrustArc Webinar - Your Guide for Smooth Cross-Border Data Transfers and Glob...
TrustArc Webinar - Your Guide for Smooth Cross-Border Data Transfers and Glob...TrustArc Webinar - Your Guide for Smooth Cross-Border Data Transfers and Glob...
TrustArc Webinar - Your Guide for Smooth Cross-Border Data Transfers and Glob...
 
From NCSA to the National Research Platform
From NCSA to the National Research PlatformFrom NCSA to the National Research Platform
From NCSA to the National Research Platform
 
Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!
 
MongoDB to ScyllaDB: Technical Comparison and the Path to Success
MongoDB to ScyllaDB: Technical Comparison and the Path to SuccessMongoDB to ScyllaDB: Technical Comparison and the Path to Success
MongoDB to ScyllaDB: Technical Comparison and the Path to Success
 
New ThousandEyes Product Features and Release Highlights: June 2024
New ThousandEyes Product Features and Release Highlights: June 2024New ThousandEyes Product Features and Release Highlights: June 2024
New ThousandEyes Product Features and Release Highlights: June 2024
 
Guidelines for Effective Data Visualization
Guidelines for Effective Data VisualizationGuidelines for Effective Data Visualization
Guidelines for Effective Data Visualization
 
DynamoDB to ScyllaDB: Technical Comparison and the Path to Success
DynamoDB to ScyllaDB: Technical Comparison and the Path to SuccessDynamoDB to ScyllaDB: Technical Comparison and the Path to Success
DynamoDB to ScyllaDB: Technical Comparison and the Path to Success
 
Facilitation Skills - When to Use and Why.pptx
Facilitation Skills - When to Use and Why.pptxFacilitation Skills - When to Use and Why.pptx
Facilitation Skills - When to Use and Why.pptx
 
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdfLee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
 
CTO Insights: Steering a High-Stakes Database Migration
CTO Insights: Steering a High-Stakes Database MigrationCTO Insights: Steering a High-Stakes Database Migration
CTO Insights: Steering a High-Stakes Database Migration
 
Fuxnet [EN] .pdf
Fuxnet [EN]                                   .pdfFuxnet [EN]                                   .pdf
Fuxnet [EN] .pdf
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
 
An All-Around Benchmark of the DBaaS Market
An All-Around Benchmark of the DBaaS MarketAn All-Around Benchmark of the DBaaS Market
An All-Around Benchmark of the DBaaS Market
 
ThousandEyes New Product Features and Release Highlights: June 2024
ThousandEyes New Product Features and Release Highlights: June 2024ThousandEyes New Product Features and Release Highlights: June 2024
ThousandEyes New Product Features and Release Highlights: June 2024
 
Introduction to ThousandEyes AMER Webinar
Introduction  to ThousandEyes AMER WebinarIntroduction  to ThousandEyes AMER Webinar
Introduction to ThousandEyes AMER Webinar
 
Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...
Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...
Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...
 
Building a Semantic Layer of your Data Platform
Building a Semantic Layer of your Data PlatformBuilding a Semantic Layer of your Data Platform
Building a Semantic Layer of your Data Platform
 
Elasticity vs. State? Exploring Kafka Streams Cassandra State Store
Elasticity vs. State? Exploring Kafka Streams Cassandra State StoreElasticity vs. State? Exploring Kafka Streams Cassandra State Store
Elasticity vs. State? Exploring Kafka Streams Cassandra State Store
 
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
 
Radically Outperforming DynamoDB @ Digital Turbine with SADA and Google Cloud
Radically Outperforming DynamoDB @ Digital Turbine with SADA and Google CloudRadically Outperforming DynamoDB @ Digital Turbine with SADA and Google Cloud
Radically Outperforming DynamoDB @ Digital Turbine with SADA and Google Cloud
 

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
  翻译: