To manage form flow, the first thing you need to do is create a singleton class with static methods. Next, you implement a stackable system in which to store any object. The showPrevious() method exposes objects’ special data.
package tips.formstack;import java.util.Stack;public class FormFlow { private static Stack stack = new Stack(); public static void addInstance(Object instance) { stack.push(instance); } public static Object getInstance() { return stack.pop(); } public static void showPrevious() { ((Showable)FormFlow.stack.pop()).show(); }}/* * Design an interface to extract common functionality */package tips.formstack;public interface Showable { void show();}/* * Design a class that implements Showable*/package tips.formstack;public class MyShowableObject implements Showable { int index; public MyShowableObject(int index){ this.index = index; } public void show() { System.out.println("Showing "+index); }}