Design and implement a class called Buzzer with the followin

Design and implement a class called Buzzer with the following features (no main function). The buzzer has two buttons: green and red each of which can be configured to print a customized string. Here is a list of words that the buttons cannot be configured with: \"hate\", \"fail\" and \"dislike\". Once configured, the user can press either button and the corresponding string should be displayed. If the user presses a button before successfully configuring it, \"Configure me!\" should be displayed.

Solution

import java.awt.Button;
import java.awt.event.*;

import javax.swing.JOptionPane;

import java.applet.*;
public class Buzzer extends Applet implements ActionListener
{

   Button b1,b2;
   public void init()
   {
       b1=new Button(\"Red\");
       b2=new Button(\"Green\");
       add(b1);
       add(b2);
       b1.addActionListener(this);
       b2.addActionListener(this);
       setSize(400,400);
       setVisible(true);
   }
   public void actionPerformed(ActionEvent e)
   {
       if(e.getSource()==b1)
           JOptionPane.showMessageDialog(null, \"Configured Me\");
      
   }
  
}

 Design and implement a class called Buzzer with the following features (no main function). The buzzer has two buttons: green and red each of which can be confi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site