This isn't a constructor:
public Void AddCstmrForm(Runnable myFunc) throws Exception {
initComponents();
...
}
It's a method called AddCstmrForm
with a Void
return type.
I think you meant:
public AddCstmrForm(Runnable myFunc) throws Exception {
initComponents();
...
}
You also need to create a Runnable
to call your LockOrUnlockButtons
method. For example:
AddCstmrForm addCstmr = new AddCstmrForm(new Runnable() {
@Override public void run() {
LockOrUnlockButtons();
}
});
Unless you're using Java 8, in which case you could write:
AddCstmrForm addCstmr = new AddCstmrForm(this::LockOrUnlockButtons);
Additionally, your LockOrUnlockButtons
can be simplified significantly:
private void LockOrUnlockButtons() throws Exception {
boolean anyCustomers = !sngltn.GetAllCustemers().isEmpty();
buttonUpdateAddActivityCstmrCrd.setEnabled(anyCustomers);
buttonDeleteCstmrCrd.setEnabled(anyCustomers);
buttonQueriesViewData.setEnabled(anyCustomers);
}
(I'd also strongly advise you to follow Java naming conventions, use a return type of void
rather than Void
unless you really need to, and avoid throws Exception
. You should revisit your exception handling approach in general, by the looks of things.)