• Post Reply Bookmark Topic Watch Topic
  • New Topic

Computing Concepts with Java Essentials  RSS feed

 
Java Daisuki
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have no background in programming, starting to learn 3 months ago, studying Java as a part of university course. I do not understand the following explanation of this textbook page 411. Could anyone help me ?

Each button has a separate listener, but all four listener objects are instances of the same listener class. The complier automaticallly turns the local variables that an inner class accesses into instance fields of the inner class.

Codes :

public JButton makeButton(String label, final int dx, final int dy)
{
JButton button = new JButton(label);

class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
box.translate(dx, dy);
repaint();
}
}

I am studying for the exam at the moment, will appreciate your help.
 
Ko Wey
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at your stuff this way, may be you will understand it better:
(Compile and run)



Each button has its own listener: try it!
 
Java Daisuki
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your explanation. I will try to compile it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!