Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JFrame ActionListener

JFrame myframe = new JFrame("My Sample Frame");
  JButton mybutton = new JButton("Okay");

Can someone explain to me these part.

 mybutton.addActionListener(new ActionListener(){

  public void actionPerformed(ActionEvent evt){

  //Assuming that the content here will do something.

  }
like image 921
Kevin Florenz Daus Avatar asked Jun 27 '26 06:06

Kevin Florenz Daus


2 Answers

You should read this Tutorial about writing Event Listeners.

like image 78
oliholz Avatar answered Jun 28 '26 20:06

oliholz


What exactly do you not understand about the code?

The code adds an action listener to the button. The actionPerformed method of the action listener will be called when the button is clicked.

Note that an anonymous inner class is used here.

like image 41
Jesper Avatar answered Jun 28 '26 20:06

Jesper