JButton updBt = new JButton("My Button");
updBt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Call method or do what you want here
}
});
> > JButton updBt = new JButton("My Button");
> updBt.addActionListener(new ActionListener() {
>public void actionPerformed(ActionEvent e) {
>// Call method or do what you want here
> }
> });
>
// Call method or do what you want here:
if (ae.getActionCommand().equals(My Button))
I want to get the code after this. I am trying to get the code for the last hours and was not able to get hope some one will helo me.
Thanks
try this but u have to implement the ActionListener after that it will work
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Test extends JFrame implements ActionListener{
public JButton testBtn ;
public Test(){
testBtn = new JButton("Test");
testBtn.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
String command = e.getActionCommand();
if(command.equals("Test")){
System.out.println("Hello im pressed");
}
}
}
and what ever u do in actionperformed function u like by pressing it and calling that function
null