//Demonstrate Buttons 
//from Java: The Complete Reference

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
/*</applet code="ButtonDemo" width = 250 height = 150 />
*/

public class ButtonDemo extends Applet implements ActionListener
{
    String msg = "";
    Button yes, no, maybe;
    
    public void init()
    {
        // this is a workaround for a security conflict with some browsers
        // including some versions of Netscape & Internet Explorer which do 
        // not allow access to the AWT system event queue which JApplets do 
        // on startup to check access. May not be necessary with your browser. 
        //JRootPane rootPane = this.getRootPane();    
        //rootPane.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
    
        yes = new Button("YES");
        no = new Button("NO");
        maybe = new Button("MAYBE");
        
        add(yes);
        add(no);
        add(maybe);
        
        yes.addActionListener(this);
        no.addActionListener(this);
        maybe.addActionListener(this);
    }

    
    public void start() { }

    
    public void stop() { }

    
    public void paint(Graphics g)
    {
        g.drawString(msg, 6, 100);
    }

    
    public void destroy() { }

    
    public void actionPerformed (ActionEvent e) {
        String str = e.getActionCommand();
        if (str.equals("YES")) msg = "You pressed YES";
        else if (str.equals("NO")) msg = "You pressed NO";
        else if (str.equals("MAYBE")) msg = "You pressed maybe";
        else msg = "UH OH!!!";
        
        repaint();
    }
}
