HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Programming Games in J2ME"
Vol. 7, Issue 6, p. 90

	


Listing 1


javax.microedition.lcdui.*;

public class gameCanvas extends Canvas
{
    ...
    Image    backBuffer;
    Graphics    backBufferGraphics;
    ...
    public gameCanvas()
    {
        ....
 // initialize the back-buffer to be the same dimension as the canvas,
 // and get the Graphics of the buffer for off-screen drawing
        backBuffer = Image.createImage( getWidth(), getHeight() );
        backBufferGraphics = backBuffer.getGraphics();
        ....
    }
    ....
    public void paint(Graphics g)
    {
        ...
        // do all the Graphics drawing onto the back-buffer
        backBufferGraphics.draw...
        ...
        // now "flip" the back-buffer to the front 
        // by drawing the whole back-buffer image onto the screen.
        // since individual Graphics call is "double-buffered",
        // this wonÕt create any "tearing" on the screen.
        g.drawImage( backBuffer, 0, 0 Graphics.TOP|Graphics.LEFT );
    }
    ....
}


Listing 2


HttpConnection c = null;
InputStream is = null;
OutputStream os = null;
try 
{
			// open http connection
c = (HttpConnection)Connector.open( url, Connector.READ_WRITE );
			
	// Set the request method and headers
	c.setRequestMethod( HttpConnection.POST );
	c.setRequestProperty( "User-Agent" , "Profile/MIDP-1.0 Configuration/CLDC-1.0" );
	c.setRequestProperty( "Content-Language" , "en-US" );
	c.setRequestProperty( "Connection" , "close" );	
			
	// write request
	os = c.openOutputStream();			
	....		

	// get response
	is = c.openInputStream();
	...

	...
} 		
finally 
{
		try{ os.close(); }catch( Exception e ){}
		try{ is.close(); }catch( Exception e ){}
		try{ c.close(); }catch( Exception e ){}
}


Listing 3


StreamConnection connection = null;
InputStream is = null;
OutputStream os = null;
try
{	
		Connection aConnection = Connector.open( "socket://" + host
		 + ":" + port);
		connection = (StreamConnection) aConnection;
		os = connection.openOutputStream();			
		..
		is = connection.openInputStream();  
		...
}
finally
{
		try{ os.close(); }catch( Exception e ){}
		try{ is.close(); }catch( Exception e ){}
		try{ c.close(); }catch( Exception e ){}
}

 

All Rights Reserved
Copyright © 2002 SYS-CON Media
E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.