button class
Button class:
This class is used to
create the command button, which is used to initiate the particular action.
The constructors of the Button class:
a) Button()
b) Button(String s)
Button() : This
constructor is used to create the command button with not caption on it(
caption is the information which is displayed over the command button)
Button(String s): This
constructor is used to create the command button with s as a caption on it.
Methods:
1. setLabel()This method
is used to set the information which we want to display over the command button
i.e. its caption
The general form of the method is ,
void
setLabel(String s)
where ,
s is the information
2. getLabel()This method
is used to return the string which is assigned as the caption of the Button
The general
form is,
String getLabel()
Event Handling: Events are the action performed by the user or the
system. Example of events:
a) Clicking on
the command button
b) Clicking on
the list box
c) Double
clicking on the items etc….
The package
java.awt.event.* provides the various interfaces for handling the events.
The Button class
objects generates the ActionEvent.For handling this event the java.awt.event
package provides the ActionListener interface.
PROGRAM-4
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*
<applet
code="ButtonDemo1" height=200 width=200>
</applet>
*/
public class ButtonDemo1
extends Applet implements ActionListener
{
Label l;
public
void init()
{
l=new
Label("
");
add(l);
Button
b=new Button("Show");
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
l.setText("Welcome
To AWT");
}
}
Comments
Post a Comment