Is There A or Is There A? This is a question to ask when considering extending a class. If the new class is "Is A", the extended frame, but if the class just needs a frame reference, do not expand .
In fact, if a custom component is required , extend the JComponent or JPanel , then add it to the frame, .. applet, window, JInternalFrame , dialog, layout constraint, part of the split panel.
Listeners
As for the listeners. Instead of traversing the huge if / else structure in one actionPerformed() method to determine the desired action, this is more optimal for:
- Create a listener for each control that needs it.
- Create an instance of
AbstractAction that can be used for several controls (copy button, menu item, etc.).
Summary
So (usually) for:
JFrame not distributed.- Listeners, create and add as needed.
source share