I have reached the last stages of my app. I am designing the practice Form. On the Form I have identified the exercise to use in practice, and have added a button to the practice Form with the name of the exercise on it. I have the button open the viewing class (dirReplay class, derived from the Replay class) using the name of the exercise to build the Field Form, retrieve the player location from the database and place the players to run the play. When the play is finished, I want to return to the practice Form in the Plan class to continue the practice, jumping back to the Field class as I follow the plan to display the additional plays as outlined in the practice plan on the Form.
I have 2 methods in dirReplay class, dirReplay which builds the glass pane and field, and the placePlayers() method that moves the players on the field. When I get to the last record in the database, normal use of the Replay class closes the cursor and database and shows a "Finished" screen.
I use databases in the app to move data between classes, but dirReplay is an action Form, not a data Form.
After the dirReplay method builds the field, placePlayers() starts by opening the database.
public boolean placePlayers() throws IOException {
db = Display.getInstance().openOrCreate("pandr.db");
String rd = "SELECT * FROM pandr WHERE name ='" + namet + "'";
cur = db.executeQuery(rd);
Row currentRow = cur.getRow();
cc = currentRow.getInteger(3);
x = cc+1;
for (
Button rt = new Button("Return");
for (r = 1; r < x; r++) {
.
.Place images on field, delete images, place images in new location
.
if ( last record
.
.Place images in last location
.
monitor.animateLayoutAndWait(1800);
db.close();
cur.close();
// new FinishBanner();
return(true);
rt.addActionListener(rtn -> {
try {
current.showBack();
} catch (IOException ex) {
throw new RuntimeException(ex);
});
}
}
}
}
I define the current Form in the calling class. showBack() and current.showBack() both give an "cannot find symbol" error when I try to use them.
Has anyone had success going back to the previous class Form in your app?
If current
is defined in a different class this won't work. When creating the new Form
you need to pass the current Form
and store it in a variable so you can go back in the form stack e.g.:
Form destinationForm = new DestinationForm(current);
Then in DestinationForm
:
private Form previous;
public DestinationForm(Form previous)
this.previous = previous;
}
public void goBack() {
previous.showBack();
}