0% found this document useful (0 votes)
18 views10 pages

Unit02 2.3buttons

button

Uploaded by

towaxa1167
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views10 pages

Unit02 2.3buttons

button

Uploaded by

towaxa1167
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 10

Swings

By
Sangita B.Chavan
Lecturer in Computer
Technology
Govt. Polytechnic,Ahmednagar
Learning Objective
Use the given type of button in
Java based GUI.
Buttons:-
 Swing button are subclasses of the AbstractButton
class.
 AbstractButton is an abstract subclass of
JComponent.
 It includes JButton,JToggleButton such as
JCheckBox ,JRadioButton
JButton:-
 The JButton class is used to create a labeled button
that has platform independent implementation. (i.e
The JButton class creates a push button that
generates an event when it is pressed.)
 It inherits AbstractButton class.
 Commonly used Constructors:
 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.
•Jbutton(String s,Icon i): It creates a
button with the specified text and icon.

Commonly used Methods of


AbstractButton class:
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.
JCheckBox:-
The JCheckBox class is used to create a
checkbox.
JCheckBoxes are user interface component that
have two states:checked and unchecked(true
or false)which display its state to the user.
JCheckBox class has the following constructors:
JCheckBox(): Creates an initially unselected
checkbox button with no text and no icon.
JCheckBox(String s): Creates an initially
unselected check box with text.
JCheckBox(String s,boolean state): Creates
the check box with text and it specifies whether
it is initially selected or not.
JCheckBox(Icon i):Constructs an initially
unselected check box with an icon.
JCheckBox(Icon i,boolean
state) :Constructs check box with
icon and it specifies whether it was
initially selected or not.
JCheckBox(String s,Icon i) Creates
an initially unselected check box
with specified text and icon.
JCheckBox(String s,Icon I,boolean
state):Create a check box with
specified text and icon and specifies
that whether it is initially selected or
not.
JRadioButton:-
 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.
 JRadioButton class has the following constructors:
JRadioButton() :Creates an unselected radio
button with no text.
JRadioButton(String s):Creates an unselected
radio button with specified text.
JRadioButton(String s,boolean state):Creates
a radio button with the specified text and selected
status.
JRadioButton(Icon i):Creates an initially
unselected radio button with the specified icon.
JRadioButton(Icon i,boolean
state) :Creates an initially selected
button with specified image.
JRadioButton(String s,Icon
i):Creates a radion button with
specified string and specified image
that is initially unselected.
JRadioButton(String s,Icon
I,boolean state):Creates a radio
button that has specified text,
image and selection state.
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.
Summary
Use the given type of button in
Java based GUI.

You might also like