Practical-5 Develop an applet that contains one button. Initialize the label on the button to “start”, when the user presses the button, which changes the label between these two values each time the button is pressed.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Practical5 extends Applet implements ActionListener {
Button b;
public void init() {
b=new Button("Start");
b.addActionListener(this);
add(b);
}
public void actionPerformed(ActionEvent e)
{
if(b.getLabel()=="Start")
{
b.setLabel("Stop");
}
else
{
b.setLabel("Start");
}
}
}
Output:
Comments
Post a Comment