Wednesday, 27 July 2016

swing - KeyAdapter inner class... What exactly is Java doing here?

Whenever I need to grab input from the keyboard, I use the following KeyAdapter inner class technique.



controls = new KeyAdapter()

{
public void keyPressed(KeyEvent e)
{
//do something with input
}
};


It wasn't recently that I learned how to do this, but I am beginning to become uncomfortable, as I like to understand what is happening in my code. What exactly is Java doing here? The best I can come up with is it is a form of inner class, but why can't I write a constructor?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...