Button, Choice class in java.awt package: Types of constructors, Methods

Button class: Button class in java.awt package is used to wrap push button. A push button has a label and a button. Button class is a sub class of Component class.

Types of constructors defined by Button class:

Type-1: To create an empty button.

Button( )

Type-2: To create a button with string.

Button(String str)

Types of methods defined by Button class:

setLabel( ) method: It is used to set a label.


void setLabel(String str)

getLabel( ) method: It is used to get a label.

String getLabel( )

Choice class: Choice class creates choice pop up lists from which users can select. There is a left justified label with every choice.

Methods defined by Choice class:

add( ) method: It is used to add a selection to list.


void add(String str)

getSelectedItem( ) method: It is used to obtain selected item.


String getSelectedItem( )

getSelectedIndex( ) method: It is used to obtain index of item.


int getSelectedIndex( )

getItemCount( ) method: It is used to get the number of items in list.


int getItemCount( )

select( ) method: It is used to set the current selected item.


By using an index:

void select(int index)

By matching a string:

void select(String str)

getItem( ) method: It is used to find an item by its index.


String getItem(int index)

Leave a Reply