Error in my code using Event Handling in Java




Asked on October 27, 2014
package programs;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public   class ButtonActionDemo extends Applet implements ActionListener{
String msg= "";
public void init(){
setSize(400, 400);
setLayout(new FlowLayout());
setVisible(true);
Button b1= new Button("yes");
Button b2= new Button("no");
Button b3= new Button("can't say");
add(b1); add(b2); add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerforme(ActionEvent ae){
String str= ae.getActionCommand(); // to retrive label on the button
if(str.equals("yes"))
{
msg= "You presse YES";
}
else if(str.equals("no"))
{
msg= "You presse NO";
}
else
{
msg= "You presse CAN'T SAY";
}
}
public void paint(Graphics g){
g.drawString(msg, 10, 200);
}
}





Write Answer











©2024 concretepage.com | Privacy Policy | Contact Us