import java.awt.*;
import java.awt.event.*;
class MyButton extends Frame implements ActionListener
{
private Button btn_yes,btn_no;
public MyButton()
{
btn_yes=new Button("Yes");
btn_no=new Button("No");
FlowLayout f=new FlowLayout();
setLayout(f);
add(btn_yes);
add(btn_no);
setTitle("Button Demo");
setSize(400,400);
setLocation(100,100);
btn_yes.addActionListener(this);
btn_no.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String btn=ae.getActionCommand();
if(btn.equals("Yes"))
System.out.println("Yes Button is Clicked");
else
System.out.println("No Button is Clicked");
}
}
class ButtonDemo
{
public static void main(String args[])
{
new MyButton().setVisible(true);
}
}
No comments:
Post a Comment