Those braces just ... don't make sense. I had to check to make sure, but basically they're only used for scoping basically they're only used for scoping. You don't need that scoping here. You could very well make a function that takes a String, creates a JButton
, sets its actionCommand
to that string, and adds this
as actionListener
to the button. Then you'd have less repeated lines too.
Those braces just ... don't make sense. I had to check to make sure, but basically they're only used for scoping. You don't need that scoping here. You could very well make a function that takes a String, creates a JButton
, sets its actionCommand
to that string, and adds this
as actionListener
to the button. Then you'd have less repeated lines too.
Those braces just ... don't make sense. I had to check to make sure, but basically they're only used for scoping. You don't need that scoping here. You could very well make a function that takes a String, creates a JButton
, sets its actionCommand
to that string, and adds this
as actionListener
to the button. Then you'd have less repeated lines too.
dialog.getContentPane().add(contentPanel, BorderLayout.CENTER);
{
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
dialog.getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton cancelButton = new JButton("Cancel");
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton);
cancelButton.addActionListener(this);
}
{
backButton = new JButton("Back");
backButton.setActionCommand("Back");
backButton.setEnabled(false);
buttonPane.add(backButton);
dialog.getRootPane().setDefaultButton(backButton);
backButton.addActionListener(this);
}
{
nextButton = new JButton("Next");
nextButton.setActionCommand("Next");
buttonPane.add(nextButton);
dialog.getRootPane().setDefaultButton(nextButton);
nextButton.addActionListener(this);
}
}
What's going on here?
Those braces just ... don't make sense. I had to check to make sure, but basically they're only used for scoping. You don't need that scoping here. You could very well make a function that takes a String, creates a JButton
, sets its actionCommand
to that string, and adds this
as actionListener
to the button. Then you'd have less repeated lines too.
Personally I feel that you should use blank lines for signaling separate "parts" of a function, and that quite possibly, each of these parts could be a separate function themselves.
if (model.canGoForward()) {
nextButton.setEnabled(true);
} else {
nextButton.setEnabled(false);
}
if (model.canGoBack()) {
backButton.setEnabled(true);
} else {
backButton.setEnabled(false);
}
If true, set true, if false, set false. Replace with set value instead:
nextButton.setEnabled(model.canGoForward());
backButton.setEnabled(model.canGoBack());
Oh, and I think model.completable()
should be model.isCompletable()
instead, to signal it returns a boolean. Function names should be actionable, if they do something, or a statement, if they test/ask something.