dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Jun 22, 2005

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Managing the Form Flow in J2ME

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);		
	}
}
Alejandro Parodi
 
Thanks for your registration, follow us on our social networks to keep up-to-date