SlideShare uma empresa Scribd logo
1 de 46
JAVA SWING
Created by Apurbo Datta
OVERVIEW:
What is Swing?
Java swing components
How to change TitleBar icon in
Java Swing
Some Java Swing Apps
What is java swing
 Java Swing is a part of Java Foundation Classes (JFC) that is
used to create window-based applications. It is built on the top
of AWT (Abstract Windowing Toolkit) API and entirely written in
java.
 Java Swing provides platform-independent and lightweight
components.
 The javax.swing package provides classes for java swing API
such as JButton, JTextField, JTextArea, JRadioButton,
JCheckbox, JMenu, JColorChooser etc.
No. Java AWT Java Swing
1)
AWT components are platform-
dependent.
Java swing components are platform-
independent.
2) AWT components are heavyweight. Swing components are lightweight.
3)
AWT doesn't support pluggable look
and feel.
Swing supports pluggable look and
feel.
4 )
AWT provides less components than
Swing.
Swing provides more powerful
components such as tables, lists,
scrollpanes, colorchooser, tabbedpane
etc.
5)
AWT doesn't follows MVC(Model View
Controller) where model represents
data, view represents presentation and
controller acts as an interface between
model and view.
Swing follows MVC.
Difference between AWT and Swing
Hierarchy of Java Swing classes
Commonly used Methods of Component class
Method Description
public void add(Component c) add a component on another component.
public void setSize(int width,int height) sets size of the component.
public void setLayout(LayoutManager m) sets the layout manager for the component.
public void setVisible(boolean b)
sets the visibility of the component. It is by
default false.
Java JButton
Declaration of JButton class.
public class JButton extends AbstractButton implements Access
ible
Constructor Description
JButton() It creates a button with no text and icon.
JButton(String s) It creates a button with the specified text.
JButton(Icon i)
It creates a button with the specified icon
object.
Commonly used Constructors of JButton:
Methods Description
void setText(String s) It is used to set specified text on button
String getText() It is used to return the text of the button.
void setEnabled(boolean b) It is used to enable or disable the button.
void setIcon(Icon b)
It is used to set the specified Icon on the
button.
Icon getIcon() It is used to get the Icon of the button.
void setMnemonic(int a) It is used to set the mnemonic on the button.
void addActionListener(ActionListener a)
It is used to add the action listener to this
object.
Commonly used Methods of AbstractButton class:
Example of Java JButton
Java JPasswordField
The object of a JPasswordField class is a text component specialized for password entry. It allows the
editing of a single line of text. It inherits JTextField class.
JPasswordField class declaration
public class JPasswordField extends JTextField
Constructor Description
JPasswordField()
Constructs a new JPasswordField, with a default
document, null starting text string, and 0 column
width.
JPasswordField(int columns)
Constructs a new empty JPasswordField with the
specified number of columns.
JPasswordField(String text)
Constructs a new JPasswordField initialized with
the specified text.
JPasswordField(String text, int columns)
Construct a new JPasswordField initialized with
Commonly used Constructors JPasswordField:
Java JPasswordField Example Java JPasswordField Example with ActionListener
The object of JLabel class is a component for placing text in a container. It is
used to display a single line of read only text. The text can be changed by an
application but a user cannot edit it directly. It inherits JComponent class.
Java JLabel
JLabel class declaration
public class JButton extends AbstractButton implements Acc
essible
Constructor Description
JLabel()
Creates a JLabel instance with no image and
with an empty string for the title.
JLabel(String s)
Creates a JLabel instance with the specified
text.
JLabel(Icon i)
Creates a JLabel instance with the specified
image.
JLabel(String s, Icon i, int
horizontalAlignment)
Creates a JLabel instance with the specified
text, image, and horizontal alignment.
Commonly used Constructors of JLabel:
Methods Description
String getText() t returns the text string that a label displays.
void setText(String text)
It defines the single line of text this
component will display.
void setHorizontalAlignment(int alignment)
It sets the alignment of the label's contents
along the X axis.
Icon getIcon()
It returns the graphic image that the label
displays.
int getHorizontalAlignment()
It returns the alignment of the label's contents
along the X axis.
Commonly used Methods of JLabel:
Java JLabel Example
Java JTextField
The object of a JTextField class is a text component that allows the editing of a
single line text. It inherits JTextComponent class.
JTextField class declaration
public class JTextField extends JTextComponent implements SwingCo
nstants
Commonly used Constructors of JTextField :
Constructor Description
JTextField() Creates a new TextField
JTextField(String text)
Creates a new TextField initialized with the
specified text.
JTextField(String text, int columns)
Creates a new TextField initialized with the
specified text and columns.
JTextField(int columns)
Creates a new empty TextField with the
specified number of columns
Commonly used Methods:
Methods Description
void addActionListener(ActionListener l)
It is used to add the specified action listener
to receive action events from this textfield.
Action getAction()
It returns the currently set Action for this
ActionEvent source, or null if no Action is set.
void setFont(Font f) It is used to set the current font.
void removeActionListener(ActionListener l)
It is used to remove the specified action
listener so that it no longer receives action
events from this textfield.
Java JTextField Example
Java JTextArea
The object of a JTextArea class is a multi line region that displays text. It allows the editing
of multiple line text. It inherits JTextComponent class
JTextArea class declaration
public class JTextArea extends JTextComponent
Constructor Description
JTextArea() Creates a text area that displays no text initially.
JTextArea(String s)
Creates a text area that displays specified text
initially.
JTextArea(int row, int column)
Creates a text area with the specified number of
rows and columns that displays no text initially.
JTextArea(String s, int row, int column)
Creates a text area with the specified number of
rows and columns that displays specified text.
Commonly used Constructors of JTextArea:
Commonly used Methods of JTextArea:
Methods Description
void setRows(int rows) It is used to set specified number of rows.
void setColumns(int cols) It is used to set specified number of columns.
void setFont(Font f) It is used to set the specified font.
void insert(String s, int position)
It is used to insert the specified text on the
specified position.
void append(String s)
It is used to append the given text to the end
of the document.
Java JTextArea Example Java JTextArea Example with
ActionListener
Java JCheckBox
The JCheckBox class is used to create a checkbox. It is used to turn an option on (true)
or off (false). Clicking on a CheckBox changes its state from "on" to "off" or from "off" to
"on ".It inherits JToggleButton class.
JCheckBox class declaration
public class JCheckBox extends JToggleButton implements Accessible
Constructor Description
JJCheckBox()
Creates an initially unselected check box
button with no text, no icon.
JChechBox(String s)
Creates an initially unselected check box with
text.
JCheckBox(String text, boolean selected)
Creates a check box with text and specifies
whether or not it is initially selected.
JCheckBox(Action a)
Creates a check box where properties are taken
from the Action supplied.
Methods Description
AccessibleContext getAccessibleContext()
It is used to get the AccessibleContext
associated with this JCheckBox.
protected String paramString()
It returns a string representation of this
JCheckBox.
Commonly used Constructors:
Commonly used Methods:
Java JCheckBox Example with ItemListeneJava JCheckBox Example
The JRadioButton class is used to create a radio button. It is used to choose one option from multiple
options. It is widely used in exam systems or quiz.
 It should be added in ButtonGroup to select one radio button only.
Java JRadioButton
JRadioButton class declaration:
public class JRadioButton extends JToggleButton implements A
ccessible
Commonly used Constructors of JRadioButton:
Constructor Description
JRadioButton()
Creates an unselected radio button with no
text.
JRadioButton(String s)
Creates an unselected radio button with
specified text.
JRadioButton(String s, boolean selected)
Creates a radio button with the specified text
and selected status.
Commonly used Methods:
Methods Description
void setText(String s) It is used to set specified text on button.
String getText() It is used to return the text of the button.
void setEnabled(boolean b) It is used to enable or disable the button.
void setIcon(Icon b)
It is used to set the specified Icon on the
button.
Icon getIcon() It is used to get the Icon of the button.
void setMnemonic(int a) It is used to set the mnemonic on the button.
void addActionListener(ActionListener a)
It is used to add the action listener to this
object.
Java JRadioButton
Example
Java JRadioButton Example with ActionListener
Java JComboBox
The object of Choice class is used to show popup menu of choices. Choice
selected by user is shown on the top of a menu. It inherits JComponent
class.
JComboBox class declaration
public class JComboBox extends JComponent implements ItemSelectable, ListDataListener, ActionListen
er, Accessible
Constructor Description
JComboBox()
Creates a JComboBox with a default data
model.
JComboBox(Object[] items)
Creates a JComboBox that contains the
elements in the specified array.
JComboBox(Vector<?> items)
Creates a JComboBox that contains the
elements in the specified Vector.
Commonly used Constructors Of JComboBox:
Methods Description
void addItem(Object anObject) It is used to add an item to the item list.
void removeItem(Object anObject) It is used to delete an item to the item list.
void removeAllItems() It is used to remove all the items from the list.
void setEditable(boolean b)
It is used to determine whether the
JComboBox is editable.
void addActionListener(ActionListener a) It is used to add the ActionListener.
void addItemListener(ItemListener i) It is used to add the ItemListener.
Commonly used Methods Of JComboBox :
Java JComboBox
Example
Java JComboBox Example with ActionListene
Java JTable
The JTable class is used to display data in tabular form. It is composed of rows and
columns.
Commonly used Constructors of JTable:
Constructor Description
JTable() Creates a table with empty cells.
JTable(Object[][] rows, Object[] columns) Creates a table with the specified data.
Java JTable Example Java JTable Example with ListSelectionListene
If you select an element in column NAME, name of the element will be
displayed on the console:
Table element selected is: Sachin
Java JList
The object of JList class represents a list of text items. The list of text items can be set
up so that the user can choose either one item or multiple items. It inherits
JComponent class.
JList class declaration
public class JList extends JComponent implements Scrollable, Accessibl
e
Commonly used Constructors of JList :
Constructor Description
JList()
Creates a JList with an empty, read-only,
model.
JList(ary[] listData)
Creates a JList that displays the elements in
the specified array.
JList(ListModel<ary> dataModel)
Creates a JList that displays elements from
the specified, non-null, model.
Commonly used Methods of JList :
Methods Description
Void
addListSelectionListener(ListSelectionListener
listener)
It is used to add a listener to the list, to be
notified each time a change to the selection
occurs.
int getSelectedIndex()
It is used to return the smallest selected cell
index.
ListModel getModel()
It is used to return the data model that holds
a list of items displayed by the JList
component.
void setListData(Object[] listData)
It is used to create a read-only ListModel from
an array of objects.
Java JList Example with ActionListenJava JList Example
Java JPanel
The JPanel is a simplest container class. It provides space in which an
application can attach any other component. It inherits the JComponents
class.
It doesn't have title bar.
JPanel class declaration
public class JPanel extends JComponent implements Accessible
Commonly used Constructors of JPanel :
Constructor Description
JPanel()
It is used to create a new JPanel with a double
buffer and a flow layout.
JPanel(boolean isDoubleBuffered)
It is used to create a new JPanel with
FlowLayout and the specified buffering
strategy.
JPanel(LayoutManager layout)
It is used to create a new JPanel with the
specified layout manager.
Java JPanel Example
Java JProgressBar
The JProgressBar class is used to display the progress of the task. It inherits
JComponent class.
JProgressBar class declaration
public class JProgressBar extends JComponent implements SwingConstants, Ac
cessible
Commonly used Constructors:
Constructor Description
JProgressBar()
It is used to create a horizontal progress bar but no
string text.
JProgressBar(int min, int max)
It is used to create a horizontal progress bar with
the specified minimum and maximum value.
JProgressBar(int orient)
It is used to create a progress bar with the
specified orientation, it can be either Vertical or
Horizontal by using SwingConstants.VERTICAL and
SwingConstants.HORIZONTAL constants.
JProgressBar(int orient, int min, int max)
It is used to create a progress bar with the
specified orientation, minimum and maximum
Commonly used Methods:
Method Description
void setStringPainted(boolean b) It is used to determine whether string should be displayed.
void setString(String s) It is used to set value to the progress string.
void setOrientation(int orientation)
It is used to set the orientation, it may be either vertical or
horizontal by using SwingConstants.VERTICAL and
SwingConstants.HORIZONTAL constants.
void setValue(int value) It is used to set the current value on the progress bar.
Java JProgressBar Example
Java JSlider
The Java JSlider class is used to create the slider. By using JSlider, a user can select a value
from a specific range.
Commonly used Constructors of JSlider class
Constructor Description
JSlider()
creates a slider with the initial value of 50 and
range of 0 to 100.
JSlider(int orientation)
creates a slider with the specified orientation
set by either JSlider.HORIZONTAL or
JSlider.VERTICAL with the range 0 to 100 and
initial value 50.
JSlider(int min, int max)
creates a horizontal slider using the given min
and max.
JSlider(int min, int max, int value)
creates a horizontal slider using the given min,
max and value.
JSlider(int orientation, int min, int max, int
value)
creates a slider using the given orientation,
min, max and value.
Commonly used Methods of JSlider class
Method Description
public void setMinorTickSpacing(int n)
is used to set the minor tick spacing to the
slider.
public void setMajorTickSpacing(int n)
is used to set the major tick spacing to the
slider.
public void setPaintTicks(boolean b)
is used to determine whether tick marks are
painted.
public void setPaintLabels(boolean b)
is used to determine whether labels are
painted.
public void setPaintTracks(boolean b) is used to determine whether track is painted.Java JSlider Example
Java JSlider Example: painting ticks
How to change TitleBar icon in Java Swing
Some Java Swing Apps
Online Exam
IP Finder
Calculator

Mais conteúdo relacionado

Mais procurados (20)

Java Swing
Java SwingJava Swing
Java Swing
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Applets
AppletsApplets
Applets
 
Java awt
Java awtJava awt
Java awt
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
Servlets
ServletsServlets
Servlets
 
Java I/O
Java I/OJava I/O
Java I/O
 
Java Thread Synchronization
Java Thread SynchronizationJava Thread Synchronization
Java Thread Synchronization
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Generics
GenericsGenerics
Generics
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
 
Swing
SwingSwing
Swing
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
 
Thread model in java
Thread model in javaThread model in java
Thread model in java
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
 
Applets in java
Applets in javaApplets in java
Applets in java
 
JAVA GUI PART I
JAVA GUI PART IJAVA GUI PART I
JAVA GUI PART I
 

Destaque

Sistema Cardio-Respiratorio
Sistema Cardio-RespiratorioSistema Cardio-Respiratorio
Sistema Cardio-RespiratorioFlavia Sanz
 
Análisis de objetivos del plan de la patria
Análisis de objetivos del plan de la patriaAnálisis de objetivos del plan de la patria
Análisis de objetivos del plan de la patriajose hernandez
 
Deseda etrada presentación final
Deseda etrada presentación finalDeseda etrada presentación final
Deseda etrada presentación finalcarlosdesedam
 
DIÁRIO OFICIAL DE ILHÉUS DO DIA 24-03-2017
DIÁRIO OFICIAL DE ILHÉUS DO DIA 24-03-2017DIÁRIO OFICIAL DE ILHÉUS DO DIA 24-03-2017
DIÁRIO OFICIAL DE ILHÉUS DO DIA 24-03-2017Guy Valerio
 
Going open at the state and district level (#goopen)
Going open at the state and district level (#goopen)Going open at the state and district level (#goopen)
Going open at the state and district level (#goopen)Jane Park
 
Digital Electronic and it application
Digital Electronic and it applicationDigital Electronic and it application
Digital Electronic and it applicationApurbo Datta
 
The European Renaissance_History Of Mathematics(Rigino)
The European Renaissance_History Of Mathematics(Rigino)The European Renaissance_History Of Mathematics(Rigino)
The European Renaissance_History Of Mathematics(Rigino)Rigino Macunay Jr.
 
تحفة الأبرار بنكت الأذكار - جلال الدين السيوطي
تحفة الأبرار بنكت الأذكار - جلال الدين السيوطيتحفة الأبرار بنكت الأذكار - جلال الدين السيوطي
تحفة الأبرار بنكت الأذكار - جلال الدين السيوطيأذكر الله يذكرك
 
Create Splash Screen with Java Step by Step
Create Splash Screen with Java Step by StepCreate Splash Screen with Java Step by Step
Create Splash Screen with Java Step by StepAbdul Rahman Sherzad
 
java swing programming
java swing programming java swing programming
java swing programming Ankit Desai
 
C programming-apurbo datta
C programming-apurbo dattaC programming-apurbo datta
C programming-apurbo dattaApurbo Datta
 
Java Swing
Java SwingJava Swing
Java SwingShraddha
 
Forms authentication
Forms authenticationForms authentication
Forms authenticationSNJ Chaudhary
 

Destaque (20)

Sistema Cardio-Respiratorio
Sistema Cardio-RespiratorioSistema Cardio-Respiratorio
Sistema Cardio-Respiratorio
 
Análisis de objetivos del plan de la patria
Análisis de objetivos del plan de la patriaAnálisis de objetivos del plan de la patria
Análisis de objetivos del plan de la patria
 
Deseda etrada presentación final
Deseda etrada presentación finalDeseda etrada presentación final
Deseda etrada presentación final
 
GRAFICAS
GRAFICASGRAFICAS
GRAFICAS
 
Industrial Analysis for the LAUSD - Health Fair
Industrial Analysis for the LAUSD - Health Fair Industrial Analysis for the LAUSD - Health Fair
Industrial Analysis for the LAUSD - Health Fair
 
DIÁRIO OFICIAL DE ILHÉUS DO DIA 24-03-2017
DIÁRIO OFICIAL DE ILHÉUS DO DIA 24-03-2017DIÁRIO OFICIAL DE ILHÉUS DO DIA 24-03-2017
DIÁRIO OFICIAL DE ILHÉUS DO DIA 24-03-2017
 
Java Swing
Java SwingJava Swing
Java Swing
 
Going open at the state and district level (#goopen)
Going open at the state and district level (#goopen)Going open at the state and district level (#goopen)
Going open at the state and district level (#goopen)
 
Java swing
Java swingJava swing
Java swing
 
Digital Electronic and it application
Digital Electronic and it applicationDigital Electronic and it application
Digital Electronic and it application
 
The European Renaissance_History Of Mathematics(Rigino)
The European Renaissance_History Of Mathematics(Rigino)The European Renaissance_History Of Mathematics(Rigino)
The European Renaissance_History Of Mathematics(Rigino)
 
تحفة الأبرار بنكت الأذكار - جلال الدين السيوطي
تحفة الأبرار بنكت الأذكار - جلال الدين السيوطيتحفة الأبرار بنكت الأذكار - جلال الدين السيوطي
تحفة الأبرار بنكت الأذكار - جلال الدين السيوطي
 
Create Splash Screen with Java Step by Step
Create Splash Screen with Java Step by StepCreate Splash Screen with Java Step by Step
Create Splash Screen with Java Step by Step
 
java swing programming
java swing programming java swing programming
java swing programming
 
C programming-apurbo datta
C programming-apurbo dattaC programming-apurbo datta
C programming-apurbo datta
 
Java Swing
Java SwingJava Swing
Java Swing
 
PyCologne
PyColognePyCologne
PyCologne
 
2310 b 11
2310 b 112310 b 11
2310 b 11
 
01 Ajax Intro
01 Ajax Intro01 Ajax Intro
01 Ajax Intro
 
Forms authentication
Forms authenticationForms authentication
Forms authentication
 

Semelhante a Java swing

Semelhante a Java swing (20)

Advanced java programming
Advanced java programmingAdvanced java programming
Advanced java programming
 
Java swing
Java swingJava swing
Java swing
 
13457272.ppt
13457272.ppt13457272.ppt
13457272.ppt
 
Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...
Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...
Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...
 
AWT New-3.pptx
AWT New-3.pptxAWT New-3.pptx
AWT New-3.pptx
 
Unit 5 java-awt (1)
Unit 5 java-awt (1)Unit 5 java-awt (1)
Unit 5 java-awt (1)
 
Z blue introduction to gui (39023299)
Z blue   introduction to gui (39023299)Z blue   introduction to gui (39023299)
Z blue introduction to gui (39023299)
 
Unit-1 awt advanced java programming
Unit-1 awt advanced java programmingUnit-1 awt advanced java programming
Unit-1 awt advanced java programming
 
Awt, Swing, Layout managers
Awt, Swing, Layout managersAwt, Swing, Layout managers
Awt, Swing, Layout managers
 
SWING USING JAVA WITH VARIOUS COMPONENTS
SWING USING  JAVA WITH VARIOUS COMPONENTSSWING USING  JAVA WITH VARIOUS COMPONENTS
SWING USING JAVA WITH VARIOUS COMPONENTS
 
Unit-2 swing and mvc architecture
Unit-2 swing and mvc architectureUnit-2 swing and mvc architecture
Unit-2 swing and mvc architecture
 
JavaYDL17
JavaYDL17JavaYDL17
JavaYDL17
 
Ajp notes-chapter-02
Ajp notes-chapter-02Ajp notes-chapter-02
Ajp notes-chapter-02
 
PDF ON JAVA - JFC CONCEPT
PDF ON JAVA - JFC CONCEPTPDF ON JAVA - JFC CONCEPT
PDF ON JAVA - JFC CONCEPT
 
tL19 awt
tL19 awttL19 awt
tL19 awt
 
CORE JAVA-2
CORE JAVA-2CORE JAVA-2
CORE JAVA-2
 
Swing
SwingSwing
Swing
 
Swing
SwingSwing
Swing
 
Jp notes
Jp notesJp notes
Jp notes
 
B.Sc. III(VI Sem) Advance Java Unit3: AWT & Event Handling
B.Sc. III(VI Sem) Advance Java Unit3: AWT & Event HandlingB.Sc. III(VI Sem) Advance Java Unit3: AWT & Event Handling
B.Sc. III(VI Sem) Advance Java Unit3: AWT & Event Handling
 

Mais de Apurbo Datta

Interpolation and-its-application
Interpolation and-its-applicationInterpolation and-its-application
Interpolation and-its-applicationApurbo Datta
 
Bioinformatrics and it's application
Bioinformatrics and it's applicationBioinformatrics and it's application
Bioinformatrics and it's applicationApurbo Datta
 
Data communication and communications technology
Data communication and communications technologyData communication and communications technology
Data communication and communications technologyApurbo Datta
 
Internet of Things(Bangladesh)
Internet of Things(Bangladesh)Internet of Things(Bangladesh)
Internet of Things(Bangladesh)Apurbo Datta
 
Algorithms In our Daily life
Algorithms In our Daily lifeAlgorithms In our Daily life
Algorithms In our Daily lifeApurbo Datta
 
How to improve Bangladeshi movie industry
How to improve Bangladeshi movie industryHow to improve Bangladeshi movie industry
How to improve Bangladeshi movie industryApurbo Datta
 
High study in abroad(indian subcontinent countries)
High  study in abroad(indian subcontinent countries)High  study in abroad(indian subcontinent countries)
High study in abroad(indian subcontinent countries)Apurbo Datta
 
ROBOTICS Apurbo datta
ROBOTICS Apurbo dattaROBOTICS Apurbo datta
ROBOTICS Apurbo dattaApurbo Datta
 

Mais de Apurbo Datta (10)

Interpolation and-its-application
Interpolation and-its-applicationInterpolation and-its-application
Interpolation and-its-application
 
Bioinformatrics and it's application
Bioinformatrics and it's applicationBioinformatrics and it's application
Bioinformatrics and it's application
 
Data communication and communications technology
Data communication and communications technologyData communication and communications technology
Data communication and communications technology
 
Genetic Disorder
Genetic DisorderGenetic Disorder
Genetic Disorder
 
Internet of Things(Bangladesh)
Internet of Things(Bangladesh)Internet of Things(Bangladesh)
Internet of Things(Bangladesh)
 
Algorithms In our Daily life
Algorithms In our Daily lifeAlgorithms In our Daily life
Algorithms In our Daily life
 
How to improve Bangladeshi movie industry
How to improve Bangladeshi movie industryHow to improve Bangladeshi movie industry
How to improve Bangladeshi movie industry
 
High study in abroad(indian subcontinent countries)
High  study in abroad(indian subcontinent countries)High  study in abroad(indian subcontinent countries)
High study in abroad(indian subcontinent countries)
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
ROBOTICS Apurbo datta
ROBOTICS Apurbo dattaROBOTICS Apurbo datta
ROBOTICS Apurbo datta
 

Último

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 

Último (20)

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 

Java swing

  • 1. JAVA SWING Created by Apurbo Datta
  • 2. OVERVIEW: What is Swing? Java swing components How to change TitleBar icon in Java Swing Some Java Swing Apps
  • 3. What is java swing  Java Swing is a part of Java Foundation Classes (JFC) that is used to create window-based applications. It is built on the top of AWT (Abstract Windowing Toolkit) API and entirely written in java.  Java Swing provides platform-independent and lightweight components.  The javax.swing package provides classes for java swing API such as JButton, JTextField, JTextArea, JRadioButton, JCheckbox, JMenu, JColorChooser etc.
  • 4. No. Java AWT Java Swing 1) AWT components are platform- dependent. Java swing components are platform- independent. 2) AWT components are heavyweight. Swing components are lightweight. 3) AWT doesn't support pluggable look and feel. Swing supports pluggable look and feel. 4 ) AWT provides less components than Swing. Swing provides more powerful components such as tables, lists, scrollpanes, colorchooser, tabbedpane etc. 5) AWT doesn't follows MVC(Model View Controller) where model represents data, view represents presentation and controller acts as an interface between model and view. Swing follows MVC. Difference between AWT and Swing
  • 5. Hierarchy of Java Swing classes
  • 6. Commonly used Methods of Component class Method Description public void add(Component c) add a component on another component. public void setSize(int width,int height) sets size of the component. public void setLayout(LayoutManager m) sets the layout manager for the component. public void setVisible(boolean b) sets the visibility of the component. It is by default false.
  • 7. Java JButton Declaration of JButton class. public class JButton extends AbstractButton implements Access ible Constructor Description JButton() It creates a button with no text and icon. JButton(String s) It creates a button with the specified text. JButton(Icon i) It creates a button with the specified icon object. Commonly used Constructors of JButton:
  • 8. Methods Description void setText(String s) It is used to set specified text on button String getText() It is used to return the text of the button. void setEnabled(boolean b) It is used to enable or disable the button. void setIcon(Icon b) It is used to set the specified Icon on the button. Icon getIcon() It is used to get the Icon of the button. void setMnemonic(int a) It is used to set the mnemonic on the button. void addActionListener(ActionListener a) It is used to add the action listener to this object. Commonly used Methods of AbstractButton class:
  • 9. Example of Java JButton
  • 10. Java JPasswordField The object of a JPasswordField class is a text component specialized for password entry. It allows the editing of a single line of text. It inherits JTextField class. JPasswordField class declaration public class JPasswordField extends JTextField Constructor Description JPasswordField() Constructs a new JPasswordField, with a default document, null starting text string, and 0 column width. JPasswordField(int columns) Constructs a new empty JPasswordField with the specified number of columns. JPasswordField(String text) Constructs a new JPasswordField initialized with the specified text. JPasswordField(String text, int columns) Construct a new JPasswordField initialized with Commonly used Constructors JPasswordField:
  • 11. Java JPasswordField Example Java JPasswordField Example with ActionListener
  • 12. The object of JLabel class is a component for placing text in a container. It is used to display a single line of read only text. The text can be changed by an application but a user cannot edit it directly. It inherits JComponent class. Java JLabel JLabel class declaration public class JButton extends AbstractButton implements Acc essible
  • 13. Constructor Description JLabel() Creates a JLabel instance with no image and with an empty string for the title. JLabel(String s) Creates a JLabel instance with the specified text. JLabel(Icon i) Creates a JLabel instance with the specified image. JLabel(String s, Icon i, int horizontalAlignment) Creates a JLabel instance with the specified text, image, and horizontal alignment. Commonly used Constructors of JLabel:
  • 14. Methods Description String getText() t returns the text string that a label displays. void setText(String text) It defines the single line of text this component will display. void setHorizontalAlignment(int alignment) It sets the alignment of the label's contents along the X axis. Icon getIcon() It returns the graphic image that the label displays. int getHorizontalAlignment() It returns the alignment of the label's contents along the X axis. Commonly used Methods of JLabel:
  • 16. Java JTextField The object of a JTextField class is a text component that allows the editing of a single line text. It inherits JTextComponent class. JTextField class declaration public class JTextField extends JTextComponent implements SwingCo nstants
  • 17. Commonly used Constructors of JTextField : Constructor Description JTextField() Creates a new TextField JTextField(String text) Creates a new TextField initialized with the specified text. JTextField(String text, int columns) Creates a new TextField initialized with the specified text and columns. JTextField(int columns) Creates a new empty TextField with the specified number of columns
  • 18. Commonly used Methods: Methods Description void addActionListener(ActionListener l) It is used to add the specified action listener to receive action events from this textfield. Action getAction() It returns the currently set Action for this ActionEvent source, or null if no Action is set. void setFont(Font f) It is used to set the current font. void removeActionListener(ActionListener l) It is used to remove the specified action listener so that it no longer receives action events from this textfield.
  • 20. Java JTextArea The object of a JTextArea class is a multi line region that displays text. It allows the editing of multiple line text. It inherits JTextComponent class JTextArea class declaration public class JTextArea extends JTextComponent Constructor Description JTextArea() Creates a text area that displays no text initially. JTextArea(String s) Creates a text area that displays specified text initially. JTextArea(int row, int column) Creates a text area with the specified number of rows and columns that displays no text initially. JTextArea(String s, int row, int column) Creates a text area with the specified number of rows and columns that displays specified text. Commonly used Constructors of JTextArea:
  • 21. Commonly used Methods of JTextArea: Methods Description void setRows(int rows) It is used to set specified number of rows. void setColumns(int cols) It is used to set specified number of columns. void setFont(Font f) It is used to set the specified font. void insert(String s, int position) It is used to insert the specified text on the specified position. void append(String s) It is used to append the given text to the end of the document.
  • 22. Java JTextArea Example Java JTextArea Example with ActionListener
  • 23. Java JCheckBox The JCheckBox class is used to create a checkbox. It is used to turn an option on (true) or off (false). Clicking on a CheckBox changes its state from "on" to "off" or from "off" to "on ".It inherits JToggleButton class. JCheckBox class declaration public class JCheckBox extends JToggleButton implements Accessible
  • 24. Constructor Description JJCheckBox() Creates an initially unselected check box button with no text, no icon. JChechBox(String s) Creates an initially unselected check box with text. JCheckBox(String text, boolean selected) Creates a check box with text and specifies whether or not it is initially selected. JCheckBox(Action a) Creates a check box where properties are taken from the Action supplied. Methods Description AccessibleContext getAccessibleContext() It is used to get the AccessibleContext associated with this JCheckBox. protected String paramString() It returns a string representation of this JCheckBox. Commonly used Constructors: Commonly used Methods:
  • 25. Java JCheckBox Example with ItemListeneJava JCheckBox Example
  • 26. The JRadioButton class is used to create a radio button. It is used to choose one option from multiple options. It is widely used in exam systems or quiz.  It should be added in ButtonGroup to select one radio button only. Java JRadioButton JRadioButton class declaration: public class JRadioButton extends JToggleButton implements A ccessible Commonly used Constructors of JRadioButton: Constructor Description JRadioButton() Creates an unselected radio button with no text. JRadioButton(String s) Creates an unselected radio button with specified text. JRadioButton(String s, boolean selected) Creates a radio button with the specified text and selected status.
  • 27. Commonly used Methods: Methods Description void setText(String s) It is used to set specified text on button. String getText() It is used to return the text of the button. void setEnabled(boolean b) It is used to enable or disable the button. void setIcon(Icon b) It is used to set the specified Icon on the button. Icon getIcon() It is used to get the Icon of the button. void setMnemonic(int a) It is used to set the mnemonic on the button. void addActionListener(ActionListener a) It is used to add the action listener to this object.
  • 28. Java JRadioButton Example Java JRadioButton Example with ActionListener
  • 29. Java JComboBox The object of Choice class is used to show popup menu of choices. Choice selected by user is shown on the top of a menu. It inherits JComponent class. JComboBox class declaration public class JComboBox extends JComponent implements ItemSelectable, ListDataListener, ActionListen er, Accessible Constructor Description JComboBox() Creates a JComboBox with a default data model. JComboBox(Object[] items) Creates a JComboBox that contains the elements in the specified array. JComboBox(Vector<?> items) Creates a JComboBox that contains the elements in the specified Vector. Commonly used Constructors Of JComboBox:
  • 30. Methods Description void addItem(Object anObject) It is used to add an item to the item list. void removeItem(Object anObject) It is used to delete an item to the item list. void removeAllItems() It is used to remove all the items from the list. void setEditable(boolean b) It is used to determine whether the JComboBox is editable. void addActionListener(ActionListener a) It is used to add the ActionListener. void addItemListener(ItemListener i) It is used to add the ItemListener. Commonly used Methods Of JComboBox :
  • 31. Java JComboBox Example Java JComboBox Example with ActionListene
  • 32. Java JTable The JTable class is used to display data in tabular form. It is composed of rows and columns. Commonly used Constructors of JTable: Constructor Description JTable() Creates a table with empty cells. JTable(Object[][] rows, Object[] columns) Creates a table with the specified data.
  • 33. Java JTable Example Java JTable Example with ListSelectionListene If you select an element in column NAME, name of the element will be displayed on the console: Table element selected is: Sachin
  • 34. Java JList The object of JList class represents a list of text items. The list of text items can be set up so that the user can choose either one item or multiple items. It inherits JComponent class. JList class declaration public class JList extends JComponent implements Scrollable, Accessibl e Commonly used Constructors of JList : Constructor Description JList() Creates a JList with an empty, read-only, model. JList(ary[] listData) Creates a JList that displays the elements in the specified array. JList(ListModel<ary> dataModel) Creates a JList that displays elements from the specified, non-null, model.
  • 35. Commonly used Methods of JList : Methods Description Void addListSelectionListener(ListSelectionListener listener) It is used to add a listener to the list, to be notified each time a change to the selection occurs. int getSelectedIndex() It is used to return the smallest selected cell index. ListModel getModel() It is used to return the data model that holds a list of items displayed by the JList component. void setListData(Object[] listData) It is used to create a read-only ListModel from an array of objects.
  • 36. Java JList Example with ActionListenJava JList Example
  • 37. Java JPanel The JPanel is a simplest container class. It provides space in which an application can attach any other component. It inherits the JComponents class. It doesn't have title bar. JPanel class declaration public class JPanel extends JComponent implements Accessible
  • 38. Commonly used Constructors of JPanel : Constructor Description JPanel() It is used to create a new JPanel with a double buffer and a flow layout. JPanel(boolean isDoubleBuffered) It is used to create a new JPanel with FlowLayout and the specified buffering strategy. JPanel(LayoutManager layout) It is used to create a new JPanel with the specified layout manager. Java JPanel Example
  • 39. Java JProgressBar The JProgressBar class is used to display the progress of the task. It inherits JComponent class. JProgressBar class declaration public class JProgressBar extends JComponent implements SwingConstants, Ac cessible Commonly used Constructors: Constructor Description JProgressBar() It is used to create a horizontal progress bar but no string text. JProgressBar(int min, int max) It is used to create a horizontal progress bar with the specified minimum and maximum value. JProgressBar(int orient) It is used to create a progress bar with the specified orientation, it can be either Vertical or Horizontal by using SwingConstants.VERTICAL and SwingConstants.HORIZONTAL constants. JProgressBar(int orient, int min, int max) It is used to create a progress bar with the specified orientation, minimum and maximum
  • 40. Commonly used Methods: Method Description void setStringPainted(boolean b) It is used to determine whether string should be displayed. void setString(String s) It is used to set value to the progress string. void setOrientation(int orientation) It is used to set the orientation, it may be either vertical or horizontal by using SwingConstants.VERTICAL and SwingConstants.HORIZONTAL constants. void setValue(int value) It is used to set the current value on the progress bar. Java JProgressBar Example
  • 41. Java JSlider The Java JSlider class is used to create the slider. By using JSlider, a user can select a value from a specific range. Commonly used Constructors of JSlider class Constructor Description JSlider() creates a slider with the initial value of 50 and range of 0 to 100. JSlider(int orientation) creates a slider with the specified orientation set by either JSlider.HORIZONTAL or JSlider.VERTICAL with the range 0 to 100 and initial value 50. JSlider(int min, int max) creates a horizontal slider using the given min and max. JSlider(int min, int max, int value) creates a horizontal slider using the given min, max and value. JSlider(int orientation, int min, int max, int value) creates a slider using the given orientation, min, max and value.
  • 42. Commonly used Methods of JSlider class Method Description public void setMinorTickSpacing(int n) is used to set the minor tick spacing to the slider. public void setMajorTickSpacing(int n) is used to set the major tick spacing to the slider. public void setPaintTicks(boolean b) is used to determine whether tick marks are painted. public void setPaintLabels(boolean b) is used to determine whether labels are painted. public void setPaintTracks(boolean b) is used to determine whether track is painted.Java JSlider Example Java JSlider Example: painting ticks
  • 43. How to change TitleBar icon in Java Swing
  • 44.
  • 45. Some Java Swing Apps Online Exam

Notas do Editor

  1. NOTE: To change the image on this slide, select the picture and delete it. Then click the Pictures icon in the placeholder to insert your own image.