Writing the "cat42" catalog.

POWER JAVA
Java on the Palm Pilot

Gernot Starke
Listing 2. Writing the "cat42" catalog.


// save current status.
public void saveState(){
	Catalog catalog = new Catalog( "cat42", Catalog.CREATE);
	if(!catalog.isOpen()){
	    return;
	}

	catalog.setRecordPos(0);

	byte[] b=new byte[RECSIZE ];

	// now fill array b with game status
	b = getGameStatus();

	catalog.writeBytes(b,0, RECSIZE );
	catalog.close();
}

// load current status
public void loadState(){
	Catalog catalog = new Catalog( "cat42", Catalog.READ_ONLY);
	if( !catalog.isOpen() ||
	catalog.getRecordCount()==0 || !catalog.setRecordPos(0)){
	    return;
	}

	byte[] b=new byte[ RECSIZE ];
	// read game status from catalog
	catalog.readBytes(b,0, RECSIZE);
	
	// initialize game status 
	initGame( b );

	catalog.close();
}

Featured

Upcoming Events

AppTrends

Sign up for our newsletter.

I agree to this site's Privacy Policy.