Thursday 5 January 2017

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 presses

Code:


import java.applet.Applet;
import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class ClickEvent extends Applet implements ActionListener {

    Button b;
    public void init()
    {
        b=new Button();
        b.setLabel("Start");
        b.addActionListener(this);
        add(b);
        
    }
    
    @Override
    public void actionPerformed(ActionEvent e) {
        
     
      if(b.getLabel()== "Start")
        {
          b.setLabel("Stop");
      }
      else
      {
       b.setLabel("Start");
          
      }
        
        
    }
    

}

Output:

Thanks
Happy Coding ;)


1 comment: