Code:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class ActionButton extends Applet implements ActionListener
{
String msg="";
Button bt1,bt2,bt3;
public void init()
{
Button bt1 = new Button("YES");
Button bt2 = new Button("NO");
Button bt3 = new Button("MAY BE...");
add(bt1);
add(bt2);
add(bt3);
bt1.addActionListener(this);
bt2.addActionListener(this);
bt3.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
if(str.equals("YES"))
{
msg="you pressed YES button...";
setBackground(Color.red);
}
else if(str.equals("NO"))
{
msg="you have pressed NO button...";
setBackground(Color.blue);
}
else
{
msg="you are undecided and pressed May be button.....";
setBackground(Color.yellow);
}
}
public void paint(Graphics g)
{
g.drawString(msg,50,50);
}
}
/*
<applet code="ActionButton" height=400 width=300 >
</applet>
*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class ActionButton extends Applet implements ActionListener
{
String msg="";
Button bt1,bt2,bt3;
public void init()
{
Button bt1 = new Button("YES");
Button bt2 = new Button("NO");
Button bt3 = new Button("MAY BE...");
add(bt1);
add(bt2);
add(bt3);
bt1.addActionListener(this);
bt2.addActionListener(this);
bt3.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
if(str.equals("YES"))
{
msg="you pressed YES button...";
setBackground(Color.red);
}
else if(str.equals("NO"))
{
msg="you have pressed NO button...";
setBackground(Color.blue);
}
else
{
msg="you are undecided and pressed May be button.....";
setBackground(Color.yellow);
}
}
public void paint(Graphics g)
{
g.drawString(msg,50,50);
}
}
/*
<applet code="ActionButton" height=400 width=300 >
</applet>
*/