Вы можете уменьшить их до двух конструкторов, если переупорядочить аргументы и использовать varargs:
public ShortcutButton(String text, ActionListener actionListener, KeyStroke... keyStrokes) {
super(text);
addActionListener(actionListener);
addShortcuts(keyStrokes);
}
public ShortcutButton(String text, ActionListener actionListener, String... keyStrokes) {
super(text);
addActionListener(actionListener);
addShortcuts(keyStrokes);
}
и если у вас есть метод, который преобразует String[]
в KeyStroke[]
, вы можете еще больше сократитькод:
public ShortcutButton(String text, ActionListener actionListener, KeyStroke... keyStrokes) {
super(text);
addActionListener(actionListener);
addShortcuts(keyStrokes);
}
public ShortcutButton(String text, ActionListener actionListener, String... keyStrokes) {
this(text,actionListener,getShortCuts(keyStrokes));
}