composition or inheritance for a jdialog

?

-

i current have a subclass of JDialog that has only these two lines in
the constructor:

getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
DISPOSE_ACTION_KEY);
getRootPane().getActionMap().put(DISPOSE_ACTION_KEY,
new AbstractAction() {
public void actionPerformed(ActionEvent evt) {
dispose();
}
});


is it right to subclass it? or should i switch to composition?
 
J

John C. Bollinger

- said:
i current have a subclass of JDialog that has only these two lines in
the constructor:

getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
DISPOSE_ACTION_KEY);
getRootPane().getActionMap().put(DISPOSE_ACTION_KEY,
new AbstractAction() {
public void actionPerformed(ActionEvent evt) {
dispose();
}
});


is it right to subclass it? or should i switch to composition?

I try to avoid subclassing GUI components. There are sometimes good
reasons to do it, but the example you have presented does not exhibit one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top