Quoting from a commentary on teaching GUIs:
“Although inheritance is very important to understand, it isn't used that often. One of the few places where it is used to great advantage is in GUIs. The GUI system can and should be used as a real, not contrived, example of inheritance.”
There are several kinds of listeners in Java, depending on what the user does, but the most common is called an action listener, which is used with buttons, menu items, etc.
convertBtn.addActionListener(new ConvertBtnListener());
class ConvertBtnListener implements ActionListener
The
actionPerformed method in this class must be able to get and set the values in the text fields or other input and output areas of the
GUI.
A simple, common solution is to define this listener class inside the JFrame subclass.
Any method inside an inner class can refer to instance variables in the outer class.