<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8090004115078610550</id><updated>2012-02-16T20:28:12.466-08:00</updated><category term='Detection'/><category term='programming paradigms'/><category term='Game'/><category term='jar file'/><category term='querystring'/><category term='applet'/><category term='Flicker'/><category term='weka basic tutorial'/><category term='Host Name'/><category term='Push-Relabel'/><category term='sql script'/><category term='Web'/><category term='c#'/><category term='word2html'/><category term='artificial Intelligence'/><category term='Design Document'/><category term='css'/><category term='AI'/><category term='doc2html'/><category term='backpropagation'/><category term='transistor'/><category term='neural network weka'/><category term='pringles'/><category term='interactivity'/><category term='Manifest'/><category term='Collision'/><category term='notes'/><category term='global.asax'/><category term='linq'/><category term='query string'/><category term='Prim-Jarnik'/><category term='security'/><category term='default.aspx'/><category term='insertion sort'/><category term='Sprites'/><category term='Tile Based'/><category term='Story Boarding'/><category term='bubble sort'/><category term='Boyer-Moore'/><category term='IP Mapping'/><category term='Relabel-to-front'/><category term='Map'/><category term='sql 2005'/><category term='Knuth-Morris-Pratt'/><category term='Prim&apos;s'/><category term='md2'/><category term='BLUEJ'/><category term='Johnsons'/><category term='CMS'/><category term='asp.net'/><category term='asp.net security'/><category term='content management system'/><category term='merge sort'/><category term='shell sort'/><category term='sql vr'/><category term='basic weka'/><category term='JAVA'/><category term='weka'/><category term='decrypt'/><category term='Simple Screen Manager'/><category term='heap sort'/><category term='blender'/><category term='scipting language'/><category term='weka commandline'/><category term='export'/><category term='template'/><category term='Automatic'/><category term='triggers'/><category term='weka tutorial'/><category term='Rabin-Karp'/><category term='Baruvka&apos;s'/><category term='encrypt'/><category term='delete'/><category term='2D graphics'/><category term='Buffering'/><category term='python'/><category term='Floyd-Warshall'/><category term='user interface'/><category term='class'/><category term='encrypt/decrypt'/><category term='capacitor'/><category term='sql 2000'/><category term='SSL'/><category term='IIS6'/><category term='Animation'/><category term='Object'/><category term='weka gui'/><category term='Website'/><category term='robotics'/><category term='relay'/><category term='Java Threads'/><category term='Strassen&apos;s'/><category term='webconfig'/><category term='Bellman-Ford'/><category term='version'/><category term='Dijkstra&apos;s'/><category term='httpmodules'/><category term='Kruskal&apos;s'/><category term='JAR'/><category term='electronics'/><category term='resistor'/><category term='quick sort'/><category term='sql'/><category term='hacks'/><category term='neural network'/><category term='convert word to html'/><category term='source code'/><category term='cool ad'/><category term='selection sort'/><category term='Ford-Fulkerson'/><title type='text'>Content on a need to know basis for Computer Science Students</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>42</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-1652021984205142753</id><published>2011-10-08T01:10:00.000-07:00</published><updated>2011-11-01T00:13:33.617-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='delete'/><category scheme='http://www.blogger.com/atom/ns#' term='triggers'/><title type='text'>Delete All Triggers (Sql Server 2008)</title><content type='html'>DECLARE @SqlCmd VARCHAR(8000)&lt;br /&gt;declare @Trig sysname&lt;br /&gt;declare @owner sysname&lt;br /&gt;declare @uid int&lt;br /&gt;&lt;br /&gt;DECLARE TGCursor CURSOR FOR&lt;br /&gt;SELECT name, uid FROM sysobjects WHERE type = 'TR'&lt;br /&gt;OPEN TGCursor&lt;br /&gt;FETCH next FROM TGCursor INTO @Trig, @uid&lt;br /&gt;WHILE @@FETCH_STATUS = 0&lt;br /&gt;BEGIN&lt;br /&gt;&lt;br /&gt;select @SQLCmd = 'drop trigger [' + @Trig + ']'&lt;br /&gt;&lt;br /&gt;exec (@SqlCmd)&lt;br /&gt;&lt;br /&gt;FETCH next FROM TGCursor INTO @Trig, @uid&lt;br /&gt;END&lt;br /&gt;CLOSE TGCursor&lt;br /&gt;DEALLOCATE TGCursor&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-1652021984205142753?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/1652021984205142753/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2011/10/opencv-231-installation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/1652021984205142753'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/1652021984205142753'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2011/10/opencv-231-installation.html' title='Delete All Triggers (Sql Server 2008)'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-1512124063194197100</id><published>2011-10-07T01:13:00.001-07:00</published><updated>2011-10-07T01:13:12.422-07:00</updated><title type='text'>Delete all stored procedures</title><content type='html'>declare @procName sysname&lt;br /&gt;&lt;br /&gt;declare someCursor cursor for&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select name from sysobjects where type = 'P' and objectproperty(id, 'IsMSShipped') = 0&lt;br /&gt;&lt;br /&gt;open someCursor&lt;br /&gt;fetch next from someCursor into @procName&lt;br /&gt;while @@FETCH_STATUS = 0&lt;br /&gt;begin&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; exec('drop proc ' + @procName)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fetch next from someCursor into @procName&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;close someCursor&lt;br /&gt;deallocate someCursor&lt;br /&gt;go&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-1512124063194197100?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/1512124063194197100/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2011/10/delete-all-stored-procedures.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/1512124063194197100'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/1512124063194197100'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2011/10/delete-all-stored-procedures.html' title='Delete all stored procedures'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-9009338860482870808</id><published>2011-10-07T01:12:00.001-07:00</published><updated>2011-10-07T01:12:52.245-07:00</updated><title type='text'>Generate Audit Table for every database</title><content type='html'>-- ALL COLUMN TYPES SHOULD HAVE A NUMBER&lt;br /&gt;-- DO NOT USE FOR VARIABLE TYPES OF TYPE "MAX"&lt;br /&gt;--&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- #########################################################&lt;br /&gt;&lt;br /&gt;-- ##########################################################&lt;br /&gt;/* SET CONFIG VARIABLES THAT ARE USED IN SCRIPT */&lt;br /&gt;-- ##########################################################&lt;br /&gt;&lt;br /&gt;-- Do we want to generate the SP definitions for every user defined&lt;br /&gt;-- table in the database or just a single specified table?&lt;br /&gt;-- Assign a blank string - '' for all tables or the table name for&lt;br /&gt;-- a single table.&lt;br /&gt;DECLARE @GenerateProcsFor varchar(100)&lt;br /&gt;--SET @GenerateProcsFor = 'Orders'&lt;br /&gt;SET @GenerateProcsFor = ''&lt;br /&gt;&lt;br /&gt;-- which database do we want to create the procs for?&lt;br /&gt;-- Change both the USE and SET lines below to set the datbase name&lt;br /&gt;-- to the required database.&lt;br /&gt;USE RMS_ORIGINAL&lt;br /&gt;DECLARE @DatabaseName varchar(100)&lt;br /&gt;SET @DatabaseName = 'RMS_ORIGINAL'&lt;br /&gt;&lt;br /&gt;-- do we want the script to print out the CREATE PROC statements&lt;br /&gt;-- or do we want to execute them to actually create the procs?&lt;br /&gt;-- Assign a value of either 'Print' or 'Execute'&lt;br /&gt;DECLARE @PrintOrExecute varchar(10)&lt;br /&gt;SET @PrintOrExecute = 'Execute'&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- Is there a table name prefix i.e. 'tbl_' which we don't want&lt;br /&gt;-- to include in our stored proc names?&lt;br /&gt;DECLARE @TablePrefix varchar(10)&lt;br /&gt;SET @TablePrefix = ''&lt;br /&gt;&lt;br /&gt;-- For our '_lst' and '_sel' procedures do we want to&lt;br /&gt;-- do SELECT * or SELECT [ColumnName,]...&lt;br /&gt;-- Assign a value of either 1 or 0&lt;br /&gt;DECLARE @UseSelectWildCard bit&lt;br /&gt;SET @UseSelectWildCard = 0&lt;br /&gt;&lt;br /&gt;-- ##########################################################&lt;br /&gt;/* END SETTING OF CONFIG VARIABLE&lt;br /&gt;-- do not edit below this line */&lt;br /&gt;-- ##########################################################&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- DECLARE CURSOR containing all columns from user defined tables&lt;br /&gt;-- in the database&lt;br /&gt;DECLARE TableCol Cursor FOR&lt;br /&gt;SELECT c.TABLE_SCHEMA, c.TABLE_NAME, c.COLUMN_NAME, c.DATA_TYPE, c.CHARACTER_MAXIMUM_LENGTH&lt;br /&gt;FROM INFORMATION_SCHEMA.Columns c INNER JOIN&lt;br /&gt;INFORMATION_SCHEMA.Tables t ON c.TABLE_NAME = t.TABLE_NAME&lt;br /&gt;WHERE t.Table_Catalog = @DatabaseName&lt;br /&gt;AND t.TABLE_TYPE = 'BASE TABLE'&lt;br /&gt;ORDER BY c.TABLE_NAME, c.ORDINAL_POSITION&lt;br /&gt;&lt;br /&gt;-- Declare variables which will hold values from cursor rows&lt;br /&gt;DECLARE @TableSchema varchar(100), @TableName varchar(100)&lt;br /&gt;DECLARE @ColumnName varchar(100), @DataType varchar(30)&lt;br /&gt;DECLARE @CharLength varchar(100)&lt;br /&gt;&lt;br /&gt;DECLARE @ColumnNameCleaned varchar(100)&lt;br /&gt;&lt;br /&gt;-- Declare variables which will track what table we are&lt;br /&gt;-- creating Stored Procs for&lt;br /&gt;DECLARE @CurrentTable varchar(100)&lt;br /&gt;DECLARE @FirstTable bit&lt;br /&gt;DECLARE @FirstColumnName varchar(100)&lt;br /&gt;DECLARE @FirstColumnDataType varchar(30)&lt;br /&gt;DECLARE @ObjectName varchar(100) -- this is the tablename with the&lt;br /&gt;-- specified tableprefix lopped off.&lt;br /&gt;DECLARE @TablePrefixLength int&lt;br /&gt;&lt;br /&gt;-- init vars&lt;br /&gt;SET @CurrentTable = ''&lt;br /&gt;SET @FirstTable = 1&lt;br /&gt;SET @TablePrefixLength = Len(@TablePrefix)&lt;br /&gt;&lt;br /&gt;-- Declare variables which will hold the queries we are building use unicode&lt;br /&gt;-- data types so that can execute using sp_ExecuteSQL&lt;br /&gt;DECLARE @LIST nvarchar(4000), @UPSERT nvarchar(4000)&lt;br /&gt;DECLARE @SELECT nvarchar(4000), @INSERT nvarchar(4000), @INSERTVALUES varchar(4000)&lt;br /&gt;DECLARE @UPDATE nvarchar(4000), @DELETE nvarchar(4000)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- open the cursor&lt;br /&gt;OPEN TableCol&lt;br /&gt;&lt;br /&gt;-- get the first row of cursor into variables&lt;br /&gt;FETCH NEXT FROM TableCol INTO @TableSchema, @TableName, @ColumnName, @DataType, @CharLength&lt;br /&gt;&lt;br /&gt;-- loop through the rows of the cursor&lt;br /&gt;WHILE @@FETCH_STATUS = 0 BEGIN&lt;br /&gt;&lt;br /&gt;SET @ColumnNameCleaned = Replace(@ColumnName, ' ', '')&lt;br /&gt;&lt;br /&gt;-- is this a new table?&lt;br /&gt;IF @TableName &amp;lt;&amp;gt; @CurrentTable BEGIN&lt;br /&gt;&lt;br /&gt;-- if is the end of the last table&lt;br /&gt;IF @CurrentTable &amp;lt;&amp;gt; '' BEGIN&lt;br /&gt;IF @GenerateProcsFor = '' OR @GenerateProcsFor = @CurrentTable BEGIN&lt;br /&gt;&lt;br /&gt;-- first add any syntax to end the statement&lt;br /&gt;&lt;br /&gt;-- _lst&lt;br /&gt;SET @LIST = @List + Char(13) + 'FROM ' + @CurrentTable + Char(13)&lt;br /&gt;SET @LIST = @LIST + Char(13) + Char(13) + 'SET NOCOUNT OFF' + Char(13) + Char(13)&lt;br /&gt;SET @LIST = @LIST + Char(13)&lt;br /&gt;&lt;br /&gt;-- _sel&lt;br /&gt;SET @SELECT = @SELECT + Char(13) + 'FROM ' + @CurrentTable + Char(13)&lt;br /&gt;SET @SELECT = @SELECT + 'WHERE [' + @FirstColumnName + '] = @' + Replace(@FirstColumnName, ' ', '') + Char(13)&lt;br /&gt;SET @SELECT = @SELECT + Char(13) + Char(13) + 'SET NOCOUNT OFF' + Char(13) + Char(13)&lt;br /&gt;SET @SELECT = @SELECT + Char(13)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- UPDATE (remove trailing comma and append the WHERE clause)&lt;br /&gt;SET @UPDATE = SUBSTRING(@UPDATE, 0, LEN(@UPDATE)- 1) + Char(13) + Char(9) + 'WHERE [' + @FirstColumnName + '] = @' + Replace(@FirstColumnName, ' ', '') + Char(13)&lt;br /&gt;&lt;br /&gt;-- INSERT&lt;br /&gt;SET @INSERT = SUBSTRING(@INSERT, 0, LEN(@INSERT) - 1) + Char(13) + Char(9) + ')' + Char(13)&lt;br /&gt;SET @INSERTVALUES = SUBSTRING(@INSERTVALUES, 0, LEN(@INSERTVALUES) -1) + Char(13) + Char(9) + ')'&lt;br /&gt;SET @INSERT = @INSERT + @INSERTVALUES&lt;br /&gt;&lt;br /&gt;-- _ups&lt;br /&gt;SET @UPSERT = @UPSERT + Char(13) + 'AS' + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + 'SET NOCOUNT ON' + Char(13)&lt;br /&gt;IF @FirstColumnDataType IN ('int', 'bigint', 'smallint', 'tinyint', 'float', 'decimal')&lt;br /&gt;BEGIN&lt;br /&gt;SET @UPSERT = @UPSERT + 'IF @' + Replace(@FirstColumnName, ' ', '') + ' = 0 BEGIN' + Char(13)&lt;br /&gt;END ELSE BEGIN&lt;br /&gt;SET @UPSERT = @UPSERT + 'IF @' + Replace(@FirstColumnName, ' ', '') + ' = '''' BEGIN' + Char(13)&lt;br /&gt;END&lt;br /&gt;SET @UPSERT = @UPSERT + ISNULL(@INSERT, '') + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + Char(9) + 'SELECT SCOPE_IDENTITY() As InsertedID' + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + 'END' + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + 'ELSE BEGIN' + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + ISNULL(@UPDATE, '') + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + 'END' + Char(13) + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + 'SET NOCOUNT OFF' + Char(13) + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + Char(13)&lt;br /&gt;&lt;br /&gt;IF @PrintOrExecute &amp;lt;&amp;gt; 'Execute' BEGIN&lt;br /&gt;PRINT @LIST&lt;br /&gt;PRINT @SELECT&lt;br /&gt;PRINT @UPSERT&lt;br /&gt;PRINT @DELETE&lt;br /&gt;END ELSE BEGIN&lt;br /&gt;EXEC sp_Executesql @LIST&lt;br /&gt;EXEC sp_Executesql @SELECT&lt;br /&gt;EXEC sp_Executesql @UPSERT&lt;br /&gt;EXEC sp_Executesql @DELETE&lt;br /&gt;END&lt;br /&gt;END -- end @GenerateProcsFor = '' OR @GenerateProcsFor = @CurrentTable&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;-- update the value held in @CurrentTable&lt;br /&gt;SET @CurrentTable = @TableName&lt;br /&gt;SET @FirstColumnName = @ColumnName&lt;br /&gt;SET @FirstColumnDataType = @DataType&lt;br /&gt;&lt;br /&gt;IF @TablePrefixLength &amp;gt; 0 BEGIN&lt;br /&gt;IF SUBSTRING(@CurrentTable, 1, @TablePrefixLength) = @TablePrefix BEGIN&lt;br /&gt;PRINT Char(13) + 'DEBUG: OBJ NAME: ' + RIGHT(@CurrentTable, LEN(@CurrentTable) - @TablePrefixLength)&lt;br /&gt;SET @ObjectName = RIGHT(@CurrentTable, LEN(@CurrentTable) - @TablePrefixLength)&lt;br /&gt;END ELSE BEGIN&lt;br /&gt;SET @ObjectName = @CurrentTable&lt;br /&gt;END&lt;br /&gt;END ELSE BEGIN&lt;br /&gt;SET @ObjectName = @CurrentTable&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;IF @GenerateProcsFor = '' OR @GenerateProcsFor = @CurrentTable BEGIN&lt;br /&gt;&lt;br /&gt;-- _lst&lt;br /&gt;SET @LIST = 'CREATE PROCEDURE [dbo].[udp_' + @ObjectName + '_lst]' + Char(13)&lt;br /&gt;SET @LIST = @LIST + 'AS' + Char(13)&lt;br /&gt;SET @LIST = @LIST + 'SET NOCOUNT ON' + Char(13)&lt;br /&gt;IF @UseSelectWildcard = 1 BEGIN&lt;br /&gt;SET @LIST = @LIST + Char(13) + 'SELECT * '&lt;br /&gt;END&lt;br /&gt;ELSE BEGIN&lt;br /&gt;SET @LIST = @LIST + Char(13) + 'SELECT [' + @ColumnName + ']'&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;-- _sel&lt;br /&gt;SET @SELECT = 'CREATE PROCEDURE [dbo].[udp_' + @ObjectName + '_sel]' + Char(13)&lt;br /&gt;SET @SELECT = @SELECT + Char(9) + '@' + @ColumnNameCleaned + ' ' + @DataType&lt;br /&gt;IF @DataType IN ('varchar', 'nvarchar', 'char', 'nchar') BEGIN&lt;br /&gt;IF @CharLength = -1 BEGIN&lt;br /&gt;SET @SELECT = @SELECT + '(MAX)'&lt;br /&gt;END&lt;br /&gt;ELSE BEGIN&lt;br /&gt;SET @SELECT = @SELECT + '(' + CAST(@CharLength As varchar(100)) + ')'&lt;br /&gt;END&lt;br /&gt;END&lt;br /&gt;SET @SELECT = @SELECT + Char(13) + 'AS' + Char(13)&lt;br /&gt;SET @SELECT = @SELECT + 'SET NOCOUNT ON' + Char(13)&lt;br /&gt;IF @UseSelectWildcard = 1 BEGIN&lt;br /&gt;SET @SELECT = @SELECT + Char(13) + 'SELECT * '&lt;br /&gt;END&lt;br /&gt;ELSE BEGIN&lt;br /&gt;SET @SELECT = @SELECT + Char(13) + 'SELECT [' + @ColumnName + ']'&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;-- _ups&lt;br /&gt;SET @UPSERT = 'CREATE PROCEDURE [dbo].[udp_' + @ObjectName + '_ups]' + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + Char(13) + Char(9) + '@' + @ColumnNameCleaned + ' ' + @DataType&lt;br /&gt;IF @DataType IN ('varchar', 'nvarchar', 'char', 'nchar') BEGIN&lt;br /&gt;IF @CharLength = -1 BEGIN&lt;br /&gt;SET @UPSERT = @UPSERT + '(MAX)'&lt;br /&gt;END&lt;br /&gt;ELSE BEGIN&lt;br /&gt;SET @UPSERT = @UPSERT + '(' + CAST(@CharLength As Varchar(10)) + ')'&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;-- UPDATE&lt;br /&gt;SET @UPDATE = Char(9) + 'UPDATE ' + @TableName + ' SET ' + Char(13)&lt;br /&gt;&lt;br /&gt;-- INSERT -- don't add first column to insert if it is an&lt;br /&gt;-- integer (assume autonumber)&lt;br /&gt;SET @INSERT = Char(9) + 'INSERT INTO ' + @TableName + ' (' + Char(13)&lt;br /&gt;SET @INSERTVALUES = Char(9) + 'VALUES (' + Char(13)&lt;br /&gt;&lt;br /&gt;IF @FirstColumnDataType NOT IN ('int', 'bigint', 'smallint', 'tinyint')&lt;br /&gt;BEGIN&lt;br /&gt;SET @INSERT = @INSERT + Char(9) + Char(9) + '[' + @ColumnName + '],' + Char(13)&lt;br /&gt;SET @INSERTVALUES = @INSERTVALUES + Char(9) + Char(9) + '@' + @ColumnNameCleaned + ',' + Char(13)&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;-- _del&lt;br /&gt;SET @DELETE = 'CREATE PROCEDURE [dbo].[udp_' + @ObjectName + '_del]' + Char(13)&lt;br /&gt;SET @DELETE = @DELETE + Char(9) + '@' + @ColumnNameCleaned + ' ' + @DataType&lt;br /&gt;IF @DataType IN ('varchar', 'nvarchar', 'char', 'nchar') BEGIN&lt;br /&gt;IF @CharLength = -1 BEGIN&lt;br /&gt;SET @DELETE = @DELETE + '(MAX)'&lt;br /&gt;END&lt;br /&gt;ELSE BEGIN&lt;br /&gt;SET @DELETE = @DELETE + '(' + CAST(@CharLength As Varchar(10)) + ')'&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;END&lt;br /&gt;SET @DELETE = @DELETE + Char(13) + 'AS' + Char(13)&lt;br /&gt;SET @DELETE = @DELETE + 'SET NOCOUNT ON' + Char(13) + Char(13)&lt;br /&gt;SET @DELETE = @DELETE + 'DELETE FROM ' + @TableName + Char(13)&lt;br /&gt;SET @DELETE = @DELETE + 'WHERE [' + @ColumnName + '] = @' + @ColumnNameCleaned + Char(13)&lt;br /&gt;SET @DELETE = @DELETE + Char(13) + 'SET NOCOUNT OFF' + Char(13)&lt;br /&gt;SET @DELETE = @DELETE + Char(13)&lt;br /&gt;&lt;br /&gt;END -- end @GenerateProcsFor = '' OR @GenerateProcsFor = @CurrentTable&lt;br /&gt;END&lt;br /&gt;ELSE BEGIN&lt;br /&gt;IF @GenerateProcsFor = '' OR @GenerateProcsFor = @CurrentTable BEGIN&lt;br /&gt;&lt;br /&gt;-- _lst&lt;br /&gt;IF @UseSelectWildCard = 0 BEGIN&lt;br /&gt;SET @LIST = @LIST + ', ' + Char(13) + Char(9) + '[' + @ColumnName + ']'&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;-- _sel&lt;br /&gt;IF @UseSelectWildCard = 0 BEGIN&lt;br /&gt;SET @SELECT = @SELECT + ', ' + Char(13) + Char(9) + '[' + @ColumnName + ']'&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;-- _ups&lt;br /&gt;SET @UPSERT = @UPSERT + ',' + Char(13) + Char(9) + '@' + @ColumnNameCleaned + ' ' + @DataType&lt;br /&gt;IF @DataType IN ('varchar', 'nvarchar', 'char', 'nchar') BEGIN&lt;br /&gt;SET @UPSERT = @UPSERT + '(' + CAST(@CharLength As varchar(10)) + ')'&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;-- UPDATE&lt;br /&gt;SET @UPDATE = @UPDATE + Char(9) + Char(9) + '[' + @ColumnName + '] = @' + @ColumnNameCleaned + ',' + Char(13)&lt;br /&gt;&lt;br /&gt;-- INSERT&lt;br /&gt;SET @INSERT = @INSERT + Char(9) + Char(9) + '[' + @ColumnName + '],' + Char(13)&lt;br /&gt;SET @INSERTVALUES = @INSERTVALUES + Char(9) + Char(9) + '@' + @ColumnNameCleaned + ',' + Char(13)&lt;br /&gt;&lt;br /&gt;-- _del&lt;br /&gt;-- delete proc completed already&lt;br /&gt;END -- end @GenerateProcsFor = '' OR @GenerateProcsFor = @CurrentTable'&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;-- fetch next row of cursor into variables&lt;br /&gt;FETCH NEXT FROM TableCol INTO @TableSchema, @TableName, @ColumnName, @DataType, @CharLength&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;-- ----------------&lt;br /&gt;-- clean up cursor&lt;br /&gt;-- ----------------&lt;br /&gt;CLOSE TableCol&lt;br /&gt;DEALLOCATE TableCol&lt;br /&gt;&lt;br /&gt;-- if is the end of the last table&lt;br /&gt;IF @CurrentTable &amp;lt;&amp;gt; '' BEGIN&lt;br /&gt;IF @GenerateProcsFor = '' OR @GenerateProcsFor = @CurrentTable BEGIN&lt;br /&gt;&lt;br /&gt;-- first add any syntax to end the statement&lt;br /&gt;&lt;br /&gt;-- _lst&lt;br /&gt;SET @LIST = @List + Char(13) + 'FROM ' + @CurrentTable + Char(13)&lt;br /&gt;SET @LIST = @LIST + Char(13) + Char(13) + 'SET NOCOUNT OFF' + Char(13)&lt;br /&gt;SET @LIST = @LIST + Char(13)&lt;br /&gt;&lt;br /&gt;-- _sel&lt;br /&gt;SET @SELECT = @SELECT + Char(13) + 'FROM ' + @CurrentTable + Char(13)&lt;br /&gt;SET @SELECT = @SELECT + 'WHERE [' + @FirstColumnName + '] = @' + Replace(@FirstColumnName, ' ', '') + Char(13)&lt;br /&gt;SET @SELECT = @SELECT + Char(13) + Char(13) + 'SET NOCOUNT OFF' + Char(13)&lt;br /&gt;SET @SELECT = @SELECT + Char(13)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- UPDATE (remove trailing comma and append the WHERE clause)&lt;br /&gt;SET @UPDATE = SUBSTRING(@UPDATE, 0, LEN(@UPDATE)- 1) + Char(13) + Char(9) + 'WHERE [' + @FirstColumnName + '] = @' + Replace(@FirstColumnName, ' ', '') + Char(13)&lt;br /&gt;&lt;br /&gt;-- INSERT&lt;br /&gt;SET @INSERT = SUBSTRING(@INSERT, 0, LEN(@INSERT) - 1) + Char(13) + Char(9) + ')' + Char(13)&lt;br /&gt;SET @INSERTVALUES = SUBSTRING(@INSERTVALUES, 0, LEN(@INSERTVALUES) -1) + Char(13) + Char(9) + ')'&lt;br /&gt;SET @INSERT = @INSERT + @INSERTVALUES&lt;br /&gt;&lt;br /&gt;-- _ups&lt;br /&gt;SET @UPSERT = @UPSERT + Char(13) + 'AS' + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + 'SET NOCOUNT ON' + Char(13)&lt;br /&gt;IF @FirstColumnDataType IN ('int', 'bigint', 'smallint', 'tinyint', 'float', 'decimal')&lt;br /&gt;BEGIN&lt;br /&gt;SET @UPSERT = @UPSERT + 'IF @' + Replace(@FirstColumnName, ' ', '') + ' = 0 BEGIN' + Char(13)&lt;br /&gt;END ELSE BEGIN&lt;br /&gt;SET @UPSERT = @UPSERT + 'IF @' + Replace(@FirstColumnName, ' ', '') + ' = '''' BEGIN' + Char(13)&lt;br /&gt;END&lt;br /&gt;SET @UPSERT = @UPSERT + ISNULL(@INSERT, '') + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + Char(9) + 'SELECT SCOPE_IDENTITY() As InsertedID' + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + 'END' + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + 'ELSE BEGIN' + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + ISNULL(@UPDATE, '') + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + 'END' + Char(13) + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + 'SET NOCOUNT OFF' + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + Char(13)&lt;br /&gt;IF @PrintOrExecute &amp;lt;&amp;gt; 'Execute' BEGIN&lt;br /&gt;PRINT @LIST&lt;br /&gt;PRINT @SELECT&lt;br /&gt;PRINT @UPSERT&lt;br /&gt;PRINT @DELETE&lt;br /&gt;END ELSE BEGIN&lt;br /&gt;EXEC sp_Executesql @LIST&lt;br /&gt;EXEC sp_Executesql @SELECT&lt;br /&gt;EXEC sp_Executesql @UPSERT&lt;br /&gt;EXEC sp_Executesql @DELETE&lt;br /&gt;END&lt;br /&gt;END -- end @GenerateProcsFor = '' OR @GenerateProcsFor = @CurrentTable&lt;br /&gt;END&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-9009338860482870808?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/9009338860482870808/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2011/10/generate-audit-table-for-every-database.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/9009338860482870808'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/9009338860482870808'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2011/10/generate-audit-table-for-every-database.html' title='Generate Audit Table for every database'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-9068871018154640139</id><published>2011-07-13T01:24:00.000-07:00</published><updated>2011-07-13T01:24:04.294-07:00</updated><title type='text'>Fourier Transform - NOTES</title><content type='html'>Read along as the syllabus outlines. &lt;br /&gt;Matlab problems for homework. doesnt need to be terribly advance... get some experience and get some access.&lt;br /&gt;very mathematical class. corner stone for signal processing.&lt;br /&gt;rich and diverse subject. make a choice on how to start and go about.&lt;br /&gt;start with fourier series:&lt;br /&gt;identified with the mathematical analysis of periodic phenomena.&lt;br /&gt;fourier transform as a limiting case of fourier series or techniques is concerned with non periodic phenomena.(doesnt say everything but says something)&lt;br /&gt;some ideas carry easily between the 2.&lt;br /&gt;&lt;br /&gt;Analysis (taking a function and breaking it up to simple constituent parts)&lt;br /&gt;synthesis (reassembling a function from its constituent parts)&lt;br /&gt;&lt;br /&gt;both analysis and synthesis are accomplished by &lt;u&gt;linear operation&lt;/u&gt; ei.integrals and series.&lt;br /&gt;&lt;br /&gt;often see or hear that fourier analysis is part of "linear systems"&lt;br /&gt;&lt;i&gt;&lt;u&gt;period phenomena and Fourier Series&lt;/u&gt;&lt;/i&gt;&lt;br /&gt;&amp;nbsp;mathematics and engineering of regularly repeating patterns. ( you know it when you see it)&lt;br /&gt;periodic phenomena often are either periodicity in time or space. which may also overlap. ei. harmonic motion.&lt;br /&gt;periodicity in space: an object that has symmetry in space 2D or 3D or ...&lt;br /&gt;a physical quantity distributed over a region with symmetry. periodicity arises from symmetry. eg. distribution of heat on a circular ring. temperature.&lt;br /&gt;measure temp at points in a ring. periodic in space not time. therefore periodic in spatial variable.&lt;br /&gt;fourier analysis is often associated with problems with symmetry.&lt;br /&gt;&lt;br /&gt;Mathematical descriptor of periodicity. frequency is used in periodic in time. number of cycles in a second. number of repetition of a pattern over time.&lt;br /&gt;&lt;br /&gt;periodicity in space we use PERIOD.measurement of how big the pattern is that&lt;u&gt; repeats&lt;/u&gt;.&lt;br /&gt;periodic time and space come together in eg. wave motion.&lt;br /&gt;a regularly repeating or moving disturbance pattern that changes in time or moves.&lt;br /&gt;for periodicity in space, fix the time and see the pattern distributed in space. length of one complete disturbance or pattern is a &lt;u&gt;wave length&lt;/u&gt;. denoted by lambda&lt;br /&gt;&lt;br /&gt;relationship between frequency and wave length.&lt;br /&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;b&gt;distance = rate * time&lt;/b&gt;&lt;/div&gt;&lt;br /&gt;rate is the velocity (v) of the wave.&lt;br /&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;Lambda&amp;nbsp; = velocity * (1\mu)&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;lambda*mu = v&lt;/div&gt;&lt;br /&gt;Reciprocal relationship between frequency and wavelength.&lt;br /&gt;&lt;br /&gt;Math comes in because there are simple mathematical functions that are periodic that repeat and so can be used to model periodic phenomena.&lt;br /&gt;&lt;br /&gt;cost and sint are periodic of period 2pi&lt;br /&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;cos (t +2pi) = cost&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;sin(t+2pi) = sint&lt;/div&gt;&lt;br /&gt;in a circle&lt;br /&gt;(cost, sint) -&amp;gt; t is radian.periodicity in space.&lt;br /&gt;any multiple of 2pi from positive or negative&lt;br /&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;cos (t +2pin) = cost&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;sin(t+2pin) = sint&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;n = 0,+-1,+-2 &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-9068871018154640139?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/9068871018154640139/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2011/07/fourier-transform-notes.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/9068871018154640139'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/9068871018154640139'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2011/07/fourier-transform-notes.html' title='Fourier Transform - NOTES'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-3137933225333739894</id><published>2011-06-07T22:42:00.000-07:00</published><updated>2011-06-07T22:42:21.639-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql'/><category scheme='http://www.blogger.com/atom/ns#' term='linq'/><category scheme='http://www.blogger.com/atom/ns#' term='sql script'/><title type='text'>Number of connections to your Database</title><content type='html'>&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;SELECT db_name(dbid) as DatabaseName, count(dbid) as NoOfConnections,&lt;br /&gt;loginame as LoginName&lt;br /&gt;FROM sys.sysprocesses&lt;br /&gt;WHERE dbid &amp;gt; 0&lt;br /&gt;GROUP BY dbid, loginame&lt;/div&gt;&lt;br /&gt;&amp;nbsp;Works for SQL express and SQL standard edition&lt;br /&gt;&lt;br /&gt;i use this to test if the code i write keeps the connection open or closed. very useful when programming in LINQ&lt;br /&gt;&lt;br /&gt;DatabaseName&amp;nbsp;&amp;nbsp;&amp;nbsp; NoOfConnections&amp;nbsp;&amp;nbsp;&amp;nbsp; LoginName&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;master&amp;nbsp;&amp;nbsp;&amp;nbsp; 18&amp;nbsp;&amp;nbsp;&amp;nbsp; sa&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;VLOCAL&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp; vareshlocal&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-3137933225333739894?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/3137933225333739894/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2011/06/number-of-connections-to-your-database.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/3137933225333739894'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/3137933225333739894'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2011/06/number-of-connections-to-your-database.html' title='Number of connections to your Database'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-6166415459751750523</id><published>2010-12-21T17:44:00.000-08:00</published><updated>2010-12-21T18:00:08.258-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='encrypt'/><category scheme='http://www.blogger.com/atom/ns#' term='querystring'/><category scheme='http://www.blogger.com/atom/ns#' term='global.asax'/><category scheme='http://www.blogger.com/atom/ns#' term='encrypt/decrypt'/><category scheme='http://www.blogger.com/atom/ns#' term='default.aspx'/><category scheme='http://www.blogger.com/atom/ns#' term='decrypt'/><category scheme='http://www.blogger.com/atom/ns#' term='asp.net'/><category scheme='http://www.blogger.com/atom/ns#' term='webconfig'/><category scheme='http://www.blogger.com/atom/ns#' term='httpmodules'/><category scheme='http://www.blogger.com/atom/ns#' term='asp.net security'/><category scheme='http://www.blogger.com/atom/ns#' term='security'/><category scheme='http://www.blogger.com/atom/ns#' term='query string'/><title type='text'>Encrypt/Decrypt QueryString in ASP.net</title><content type='html'>when creating asp.net applications its a bummer to actually use &lt;blockquote&gt;server.urlencode&lt;/blockquote&gt; specially when your using urls such as this&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;http://www.yoursite.com/default.aspx?&lt;span style="color: rgb(255, 0, 0);"&gt;page=1&lt;/span&gt;&lt;br /&gt;http://www.yoursite.com/default.aspx?&lt;span style="color: rgb(255, 0, 0);"&gt;page=home&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;you have to protect these querystrings from unwanted variables that a user might set. alot of solutions point to encrypting these query strings. the following is an extension to the IHttpModule that i modified just setting the httpModules in web config will allow the encryption of the url.&lt;br /&gt;so you can easily use &lt;blockquote&gt;Response.Write("default.aspx?page=home");&lt;/blockquote&gt; and the output will be encrypted to this : &lt;blockquote&gt;default.aspx?ats=KtpU3C6JGPi6Q5Dm5vy/+xM33YwsP+19dJYkJ10qAOZwxK4JaK7iT8BozTwC6W17&lt;/blockquote&gt;&lt;br /&gt;in the url. and you can easily use Request.Querystring["page"] without the need to decrypt it. so the user sees one thing and the server sees another. this is a very useful feature in the production server.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;p&gt;&lt;br /&gt;    using System;&lt;br /&gt;&lt;br /&gt;    using System.IO;&lt;br /&gt;&lt;br /&gt;    using System.Web;&lt;br /&gt;&lt;br /&gt;    using System.Text;&lt;br /&gt;&lt;br /&gt;    using System.Security.Cryptography;&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;    namespace ats&lt;br /&gt;&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;        public class QueryStringModule : IHttpModule&lt;br /&gt;&lt;br /&gt;        {&lt;br /&gt;&lt;br /&gt;            private const string PARAMETER_NAME = &amp;quot;ats=&amp;quot;;&lt;br /&gt;&lt;br /&gt;            private const string ENCRYPTION_KEY = &amp;quot;key&amp;quot;;&lt;br /&gt;&lt;br /&gt;            private readonly static byte[] SALT = Encoding.ASCII.GetBytes(ENCRYPTION_KEY.Length.ToString());&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;            public void Dispose()&lt;br /&gt;&lt;br /&gt;            {&lt;br /&gt;&lt;br /&gt;                // Nothing to dispose&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;            public void Init(HttpApplication context)&lt;br /&gt;&lt;br /&gt;            {&lt;br /&gt;&lt;br /&gt;                context.BeginRequest += new EventHandler(context_BeginRequest);&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            public void context_BeginRequest(object sender, EventArgs e)&lt;br /&gt;&lt;br /&gt;            {&lt;br /&gt;&lt;br /&gt;                HttpContext context = HttpContext.Current;&lt;br /&gt;&lt;br /&gt;                if (context.Request.Url.OriginalString.Contains(&amp;quot;aspx&amp;quot;) &amp;amp;&amp;amp; context.Request.RawUrl.Contains(&amp;quot;?&amp;quot;))&lt;br /&gt;&lt;br /&gt;                {&lt;br /&gt;&lt;br /&gt;                    string query = ExtractQuery(context.Request.RawUrl);&lt;br /&gt;&lt;br /&gt;                    string path = GetVirtualPath();&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;                    if (query.StartsWith(PARAMETER_NAME, StringComparison.OrdinalIgnoreCase))&lt;br /&gt;&lt;br /&gt;                    {&lt;br /&gt;&lt;br /&gt;                        // Decrypts the query string and rewrites the path.&lt;br /&gt;&lt;br /&gt;                        string rawQuery = query.Replace(PARAMETER_NAME, string.Empty);&lt;br /&gt;&lt;br /&gt;                        string decryptedQuery = Decrypt(rawQuery);&lt;br /&gt;&lt;br /&gt;                        context.RewritePath(path, string.Empty, decryptedQuery);&lt;br /&gt;&lt;br /&gt;                    }&lt;br /&gt;&lt;br /&gt;                    else if (context.Request.HttpMethod == &amp;quot;GET&amp;quot;)&lt;br /&gt;&lt;br /&gt;                    {&lt;br /&gt;&lt;br /&gt;                        string encryptedQuery = Encrypt(query);&lt;br /&gt;&lt;br /&gt;                        context.Response.Redirect(path + encryptedQuery);&lt;br /&gt;&lt;br /&gt;                    }&lt;br /&gt;&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            private static string GetVirtualPath()&lt;br /&gt;&lt;br /&gt;            {&lt;br /&gt;&lt;br /&gt;                string path = HttpContext.Current.Request.RawUrl;&lt;br /&gt;&lt;br /&gt;                path = path.Substring(0, path.IndexOf(&amp;quot;?&amp;quot;));&lt;br /&gt;&lt;br /&gt;                path = path.Substring(path.LastIndexOf(&amp;quot;/&amp;quot;) + 1);&lt;br /&gt;&lt;br /&gt;                return path;&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            private static string ExtractQuery(string url)&lt;br /&gt;&lt;br /&gt;            {&lt;br /&gt;&lt;br /&gt;                int index = url.IndexOf(&amp;quot;?&amp;quot;) + 1;&lt;br /&gt;&lt;br /&gt;                return url.Substring(index);&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            public static string Encrypt(string inputText)&lt;br /&gt;&lt;br /&gt;            {&lt;br /&gt;&lt;br /&gt;                RijndaelManaged rijndaelCipher = new RijndaelManaged();&lt;br /&gt;&lt;br /&gt;                byte[] plainText = Encoding.Unicode.GetBytes(inputText);&lt;br /&gt;&lt;br /&gt;                PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(ENCRYPTION_KEY, SALT);&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;                using (ICryptoTransform encryptor = rijndaelCipher.CreateEncryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16)))&lt;br /&gt;&lt;br /&gt;                {&lt;br /&gt;&lt;br /&gt;                    using (MemoryStream memoryStream = new MemoryStream())&lt;br /&gt;&lt;br /&gt;                    {&lt;br /&gt;&lt;br /&gt;                        using (CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))&lt;br /&gt;&lt;br /&gt;                        {&lt;br /&gt;&lt;br /&gt;                            cryptoStream.Write(plainText, 0, plainText.Length);&lt;br /&gt;&lt;br /&gt;                            cryptoStream.FlushFinalBlock();&lt;br /&gt;&lt;br /&gt;                            return &amp;quot;?&amp;quot; + PARAMETER_NAME + Convert.ToBase64String(memoryStream.ToArray());&lt;br /&gt;&lt;br /&gt;                        }&lt;br /&gt;&lt;br /&gt;                    }&lt;br /&gt;&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            public static string Decrypt(string inputText)&lt;br /&gt;&lt;br /&gt;            {&lt;br /&gt;&lt;br /&gt;                RijndaelManaged rijndaelCipher = new RijndaelManaged();&lt;br /&gt;&lt;br /&gt;                byte[] encryptedData = Convert.FromBase64String(inputText);&lt;br /&gt;&lt;br /&gt;                PasswordDeriveBytes secretKey = new PasswordDeriveBytes(ENCRYPTION_KEY, SALT);&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;                using (ICryptoTransform decryptor = rijndaelCipher.CreateDecryptor(secretKey.GetBytes(32), secretKey.GetBytes(16)))&lt;br /&gt;&lt;br /&gt;                {&lt;br /&gt;&lt;br /&gt;                    using (MemoryStream memoryStream = new MemoryStream(encryptedData))&lt;br /&gt;&lt;br /&gt;                    {&lt;br /&gt;&lt;br /&gt;                        using (CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))&lt;br /&gt;&lt;br /&gt;                        {&lt;br /&gt;&lt;br /&gt;                            byte[] plainText = new byte[encryptedData.Length];&lt;br /&gt;&lt;br /&gt;                            int decryptedCount = cryptoStream.Read(plainText, 0, plainText.Length);&lt;br /&gt;&lt;br /&gt;                            return Encoding.Unicode.GetString(plainText, 0, decryptedCount);&lt;br /&gt;&lt;br /&gt;                        }&lt;br /&gt;&lt;br /&gt;                    }&lt;br /&gt;&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;    }&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;and adding this line to the webconfig httpmodules section:&lt;br /&gt;&lt;p&gt;&lt;br /&gt; &amp;lt;httpModules&amp;gt;&lt;br /&gt;&lt;br /&gt;       &amp;lt;add name = "QueryStringModule" type ="ats.QueryStringModule"/&amp;gt;&lt;br /&gt;&lt;br /&gt;         &amp;lt;/httpModules&amp;gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-6166415459751750523?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/6166415459751750523/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2010/12/encryptdecrypt-querystring-in-aspnet.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/6166415459751750523'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/6166415459751750523'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2010/12/encryptdecrypt-querystring-in-aspnet.html' title='Encrypt/Decrypt QueryString in ASP.net'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-646791167065300446</id><published>2010-11-30T16:25:00.000-08:00</published><updated>2010-11-30T16:26:02.525-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python'/><category scheme='http://www.blogger.com/atom/ns#' term='scipting language'/><title type='text'>The beauty of PYTHON Language</title><content type='html'>&lt;span style="font-family:san serif;font-size:+1;"&gt; &lt;span style="font-size:+2;color:green;"&gt;Introduction to Python&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt; &lt;span style="font-family:san serif;font-size:+1;"&gt;Python is a multifaceted, multi-platform, open source, general-purpose and object-oriented programming language like Java, C++ TCL, and Perl, but with a particular affinity towards text processing. Python is a language that maps well to the thought process and abilities of the modern sophisticated programmer. Python has minimal syntax and it is highly scalable, interpreted and readable. It is very easy to use and for maintenance and increases significant productivity. &lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;span style="font-family:san serif;font-size:+1;"&gt; Python is also useful for coding scripts to be embedded in server side technologies such as Microsoft ASP towards generating dynamic Web pages. Python is highly portable that its statements can be interpreted in a number of operating systems including Unix and its variants, Mac and Windows systems. Python is freely available in both source code and compiled form for nearly every hardware platform in this planet. A major deviation of Python from other languages is that Python uses the indentation of lines of code to work out how the lines should be grouped together for processing. Python is highly interactive, and specifically good for XML processing by its string slicing feature.&lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;span style="font-family:san serif;font-size:+1;"&gt; Python is written in C and has incorporated many robust features of C. Execution of Python programs is similar to Java. Python programs are compiled into an intermediate representation known as Python bytecode, which will be executed by Python Virtual machine. Python uses reference counting as its memory management scheme. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:san serif;font-size:+1;"&gt; Python is a dynamically typed language, that is, its variables are not restricted to referencing objects of any particular type by the language. &lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;span style="font-family:san serif;font-size:+1;"&gt;Scripting languages are traditionally used for small tasks, gluing other programs together, and automating processes, Python is unique in its scalability, from small scripts to very large systems. Python incorporates the best features of a variety of other languages, and introduces a few new ideas of its own, into a remarkably elegant, cohesive, and useful whole. Python can help the job done more quickly and simply. &lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:san serif;font-size:+1;"&gt;&lt;span style="font-size:+2;color:green;"&gt;Python Features&lt;/span&gt; &lt;/span&gt;&lt;p&gt; &lt;span style="font-family:san serif;font-size:+1;"&gt;Python's features are more inclined toward programmer efficiency and efficacy, sometimes at the expense of program efficiency. That is, Python programs are faster to write, but sometimes slower to run. &lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;span style="font-family:san serif;font-size:+1;"&gt;Python is a &lt;span style="color:blue;"&gt;very high level language&lt;/span&gt; (VHLL). Python programs are a high level representation of a programmer's ideas. Low-level housekeeping details like memory allocation and reclamation are handled by Python itself. The developers need not worry about them. High level means seeing the big picture and delegating the details. Python with intelligent syntax reduces clutter. The interpreter understands program structure by examining the physical structure of the code; block delimiters are not required. Modules and classes provide exceedingly accessible abstraction, encapsulation and modularity. &lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;span style="font-family:san serif;font-size:+1;"&gt;Python programs are &lt;span style="color:blue;"&gt; interpreted &lt;/span&gt; and they have only two tasks: edit and run. Normally the compiling languages like C, undergoes edit, compile, link and run cycles. With dynamic loading and some planning, the cycle can be run, edit and reload the edited part into the running process with stopping. The Python interpreter reads source files called modules, which usually have the extension .py, converts them to portable byte codes, and executes them by interpreting the byte codes much like Java does. Python is sometimes referred to as a scripting language. &lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;span style="font-family:san serif;font-size:+1;"&gt;Python code is &lt;span style="color:blue;"&gt; clean, simple and powerful&lt;/span&gt;. It is remarkably easy to write, read and maintain. Python programs can be read and understood by non-Python programmers and even non-programmers. Python also makes an excellent teaching as it is relatively devoid of the details that make other languages difficult for neophytes to learn. Python's syntax is minimalist. It lacks a lot of the noise characters that other languages suffer from, like semicolons at the end of each statement, special dereferencing symbols and braces or begin/end for nested code blocks. As opposed to some form of start/end indicators ({ and }), begin/end, if/fi, case/esac and for/done in other programming languages, the hierarchy of blocks of code in Python is indicated by that code block's indentation level. Because of its simplicity, Python's syntax is also very powerful. An equivalent task will often require far less Python code than C code. Fewer lines of code also means fewer bugs, greater programmer productivity and far less frustration. Python began as a minimalist language and change to the core language syntax has been planned and deliberately slow. Future versions of Python may even reduce the complexity of the language. &lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;span style="font-family:san serif;font-size:+1;"&gt;Python is &lt;span style="color:blue;"&gt;object-oriented&lt;/span&gt;. In Python, everything is an object. The implementation of classes and objects is much simpler in Python. The simplicity makes OOP accessible, laying bare the essential nature of object orientation without complicated trappings that get in the way of the concept. &lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;span style="font-family:san serif;font-size:+1;"&gt;In Python, variables are &lt;span style="color:blue;"&gt; dynamically typed&lt;/span&gt;. That is, variables are created when they assigned a value and their type depends on the data they contain. An existing variable can be assigned a new value of a different type. With care and understanding, this feature leads to impressive programming power. Used carelessly, dynamic typing can be a major source of program bugs. &lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;span style="font-family:san serif;font-size:+1;"&gt;Python is blessed with &lt;span style="color:blue;"&gt;large standard library&lt;/span&gt;. Python's core language is very minimal, providing much less functionality. However the standard Python distribution includes a large number and variety of modules, ready and easy to use in our own programs. Library modules include: string operations, regular expressions, file and operating system access, threads, sockets, database access, Internet protocols and even access to Python's parser internals. &lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;span style="font-family:san serif;font-size:+1;"&gt;Python works on &lt;span style="color:blue;"&gt;multi-platform&lt;/span&gt;. Python has been ported to almost every hardware platform and operating system available, including Linux, Unix, MacOS, and Windows. General-purpose modules, if properly coded, will run on multiple platforms without any modification. &lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;span style="font-family:san serif;font-size:+1;"&gt;Python has &lt;span style="color:blue;"&gt;multiple implementations&lt;/span&gt;. Python standard implementation has been written in C. Now there is JPython, which is 100% Java. This runs on Java platforms and provides seamless integration to Java classes. In addition, Stackless Python is available. This takes away the necessity of C stack, enabling Python to run in tight quarters, such as on handheld devices. &lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;span style="font-family:san serif;font-size:+1;"&gt;Python is &lt;span style="color:blue;"&gt;scalable&lt;/span&gt;. That is, simple 10-line scripts are easy to write and read and large systems with thousands of lines of code are feasible and maintainable in Python. Python implements encapsulation at multiple levels. Functions encapsulate reusable program code, classes combine data with their associated functions, modules contain related classes and functions and packages encapsulate systems. If native Python code is too slow or can not access low-level functionality, extension modules can be written in C. If we have an application that needs to be scriptable, Python can be embedded. &lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;span style="font-family:san serif;font-size:+1;"&gt;Python is &lt;span style="color:blue;"&gt;open source&lt;/span&gt;. It is completely free for use, modification, redistribution, and commercial use. Python's source code is freely downloadable.  &lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-646791167065300446?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/646791167065300446/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2010/11/beauty-of-python-language.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/646791167065300446'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/646791167065300446'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2010/11/beauty-of-python-language.html' title='The beauty of PYTHON Language'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-4374045429248508908</id><published>2010-11-22T03:59:00.001-08:00</published><updated>2010-11-22T04:02:24.811-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='convert word to html'/><category scheme='http://www.blogger.com/atom/ns#' term='asp.net'/><category scheme='http://www.blogger.com/atom/ns#' term='doc2html'/><category scheme='http://www.blogger.com/atom/ns#' term='word2html'/><title type='text'>Convert microsoft word documents to HTML</title><content type='html'>this is my class file, modified for easy use see below&lt;br /&gt;&lt;br /&gt;to invoke this method in an asp.net page just use :&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;string fullPath = Server.MapPath("~/folderTest/");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; ats_docConverter.atsWord.atsStart(fullPath + "test.doc");&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;this is my class file:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;using System;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;using System.Collections.Generic;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;using System.Linq;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;using System.Text;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;using System.Reflection;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;using System.Runtime.InteropServices;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;using System.IO;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;using System.Collections;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;namespace ats_docConverter&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;    public class atsWord : IDisposable&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        // Fields&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        private bool _CreateFilesFolder;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        private Exception _Except;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        private bool _IsWordInstalled;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        private int _ReturnCode;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        private bool _SavePictureWithDocument;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        private bool _UpdateLinksOnSave;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        private string _Version;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        private object objDoc;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        private object objDocuments;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        private object objWordApp;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        private object unknown;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        private Type wordApp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        public static void atsStart(String _filename)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            atsWord a = new atsWord();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            a.OpenDoc(_filename);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            a.DocToHtml(_filename);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            a.Dispose();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        // Methods&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        public atsWord()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            this.OfficeApplicationsInit();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        public void Dispose()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            if ((this.objWordApp != null) || (this.wordApp != null))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                Exception exception;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                try&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    if (this.objDoc != null)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        this.objDoc.GetType().InvokeMember("Close", BindingFlags.InvokeMethod, null, this.objDoc, new object[3]);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    this.objWordApp.GetType().InvokeMember("Quit", BindingFlags.InvokeMethod, null, this.objWordApp, null);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                catch (Exception exception1)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    exception = exception1;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    this._Except = exception;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                try&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    if (this.objDoc != null)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        Marshal.ReleaseComObject(this.objDoc);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        this.objDoc = null;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    Marshal.ReleaseComObject(this.objDocuments);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    this.objDocuments = null;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    Marshal.ReleaseComObject(this.objWordApp);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    this.objWordApp = null;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    GC.Collect();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    GC.WaitForPendingFinalizers();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    GC.Collect();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                catch (Exception exception2)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    exception = exception2;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    this._Except = exception;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        private int DocToHtml(string fileHtml)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            this._ReturnCode = 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            if (((this.objDoc != null) &amp;amp;&amp;amp; (this.objWordApp != null)) &amp;amp;&amp;amp; (this.wordApp != null))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                try&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    int num;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    object[] objArray;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    if (Convert.ToInt32(this.Version) &lt;= 9)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        num = 10;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        objArray = new object[] { fileHtml, num, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown };&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        this.objDoc.GetType().InvokeMember("SaveAs", BindingFlags.InvokeMethod, null, this.objDoc, objArray);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    else if (Convert.ToInt32(this.Version) &lt;= 10)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        num = 10;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        objArray = new object[] { fileHtml, num, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown };&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        this.objDoc.GetType().InvokeMember("SaveAs", BindingFlags.InvokeMethod, null, this.objDoc, objArray);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    else&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        num = 10;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        objArray = new object[] { fileHtml, num, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown };&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        this.objDoc.GetType().InvokeMember("SaveAs", BindingFlags.InvokeMethod, null, this.objDoc, objArray);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                catch (Exception exception)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    this._Except = exception;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    this._ReturnCode = 2;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    return 2;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                return 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            this._ReturnCode = 100;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            return 100;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        private void OfficeApplicationsInit()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            this._ReturnCode = 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            this._IsWordInstalled = false;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            this._SavePictureWithDocument = false;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            this._CreateFilesFolder = true;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            this._UpdateLinksOnSave = true;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            this.unknown = Type.Missing;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            this.wordApp = Type.GetTypeFromProgID("Word.Application");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            if (this.wordApp == null)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                this._ReturnCode = 1;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                this._IsWordInstalled = false;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            this.objWordApp = Activator.CreateInstance(this.wordApp);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            this.objWordApp.GetType().InvokeMember("Visible", BindingFlags.SetProperty, null, this.objWordApp, new object[] { false });&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            this.objWordApp.GetType().InvokeMember("DisplayAlerts", BindingFlags.SetProperty, null, this.objWordApp, new object[] { false });&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            this.objDocuments = this.objWordApp.GetType().InvokeMember("Documents", BindingFlags.GetProperty, null, this.objWordApp, null);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            this.objDoc = null;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            this._IsWordInstalled = true;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            this._Version = "";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            if (this._ReturnCode == 0)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                object obj2 = null;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                if (this._IsWordInstalled)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    obj2 = this.objWordApp.GetType().InvokeMember("Version", BindingFlags.GetProperty, null, this.objWordApp, null);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                this._Version = obj2.ToString().Split(new char[] { '.' })[0];&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                if (this.Version == "")&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    this._ReturnCode = 2;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        private int OpenDoc(string fileDoc)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            this._ReturnCode = 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            if ((this.objWordApp != null) &amp;amp;&amp;amp; (this.wordApp != null))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                Exception exception;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                if (this.objDoc != null)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    try&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        object[] args = new object[3];&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        args[0] = false;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        this.objDoc.GetType().InvokeMember("Close", BindingFlags.InvokeMethod, null, this.objDoc, args);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        this.objDoc = null;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    catch (Exception exception1)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        exception = exception1;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        this._Except = exception;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                try&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    object[] objArray;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    if (Convert.ToInt32(this.Version) &lt;= 9)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        objArray = new object[] { fileDoc, this.unknown, false, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown };&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        this.objDoc = this.objDocuments.GetType().InvokeMember("Open", BindingFlags.InvokeMethod, null, this.objDocuments, objArray);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    else if (Convert.ToInt32(this.Version) &lt;= 10)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        objArray = new object[] { fileDoc, this.unknown, false, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown };&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        this.objDoc = this.objDocuments.GetType().InvokeMember("Open", BindingFlags.InvokeMethod, null, this.objDocuments, objArray);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    else&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        objArray = new object[] { fileDoc, this.unknown, true, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown, this.unknown };&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        this.objDoc = this.objDocuments.GetType().InvokeMember("Open", BindingFlags.InvokeMethod, null, this.objDocuments, objArray);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    object target = this.objDoc.GetType().InvokeMember("Range", BindingFlags.InvokeMethod, null, this.objDoc, new object[] { 0, 0 });&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    target.GetType().InvokeMember("Text", BindingFlags.SetProperty, null, target,null);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    Marshal.ReleaseComObject(target);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    target = null;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    if (this._SavePictureWithDocument)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        try&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                            object obj3 = this.objDoc.GetType().InvokeMember("InlineShapes", BindingFlags.GetProperty, null, this.objDoc, null);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                            int num = (int)obj3.GetType().InvokeMember("Count", BindingFlags.GetProperty, null, obj3, null);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                            for (int i = 1; i &lt;= num; i++)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                                object obj4 = obj3.GetType().InvokeMember("Item", BindingFlags.InvokeMethod, null, obj3, new object[] { i });&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                                if (obj4 != null)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                                {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                                    object obj5 = obj4.GetType().InvokeMember("LinkFormat", BindingFlags.GetProperty, null, obj4, null);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                                    if (obj5 != null)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                                    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                                        obj5.GetType().InvokeMember("SavePictureWithDocument", BindingFlags.SetProperty, null, obj5, new object[] { true });&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                                    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                                }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        catch&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    object obj6 = this.objDoc.GetType().InvokeMember("WebOptions", BindingFlags.GetProperty, null, this.objDoc, null);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    obj6.GetType().InvokeMember("OrganizeInFolder", BindingFlags.SetProperty, null, obj6, new object[] { this._CreateFilesFolder });&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    object obj7 = this.objWordApp.GetType().InvokeMember("DefaultWebOptions", BindingFlags.InvokeMethod, null, this.objWordApp, null);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    obj7.GetType().InvokeMember("UpdateLinksOnSave", BindingFlags.SetProperty, null, obj7, new object[] { this._UpdateLinksOnSave });&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    Marshal.ReleaseComObject(obj7);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    obj7 = null;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    Marshal.ReleaseComObject(obj6);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    obj6 = null;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                catch (Exception exception2)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    exception = exception2;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    this._Except = exception;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    this._ReturnCode = 1;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                    return 1;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                return 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            this._ReturnCode = 100;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            return 100;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        private bool CreateFilesFolder&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            get&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                return this._CreateFilesFolder;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            set&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                this._CreateFilesFolder = value;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        private bool IsWordInstalled&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            get&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                return this._IsWordInstalled;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        private int ReturnCode&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            get&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                return this._ReturnCode;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        private bool SavePictureWithDocument&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            get&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                return this._SavePictureWithDocument;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            set&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                this._SavePictureWithDocument = value;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        private bool UpdateLinksOnSave&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            get&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                return this._UpdateLinksOnSave;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            set&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                this._UpdateLinksOnSave = value;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        private string Version&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            get&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;                return this._Version;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-4374045429248508908?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/4374045429248508908/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2010/11/convert-microsoft-word-documents-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/4374045429248508908'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/4374045429248508908'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2010/11/convert-microsoft-word-documents-to.html' title='Convert microsoft word documents to HTML'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-81295245201590674</id><published>2010-11-09T17:49:00.000-08:00</published><updated>2010-11-30T17:06:26.237-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Automatic'/><category scheme='http://www.blogger.com/atom/ns#' term='sql script'/><title type='text'>Auto Generate SIMPLE complete sql procedures</title><content type='html'>&lt;span style="font-weight: bold;"&gt;i modified this script from the source for it to run on SQL server 2008 R2.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;span style="font-weight: bold;"&gt;updated&lt;/span&gt;:&lt;/span&gt; THIS WILL WORK with data types of length MAX&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;-- Author: www.sqlbook.com&lt;br /&gt;-- Modified: Aresh Saharkhiz&lt;br /&gt;-- Copyright: (c) www.sqlbook.com. You are free to use and redistribute&lt;br /&gt;-- this script as long as this comments section with the&lt;br /&gt;-- author and copyright details are not altered.&lt;br /&gt;-- Purpose: For a specified user defined table (or all user defined&lt;br /&gt;-- tables) in the database this script generates 4 Stored&lt;br /&gt;-- Procedure definitions with different Procedure name&lt;br /&gt;-- suffixes:&lt;br /&gt;-- 1) List all records in the table (suffix of _lst)&lt;br /&gt;-- 2) Get a specific record from the table (suffix of _sel)&lt;br /&gt;-- 3) UPDATE or INSERT (UPSERT) - (suffix of _ups)&lt;br /&gt;-- 4) DELETE a specified row - (suffix of _del)&lt;br /&gt;-- e.g. For a table called location the script will create&lt;br /&gt;-- procedure definitions for the following procedures:&lt;br /&gt;-- dbo.udp_Location_lst&lt;br /&gt;-- dbo.udp_Location_sel&lt;br /&gt;-- dbo.udp_Location_ups&lt;br /&gt;-- dbo.udp_Location_del&lt;br /&gt;-- Notes: The stored procedure definitions can either be printed&lt;br /&gt;-- to the screen or executed using EXEC sp_ExecuteSQL.&lt;br /&gt;-- The stored proc names are prefixed with udp_ to avoid&lt;br /&gt;-- conflicts with system stored procs.&lt;br /&gt;-- Assumptions: - This script assumes that the primary key is the first&lt;br /&gt;-- column in the table and that if the primary key is&lt;br /&gt;-- an integer then it is an IDENTITY (autonumber) field.&lt;br /&gt;-- - This script is not suitable for the link tables&lt;br /&gt;-- in the middle of a many to many relationship.&lt;br /&gt;-- - After the script has run you will need to add&lt;br /&gt;-- an ORDER BY clause into the '_lst' procedures&lt;br /&gt;-- according to your needs / required sort order.&lt;br /&gt;-- - Assumes you have set valid values for the&lt;br /&gt;-- config variables in the section immediately below&lt;br /&gt;-- #########################################################&lt;br /&gt;&lt;br /&gt;-- ##########################################################&lt;br /&gt;/* SET CONFIG VARIABLES THAT ARE USED IN SCRIPT */&lt;br /&gt;-- ##########################################################&lt;br /&gt;&lt;br /&gt;-- Do we want to generate the SP definitions for every user defined&lt;br /&gt;-- table in the database or just a single specified table?&lt;br /&gt;-- Assign a blank string - '' for all tables or the table name for&lt;br /&gt;-- a single table.&lt;br /&gt;DECLARE @GenerateProcsFor varchar(100)&lt;br /&gt;--SET @GenerateProcsFor = 'Orders'&lt;br /&gt;SET @GenerateProcsFor = ''&lt;br /&gt;&lt;br /&gt;-- which database do we want to create the procs for?&lt;br /&gt;-- Change both the USE and SET lines below to set the datbase name&lt;br /&gt;-- to the required database.&lt;br /&gt;USE test&lt;br /&gt;DECLARE @DatabaseName varchar(100)&lt;br /&gt;SET @DatabaseName = 'test'&lt;br /&gt;&lt;br /&gt;-- do we want the script to print out the CREATE PROC statements&lt;br /&gt;-- or do we want to execute them to actually create the procs?&lt;br /&gt;-- Assign a value of either 'Print' or 'Execute'&lt;br /&gt;DECLARE @PrintOrExecute varchar(10)&lt;br /&gt;SET @PrintOrExecute = 'Print'&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- Is there a table name prefix i.e. 'tbl_' which we don't want&lt;br /&gt;-- to include in our stored proc names?&lt;br /&gt;DECLARE @TablePrefix varchar(10)&lt;br /&gt;SET @TablePrefix = ''&lt;br /&gt;&lt;br /&gt;-- For our '_lst' and '_sel' procedures do we want to&lt;br /&gt;-- do SELECT * or SELECT [ColumnName,]...&lt;br /&gt;-- Assign a value of either 1 or 0&lt;br /&gt;DECLARE @UseSelectWildCard bit&lt;br /&gt;SET @UseSelectWildCard = 0&lt;br /&gt;&lt;br /&gt;-- ##########################################################&lt;br /&gt;/* END SETTING OF CONFIG VARIABLE&lt;br /&gt;-- do not edit below this line */&lt;br /&gt;-- ##########################################################&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- DECLARE CURSOR containing all columns from user defined tables&lt;br /&gt;-- in the database&lt;br /&gt;DECLARE TableCol Cursor FOR&lt;br /&gt;SELECT c.TABLE_SCHEMA, c.TABLE_NAME, c.COLUMN_NAME, c.DATA_TYPE, c.CHARACTER_MAXIMUM_LENGTH&lt;br /&gt;FROM INFORMATION_SCHEMA.Columns c INNER JOIN&lt;br /&gt;INFORMATION_SCHEMA.Tables t ON c.TABLE_NAME = t.TABLE_NAME&lt;br /&gt;WHERE t.Table_Catalog = @DatabaseName&lt;br /&gt;AND t.TABLE_TYPE = 'BASE TABLE'&lt;br /&gt;ORDER BY c.TABLE_NAME, c.ORDINAL_POSITION&lt;br /&gt;&lt;br /&gt;-- Declare variables which will hold values from cursor rows&lt;br /&gt;DECLARE @TableSchema varchar(100), @TableName varchar(100)&lt;br /&gt;DECLARE @ColumnName varchar(100), @DataType varchar(30)&lt;br /&gt;DECLARE @CharLength varchar(100)&lt;br /&gt;&lt;br /&gt;DECLARE @ColumnNameCleaned varchar(100)&lt;br /&gt;&lt;br /&gt;-- Declare variables which will track what table we are&lt;br /&gt;-- creating Stored Procs for&lt;br /&gt;DECLARE @CurrentTable varchar(100)&lt;br /&gt;DECLARE @FirstTable bit&lt;br /&gt;DECLARE @FirstColumnName varchar(100)&lt;br /&gt;DECLARE @FirstColumnDataType varchar(30)&lt;br /&gt;DECLARE @ObjectName varchar(100) -- this is the tablename with the&lt;br /&gt;-- specified tableprefix lopped off.&lt;br /&gt;DECLARE @TablePrefixLength int&lt;br /&gt;&lt;br /&gt;-- init vars&lt;br /&gt;SET @CurrentTable = ''&lt;br /&gt;SET @FirstTable = 1&lt;br /&gt;SET @TablePrefixLength = Len(@TablePrefix)&lt;br /&gt;&lt;br /&gt;-- Declare variables which will hold the queries we are building use unicode&lt;br /&gt;-- data types so that can execute using sp_ExecuteSQL&lt;br /&gt;DECLARE @LIST nvarchar(4000), @UPSERT nvarchar(4000)&lt;br /&gt;DECLARE @SELECT nvarchar(4000), @INSERT nvarchar(4000), @INSERTVALUES varchar(4000)&lt;br /&gt;DECLARE @UPDATE nvarchar(4000), @DELETE nvarchar(4000)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- open the cursor&lt;br /&gt;OPEN TableCol&lt;br /&gt;&lt;br /&gt;-- get the first row of cursor into variables&lt;br /&gt;FETCH NEXT FROM TableCol INTO @TableSchema, @TableName, @ColumnName, @DataType, @CharLength&lt;br /&gt;&lt;br /&gt;-- loop through the rows of the cursor&lt;br /&gt;WHILE @@FETCH_STATUS = 0 BEGIN&lt;br /&gt;&lt;br /&gt;SET @ColumnNameCleaned = Replace(@ColumnName, ' ', '')&lt;br /&gt;&lt;br /&gt;-- is this a new table?&lt;br /&gt;IF @TableName &lt;&gt; @CurrentTable BEGIN&lt;br /&gt;&lt;br /&gt;-- if is the end of the last table&lt;br /&gt;IF @CurrentTable &lt;&gt; '' BEGIN&lt;br /&gt;IF @GenerateProcsFor = '' OR @GenerateProcsFor = @CurrentTable BEGIN&lt;br /&gt;&lt;br /&gt;-- first add any syntax to end the statement&lt;br /&gt;&lt;br /&gt;-- _lst&lt;br /&gt;SET @LIST = @List + Char(13) + 'FROM ' + @CurrentTable + Char(13)&lt;br /&gt;SET @LIST = @LIST + Char(13) + Char(13) + 'SET NOCOUNT OFF' + Char(13) + Char(13)&lt;br /&gt;SET @LIST = @LIST + Char(13)&lt;br /&gt;&lt;br /&gt;-- _sel&lt;br /&gt;SET @SELECT = @SELECT + Char(13) + 'FROM ' + @CurrentTable + Char(13)&lt;br /&gt;SET @SELECT = @SELECT + 'WHERE [' + @FirstColumnName + '] = @' + Replace(@FirstColumnName, ' ', '') + Char(13)&lt;br /&gt;SET @SELECT = @SELECT + Char(13) + Char(13) + 'SET NOCOUNT OFF' + Char(13) + Char(13)&lt;br /&gt;SET @SELECT = @SELECT + Char(13)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- UPDATE (remove trailing comma and append the WHERE clause)&lt;br /&gt;SET @UPDATE = SUBSTRING(@UPDATE, 0, LEN(@UPDATE)- 1) + Char(13) + Char(9) + 'WHERE [' + @FirstColumnName + '] = @' + Replace(@FirstColumnName, ' ', '') + Char(13)&lt;br /&gt;&lt;br /&gt;-- INSERT&lt;br /&gt;SET @INSERT = SUBSTRING(@INSERT, 0, LEN(@INSERT) - 1) + Char(13) + Char(9) + ')' + Char(13)&lt;br /&gt;SET @INSERTVALUES = SUBSTRING(@INSERTVALUES, 0, LEN(@INSERTVALUES) -1) + Char(13) + Char(9) + ')'&lt;br /&gt;SET @INSERT = @INSERT + @INSERTVALUES&lt;br /&gt;&lt;br /&gt;-- _ups&lt;br /&gt;SET @UPSERT = @UPSERT + Char(13) + 'AS' + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + 'SET NOCOUNT ON' + Char(13)&lt;br /&gt;IF @FirstColumnDataType IN ('int', 'bigint', 'smallint', 'tinyint', 'float', 'decimal')&lt;br /&gt;BEGIN&lt;br /&gt;SET @UPSERT = @UPSERT + 'IF @' + Replace(@FirstColumnName, ' ', '') + ' = 0 BEGIN' + Char(13)&lt;br /&gt;END ELSE BEGIN&lt;br /&gt;SET @UPSERT = @UPSERT + 'IF @' + Replace(@FirstColumnName, ' ', '') + ' = '''' BEGIN' + Char(13)&lt;br /&gt;END&lt;br /&gt;SET @UPSERT = @UPSERT + ISNULL(@INSERT, '') + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + Char(9) + 'SELECT SCOPE_IDENTITY() As InsertedID' + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + 'END' + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + 'ELSE BEGIN' + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + ISNULL(@UPDATE, '') + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + 'END' + Char(13) + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + 'SET NOCOUNT OFF' + Char(13) + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + Char(13)&lt;br /&gt;&lt;br /&gt;-- _del&lt;br /&gt;-- delete proc completed already&lt;br /&gt;&lt;br /&gt;-- --------------------------------------------------&lt;br /&gt;-- now either print the SP definitions or&lt;br /&gt;-- execute the statements to create the procs&lt;br /&gt;-- --------------------------------------------------&lt;br /&gt;IF @PrintOrExecute &lt;&gt; 'Execute' BEGIN&lt;br /&gt;PRINT @LIST&lt;br /&gt;PRINT @SELECT&lt;br /&gt;PRINT @UPSERT&lt;br /&gt;PRINT @DELETE&lt;br /&gt;END ELSE BEGIN&lt;br /&gt;EXEC sp_Executesql @LIST&lt;br /&gt;EXEC sp_Executesql @SELECT&lt;br /&gt;EXEC sp_Executesql @UPSERT&lt;br /&gt;EXEC sp_Executesql @DELETE&lt;br /&gt;END&lt;br /&gt;END -- end @GenerateProcsFor = '' OR @GenerateProcsFor = @CurrentTable&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;-- update the value held in @CurrentTable&lt;br /&gt;SET @CurrentTable = @TableName&lt;br /&gt;SET @FirstColumnName = @ColumnName&lt;br /&gt;SET @FirstColumnDataType = @DataType&lt;br /&gt;&lt;br /&gt;IF @TablePrefixLength &gt; 0 BEGIN&lt;br /&gt;IF SUBSTRING(@CurrentTable, 1, @TablePrefixLength) = @TablePrefix BEGIN&lt;br /&gt;PRINT Char(13) + 'DEBUG: OBJ NAME: ' + RIGHT(@CurrentTable, LEN(@CurrentTable) - @TablePrefixLength)&lt;br /&gt;SET @ObjectName = RIGHT(@CurrentTable, LEN(@CurrentTable) - @TablePrefixLength)&lt;br /&gt;END ELSE BEGIN&lt;br /&gt;SET @ObjectName = @CurrentTable&lt;br /&gt;END&lt;br /&gt;END ELSE BEGIN&lt;br /&gt;SET @ObjectName = @CurrentTable&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;IF @GenerateProcsFor = '' OR @GenerateProcsFor = @CurrentTable BEGIN&lt;br /&gt;&lt;br /&gt;-- ----------------------------------------------------&lt;br /&gt;-- now start building the procedures for the next table&lt;br /&gt;-- ----------------------------------------------------&lt;br /&gt;&lt;br /&gt;-- _lst&lt;br /&gt;SET @LIST = 'CREATE PROCEDURE [dbo].[udp_' + @ObjectName + '_lst]' + Char(13)&lt;br /&gt;SET @LIST = @LIST + 'AS' + Char(13)&lt;br /&gt;SET @LIST = @LIST + 'SET NOCOUNT ON' + Char(13)&lt;br /&gt;IF @UseSelectWildcard = 1 BEGIN&lt;br /&gt;SET @LIST = @LIST + Char(13) + 'SELECT * '&lt;br /&gt;END&lt;br /&gt;ELSE BEGIN&lt;br /&gt;SET @LIST = @LIST + Char(13) + 'SELECT [' + @ColumnName + ']'&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;-- _sel&lt;br /&gt;SET @SELECT = 'CREATE PROCEDURE [dbo].[udp_' + @ObjectName + '_sel]' + Char(13)&lt;br /&gt;SET @SELECT = @SELECT + Char(9) + '@' + @ColumnNameCleaned + ' ' + @DataType&lt;br /&gt;IF @DataType IN ('varchar', 'nvarchar', 'char', 'nchar') BEGIN&lt;br /&gt;   IF @CharLength = -1 BEGIN&lt;br /&gt;    SET @SELECT = @SELECT + '(MAX)'&lt;br /&gt;    END&lt;br /&gt;   ELSE BEGIN&lt;br /&gt;   SET @SELECT = @SELECT + '(' + CAST(@CharLength As varchar(100)) + ')'&lt;br /&gt;   END&lt;br /&gt; END&lt;br /&gt;SET @SELECT = @SELECT + Char(13) + 'AS' + Char(13)&lt;br /&gt;SET @SELECT = @SELECT + 'SET NOCOUNT ON' + Char(13)&lt;br /&gt;IF @UseSelectWildcard = 1 BEGIN&lt;br /&gt;SET @SELECT = @SELECT + Char(13) + 'SELECT * '&lt;br /&gt;END&lt;br /&gt;ELSE BEGIN&lt;br /&gt;SET @SELECT = @SELECT + Char(13) + 'SELECT [' + @ColumnName + ']'&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;-- _ups&lt;br /&gt;SET @UPSERT = 'CREATE PROCEDURE [dbo].[udp_' + @ObjectName + '_ups]' + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + Char(13) + Char(9) + '@' + @ColumnNameCleaned + ' ' + @DataType&lt;br /&gt;IF @DataType IN ('varchar', 'nvarchar', 'char', 'nchar') BEGIN&lt;br /&gt;IF @CharLength = -1 BEGIN&lt;br /&gt;    SET @UPSERT = @UPSERT + '(MAX)'&lt;br /&gt;    END&lt;br /&gt;   ELSE BEGIN&lt;br /&gt;   SET @UPSERT = @UPSERT + '(' + CAST(@CharLength As Varchar(10)) + ')'&lt;br /&gt;   END&lt;br /&gt;&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;-- UPDATE&lt;br /&gt;SET @UPDATE = Char(9) + 'UPDATE ' + @TableName + ' SET ' + Char(13)&lt;br /&gt;&lt;br /&gt;-- INSERT -- don't add first column to insert if it is an&lt;br /&gt;-- integer (assume autonumber)&lt;br /&gt;SET @INSERT = Char(9) + 'INSERT INTO ' + @TableName + ' (' + Char(13)&lt;br /&gt;SET @INSERTVALUES = Char(9) + 'VALUES (' + Char(13)&lt;br /&gt;&lt;br /&gt;IF @FirstColumnDataType NOT IN ('int', 'bigint', 'smallint', 'tinyint')&lt;br /&gt;BEGIN&lt;br /&gt;SET @INSERT = @INSERT + Char(9) + Char(9) + '[' + @ColumnName + '],' + Char(13)&lt;br /&gt;SET @INSERTVALUES = @INSERTVALUES + Char(9) + Char(9) + '@' + @ColumnNameCleaned + ',' + Char(13)&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;-- _del&lt;br /&gt;SET @DELETE = 'CREATE PROCEDURE [dbo].[udp_' + @ObjectName + '_del]' + Char(13)&lt;br /&gt;SET @DELETE = @DELETE + Char(9) + '@' + @ColumnNameCleaned + ' ' + @DataType&lt;br /&gt;IF @DataType IN ('varchar', 'nvarchar', 'char', 'nchar') BEGIN&lt;br /&gt;IF @CharLength = -1 BEGIN&lt;br /&gt;    SET @DELETE = @DELETE + '(MAX)'&lt;br /&gt;    END&lt;br /&gt;   ELSE BEGIN&lt;br /&gt;   SET @DELETE = @DELETE + '(' + CAST(@CharLength As Varchar(10)) + ')'&lt;br /&gt;   END&lt;br /&gt;&lt;br /&gt;END&lt;br /&gt;SET @DELETE = @DELETE + Char(13) + 'AS' + Char(13)&lt;br /&gt;SET @DELETE = @DELETE + 'SET NOCOUNT ON' + Char(13) + Char(13)&lt;br /&gt;SET @DELETE = @DELETE + 'DELETE FROM ' + @TableName + Char(13)&lt;br /&gt;SET @DELETE = @DELETE + 'WHERE [' + @ColumnName + '] = @' + @ColumnNameCleaned + Char(13)&lt;br /&gt;SET @DELETE = @DELETE + Char(13) + 'SET NOCOUNT OFF' + Char(13)&lt;br /&gt;SET @DELETE = @DELETE + Char(13)&lt;br /&gt;&lt;br /&gt;END -- end @GenerateProcsFor = '' OR @GenerateProcsFor = @CurrentTable&lt;br /&gt;END&lt;br /&gt;ELSE BEGIN&lt;br /&gt;IF @GenerateProcsFor = '' OR @GenerateProcsFor = @CurrentTable BEGIN&lt;br /&gt;&lt;br /&gt;-- is the same table as the last row of the cursor&lt;br /&gt;-- just append the column&lt;br /&gt;&lt;br /&gt;-- _lst&lt;br /&gt;IF @UseSelectWildCard = 0 BEGIN&lt;br /&gt;SET @LIST = @LIST + ', ' + Char(13) + Char(9) + '[' + @ColumnName + ']'&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;-- _sel&lt;br /&gt;IF @UseSelectWildCard = 0 BEGIN&lt;br /&gt;SET @SELECT = @SELECT + ', ' + Char(13) + Char(9) + '[' + @ColumnName + ']'&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;-- _ups&lt;br /&gt;SET @UPSERT = @UPSERT + ',' + Char(13) + Char(9) + '@' + @ColumnNameCleaned + ' ' + @DataType&lt;br /&gt;IF @DataType IN ('varchar', 'nvarchar', 'char', 'nchar') BEGIN&lt;br /&gt;SET @UPSERT = @UPSERT + '(' + CAST(@CharLength As varchar(10)) + ')'&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;-- UPDATE&lt;br /&gt;SET @UPDATE = @UPDATE + Char(9) + Char(9) + '[' + @ColumnName + '] = @' + @ColumnNameCleaned + ',' + Char(13)&lt;br /&gt;&lt;br /&gt;-- INSERT&lt;br /&gt;SET @INSERT = @INSERT + Char(9) + Char(9) + '[' + @ColumnName + '],' + Char(13)&lt;br /&gt;SET @INSERTVALUES = @INSERTVALUES + Char(9) + Char(9) + '@' + @ColumnNameCleaned + ',' + Char(13)&lt;br /&gt;&lt;br /&gt;-- _del&lt;br /&gt;-- delete proc completed already&lt;br /&gt;END -- end @GenerateProcsFor = '' OR @GenerateProcsFor = @CurrentTable'&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;-- fetch next row of cursor into variables&lt;br /&gt;FETCH NEXT FROM TableCol INTO @TableSchema, @TableName, @ColumnName, @DataType, @CharLength&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;-- ----------------&lt;br /&gt;-- clean up cursor&lt;br /&gt;-- ----------------&lt;br /&gt;CLOSE TableCol&lt;br /&gt;DEALLOCATE TableCol&lt;br /&gt;&lt;br /&gt;-- ------------------------------------------------&lt;br /&gt;-- repeat the block of code from within the cursor&lt;br /&gt;-- So that the last table has its procs completed&lt;br /&gt;-- and printed / executed&lt;br /&gt;-- ------------------------------------------------&lt;br /&gt;&lt;br /&gt;-- if is the end of the last table&lt;br /&gt;IF @CurrentTable &lt;&gt; '' BEGIN&lt;br /&gt;IF @GenerateProcsFor = '' OR @GenerateProcsFor = @CurrentTable BEGIN&lt;br /&gt;&lt;br /&gt;-- first add any syntax to end the statement&lt;br /&gt;&lt;br /&gt;-- _lst&lt;br /&gt;SET @LIST = @List + Char(13) + 'FROM ' + @CurrentTable + Char(13)&lt;br /&gt;SET @LIST = @LIST + Char(13) + Char(13) + 'SET NOCOUNT OFF' + Char(13)&lt;br /&gt;SET @LIST = @LIST + Char(13)&lt;br /&gt;&lt;br /&gt;-- _sel&lt;br /&gt;SET @SELECT = @SELECT + Char(13) + 'FROM ' + @CurrentTable + Char(13)&lt;br /&gt;SET @SELECT = @SELECT + 'WHERE [' + @FirstColumnName + '] = @' + Replace(@FirstColumnName, ' ', '') + Char(13)&lt;br /&gt;SET @SELECT = @SELECT + Char(13) + Char(13) + 'SET NOCOUNT OFF' + Char(13)&lt;br /&gt;SET @SELECT = @SELECT + Char(13)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- UPDATE (remove trailing comma and append the WHERE clause)&lt;br /&gt;SET @UPDATE = SUBSTRING(@UPDATE, 0, LEN(@UPDATE)- 1) + Char(13) + Char(9) + 'WHERE [' + @FirstColumnName + '] = @' + Replace(@FirstColumnName, ' ', '') + Char(13)&lt;br /&gt;&lt;br /&gt;-- INSERT&lt;br /&gt;SET @INSERT = SUBSTRING(@INSERT, 0, LEN(@INSERT) - 1) + Char(13) + Char(9) + ')' + Char(13)&lt;br /&gt;SET @INSERTVALUES = SUBSTRING(@INSERTVALUES, 0, LEN(@INSERTVALUES) -1) + Char(13) + Char(9) + ')'&lt;br /&gt;SET @INSERT = @INSERT + @INSERTVALUES&lt;br /&gt;&lt;br /&gt;-- _ups&lt;br /&gt;SET @UPSERT = @UPSERT + Char(13) + 'AS' + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + 'SET NOCOUNT ON' + Char(13)&lt;br /&gt;IF @FirstColumnDataType IN ('int', 'bigint', 'smallint', 'tinyint', 'float', 'decimal')&lt;br /&gt;BEGIN&lt;br /&gt;SET @UPSERT = @UPSERT + 'IF @' + Replace(@FirstColumnName, ' ', '') + ' = 0 BEGIN' + Char(13)&lt;br /&gt;END ELSE BEGIN&lt;br /&gt;SET @UPSERT = @UPSERT + 'IF @' + Replace(@FirstColumnName, ' ', '') + ' = '''' BEGIN' + Char(13)&lt;br /&gt;END&lt;br /&gt;SET @UPSERT = @UPSERT + ISNULL(@INSERT, '') + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + Char(9) + 'SELECT SCOPE_IDENTITY() As InsertedID' + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + 'END' + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + 'ELSE BEGIN' + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + ISNULL(@UPDATE, '') + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + 'END' + Char(13) + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + 'SET NOCOUNT OFF' + Char(13)&lt;br /&gt;SET @UPSERT = @UPSERT + Char(13)&lt;br /&gt;&lt;br /&gt;-- _del&lt;br /&gt;-- delete proc completed already&lt;br /&gt;&lt;br /&gt;-- --------------------------------------------------&lt;br /&gt;-- now either print the SP definitions or&lt;br /&gt;-- execute the statements to create the procs&lt;br /&gt;-- --------------------------------------------------&lt;br /&gt;IF @PrintOrExecute &lt;&gt; 'Execute' BEGIN&lt;br /&gt;PRINT @LIST&lt;br /&gt;PRINT @SELECT&lt;br /&gt;PRINT @UPSERT&lt;br /&gt;PRINT @DELETE&lt;br /&gt;END ELSE BEGIN&lt;br /&gt;EXEC sp_Executesql @LIST&lt;br /&gt;EXEC sp_Executesql @SELECT&lt;br /&gt;EXEC sp_Executesql @UPSERT&lt;br /&gt;EXEC sp_Executesql @DELETE&lt;br /&gt;END&lt;br /&gt;END -- end @GenerateProcsFor = '' OR @GenerateProcsFor = @CurrentTable&lt;br /&gt;END &lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-81295245201590674?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/81295245201590674/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2010/11/auto-generate-simple-complete-sql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/81295245201590674'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/81295245201590674'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2010/11/auto-generate-simple-complete-sql.html' title='Auto Generate SIMPLE complete sql procedures'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-8566565240156763193</id><published>2010-10-19T20:39:00.000-07:00</published><updated>2010-10-19T21:09:58.615-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='template'/><category scheme='http://www.blogger.com/atom/ns#' term='content management system'/><category scheme='http://www.blogger.com/atom/ns#' term='CMS'/><title type='text'>ATS my own Content Mangement System in ASP.NET 4.0 (Part 1)</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_lYg70zdQa3I/TL5rK0-2OWI/AAAAAAAAAic/glyxkZhcIO8/s1600/im1.JPG"&gt;&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;This is part 1 of a series of tutorials ive decided to write on CMS. this will be my 3rd CMS. i started with .net version 1.1 and 2.0 then moved to 3.0 and 3.5 and now 4.0&lt;br /&gt;&lt;br /&gt;my first CMS made use of dynamic templates loaded from the database and the content of the templates were placed inside each place in the template using javascript. The advantage was that the templates could be edited in any way...as long as you placed the right DIV the content would jump inside the template in the browser. the disadvantage was when you made a mistake in loading the DIV or you wanted to extend the content to add more&lt;br /&gt;&lt;br /&gt;in the second CMS i made use of master pages and created a structure, the structure would load custom user controls that were the content of the page. the disadvantage was templates should be pre-created. i had to create a complete structure of a template before i could fill it up that means placeholders had to be there and uploading the master page was a drag&lt;br /&gt;&lt;br /&gt;this version im going to be creating a combination of both, a master page that can be loaded from the database and content as custom user controls placed in the template during run time&lt;br /&gt;&lt;br /&gt;for this tutorial im going to start with creating a dynamic template loaded from the database&lt;br /&gt;im using visual studio professional with .net Framework 4.0&lt;br /&gt;&lt;br /&gt;Step 1: Create a master page and default page  and remove all the contents of the master page&lt;a href="http://2.bp.blogspot.com/_lYg70zdQa3I/TL5mjGvJG2I/AAAAAAAAAh8/kySy0CvAM6I/s1600/im1.JPG"&gt;&lt;img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 191px;" src="http://2.bp.blogspot.com/_lYg70zdQa3I/TL5mjGvJG2I/AAAAAAAAAh8/kySy0CvAM6I/s320/im1.JPG" alt="" id="BLOGGER_PHOTO_ID_5529970145747344226" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Step 2: Create a default page and remove all the contents aswell&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_lYg70zdQa3I/TL5m_qHIKOI/AAAAAAAAAiE/zYUc2TCrreE/s1600/im1.JPG"&gt;&lt;img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 184px;" src="http://3.bp.blogspot.com/_lYg70zdQa3I/TL5m_qHIKOI/AAAAAAAAAiE/zYUc2TCrreE/s320/im1.JPG" alt="" id="BLOGGER_PHOTO_ID_5529970636279523554" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Step 3 create a class file under the upcode and name it master, change  the master pages extended option in the code behind to the name of that file&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_lYg70zdQa3I/TL5nPo718dI/AAAAAAAAAiM/10TS6xcwUxo/s1600/im1.JPG"&gt;&lt;img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 184px;" src="http://4.bp.blogspot.com/_lYg70zdQa3I/TL5nPo718dI/AAAAAAAAAiM/10TS6xcwUxo/s320/im1.JPG" alt="" id="BLOGGER_PHOTO_ID_5529970910841663954" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Step  4: Time to code our master page&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;//START HERE&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt; using System;&lt;br /&gt;&lt;br /&gt; using System.Collections.Generic;&lt;br /&gt;&lt;br /&gt; using System.Linq;&lt;br /&gt;&lt;br /&gt; using System.Text;&lt;br /&gt;&lt;br /&gt; using System.Web.UI.WebControls;&lt;br /&gt;&lt;br /&gt; using System.Web.UI.HtmlControls;&lt;br /&gt;&lt;br /&gt; using System.Web.UI;&lt;br /&gt;&lt;br /&gt; using System.Data.SqlClient;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; namespace atsLibrary &lt;span style="color: rgb(204, 0, 0);"&gt;///you can name this anything you want&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; {&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     /// Basic master&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     public class Master : System.Web.UI.MasterPage&lt;br /&gt;&lt;br /&gt;     {&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;///im enumerating my placeholders incase i want to add more &lt;/span&gt;&lt;br /&gt;         private enum MyPlaceHolders&lt;br /&gt;&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;             banner,&lt;br /&gt;&lt;br /&gt;             leftnav,&lt;br /&gt;&lt;br /&gt;             bodymain,&lt;br /&gt;&lt;br /&gt;             rightnav,&lt;br /&gt;&lt;br /&gt;             footer&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;         public Master()&lt;br /&gt;&lt;br /&gt;             : base()&lt;br /&gt;&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;             base.AppRelativeVirtualPath = "~/Master.Master";&lt;br /&gt;&lt;br /&gt;             Array PlaceHolderItems = Enum.GetValues(typeof(MyPlaceHolders));&lt;br /&gt;&lt;br /&gt;             foreach(MyPlaceHolders i  in PlaceHolderItems)&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 base.ContentPlaceHolders.Add(i.ToString());&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         private HtmlHead _head;&lt;br /&gt;&lt;br /&gt;         public HtmlHead Head&lt;br /&gt;&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;             get&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 return _head;&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;             private set&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 _head = value;&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         private HtmlTitle _title;&lt;br /&gt;&lt;br /&gt;         public string Title&lt;br /&gt;&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;             get&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 return _title.Text;&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;             set&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 _title.Text = value;&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         private HtmlForm _form;&lt;br /&gt;&lt;br /&gt;         public HtmlForm Form&lt;br /&gt;&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;             get&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 return _form;&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;             private set&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 _form = value;&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;         public Panel DefaultTopNavigationPanel { get; private set; }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         protected override void FrameworkInitialize()&lt;br /&gt;&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;             base.FrameworkInitialize();&lt;br /&gt;&lt;br /&gt;             Controls.Add(new LiteralControl("\r\n\r\n&amp;lt;!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"&amp;gt;\r\n\r\n&amp;lt;html xmlns=\"http://www.w3.org/1999/xhtml\" &amp;gt;\r\n"));&lt;br /&gt;&lt;br /&gt;             Head = new HtmlHead("head");&lt;br /&gt;&lt;br /&gt;             _title = new HtmlTitle();&lt;br /&gt;&lt;br /&gt;             Head.Controls.Add(_title);&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             var headContentPlaceHolder = new ContentPlaceHolder();&lt;br /&gt;&lt;br /&gt;             headContentPlaceHolder.ID = "head";&lt;br /&gt;&lt;br /&gt;             ITemplate templateHead = null;&lt;br /&gt;&lt;br /&gt;             if (base.ContentTemplates != null)&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 templateHead = (ITemplate)base.ContentTemplates["head"];&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;             if (templateHead != null)&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 templateHead.InstantiateIn(headContentPlaceHolder);&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;             Head.Controls.Add(headContentPlaceHolder);&lt;br /&gt;&lt;br /&gt;             Controls.Add(Head);&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             Controls.Add(new LiteralControl("\r\n&amp;lt;body&amp;gt;\r\n"));&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             Form = new HtmlForm();&lt;br /&gt;&lt;br /&gt;             Form.ID = "aspnetForm";&lt;br /&gt;&lt;br /&gt;             Controls.Add(Form);&lt;br /&gt;&lt;br /&gt;             var contentPlaceHolderContainer = new Panel&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 CssClass = "main"&lt;br /&gt;&lt;br /&gt;             };&lt;br /&gt;&lt;br /&gt;             Form.Controls.Add(contentPlaceHolderContainer);&lt;br /&gt;&lt;br /&gt; &lt;span style="color: rgb(153, 0, 0);"&gt;            ///------i want to get a template from the database--------&lt;/span&gt;&lt;/p&gt;&lt;p style="color: rgb(153, 0, 0);"&gt;///the template can contain this&lt;/p&gt;&lt;p&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;///&lt;br /&gt;test me &lt;con&gt; content after the place holder &lt;con&gt;&lt;br /&gt;&lt;/con&gt;&lt;/con&gt;&lt;/span&gt;&lt;br /&gt;             object result = null;&lt;br /&gt;&lt;br /&gt;             using (SqlConnection dbConn = connectionManager.getSqlConn())&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;                 String sql = "Select templateContent from tbl_atsTemplate";&lt;br /&gt;&lt;br /&gt;                 SqlCommand newsComm = new SqlCommand(sql, dbConn);&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;                 result = newsComm.ExecuteScalar();&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;             String myResult = result.ToString();&lt;br /&gt;&lt;br /&gt;             string[] separator = new string[] { "&amp;lt;con&amp;gt;" };&lt;/p&gt;&lt;p&gt; &lt;span style="color: rgb(204, 0, 0);"&gt;///replace any con with a placeholder&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;             String[] splotArr = myResult.Split(separator, StringSplitOptions.RemoveEmptyEntries);&lt;br /&gt;&lt;br /&gt;             Array PlaceHolderItems = Enum.GetValues(typeof(MyPlaceHolders));&lt;br /&gt;&lt;br /&gt;             int i = 0;&lt;br /&gt;&lt;br /&gt;             foreach (string arrStr in splotArr)&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;                 contentPlaceHolderContainer.Controls.Add(new LiteralControl(arrStr.ToString()));&lt;br /&gt;&lt;br /&gt;                 ContentPlaceHolder SpecificContentPlaceHolder = new ContentPlaceHolder();&lt;br /&gt;&lt;br /&gt;                 String PlaceHolderName = PlaceHolderItems.GetValue(i).ToString();&lt;br /&gt;&lt;br /&gt;                 SpecificContentPlaceHolder.ID = PlaceHolderName;&lt;br /&gt;&lt;br /&gt;                 ITemplate templateSpecific = null;&lt;br /&gt;&lt;br /&gt;                 if (base.ContentTemplates != null)&lt;br /&gt;&lt;br /&gt;                 {&lt;br /&gt;&lt;br /&gt;                     templateSpecific = (ITemplate)base.ContentTemplates[PlaceHolderName];&lt;br /&gt;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt;                 if (templateSpecific != null)&lt;br /&gt;&lt;br /&gt;                 {&lt;br /&gt;&lt;br /&gt;                     templateSpecific.InstantiateIn(SpecificContentPlaceHolder);&lt;br /&gt;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt;                 contentPlaceHolderContainer.Controls.Add(SpecificContentPlaceHolder);&lt;br /&gt;&lt;br /&gt;                 i++;&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;     &lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             InternalFrameworkInitialize();&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             Form.Controls.Add(new LiteralControl("\r\n    &amp;lt;/div&amp;gt;\r\n    "));&lt;br /&gt;&lt;br /&gt;             Controls.Add(new LiteralControl("\r\n&amp;lt;/body&amp;gt;\r\n&amp;lt;/html&amp;gt;\r\n"));&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         /// method to add master specific controls from within inheriting masters&lt;br /&gt;&lt;br /&gt;         protected virtual void InternalFrameworkInitialize() { }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt; }&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;//END HERE&lt;br /&gt;&lt;/blockquote&gt;Step 5: either override the content place holders on leave them blank&lt;br /&gt;if you override you will get new content&lt;br /&gt;&lt;br /&gt;EXAMPLE:&lt;a href="http://2.bp.blogspot.com/_lYg70zdQa3I/TL5rK0-2OWI/AAAAAAAAAic/glyxkZhcIO8/s1600/im1.JPG"&gt;&lt;img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 172px;" src="http://2.bp.blogspot.com/_lYg70zdQa3I/TL5rK0-2OWI/AAAAAAAAAic/glyxkZhcIO8/s320/im1.JPG" alt="" id="BLOGGER_PHOTO_ID_5529975226222655842" border="0" /&gt;&lt;/a&gt;OUTPUT:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_lYg70zdQa3I/TL5qvyLASjI/AAAAAAAAAiU/Fw63DAWrYBU/s1600/im1.JPG"&gt;&lt;img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 176px;" src="http://4.bp.blogspot.com/_lYg70zdQa3I/TL5qvyLASjI/AAAAAAAAAiU/Fw63DAWrYBU/s320/im1.JPG" alt="" id="BLOGGER_PHOTO_ID_5529974761611872818" border="0" /&gt;&lt;/a&gt;you can see all the &lt;con&gt; were replaced by content place holders&lt;br /&gt;&lt;br /&gt;OUTCOME: given this a complete template can be placed in the database.  and internal parts of the a template can be changed using other controls. Part 2 will explain how to load these controls also coming from the database.&lt;br /&gt;&lt;br /&gt;&lt;/con&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-8566565240156763193?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/8566565240156763193/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2010/10/ats-my-own-content-mangement-system-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/8566565240156763193'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/8566565240156763193'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2010/10/ats-my-own-content-mangement-system-in.html' title='ATS my own Content Mangement System in ASP.NET 4.0 (Part 1)'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_lYg70zdQa3I/TL5mjGvJG2I/AAAAAAAAAh8/kySy0CvAM6I/s72-c/im1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-1777556980523931806</id><published>2010-08-22T05:48:00.000-07:00</published><updated>2010-08-22T06:56:59.231-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='export'/><category scheme='http://www.blogger.com/atom/ns#' term='blender'/><category scheme='http://www.blogger.com/atom/ns#' term='md2'/><title type='text'>Convert a blender model to an MD2 Format</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/THEq-icjhII/AAAAAAAAAdU/1o3WyJbJv7w/s1600/untitled3.JPG"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/THEe6DgQJxI/AAAAAAAAAc0/MhQQ3mCPmsQ/s1600/untitled.JPG"&gt;&lt;img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 400px; height: 286px;" src="http://4.bp.blogspot.com/_lYg70zdQa3I/THEe6DgQJxI/AAAAAAAAAc0/MhQQ3mCPmsQ/s400/untitled.JPG" alt="" id="BLOGGER_PHOTO_ID_5508217801972655890" border="0" /&gt;&lt;/a&gt;MD2 is a model format used by id Software's id Tech 2 engine and is thus  used by Quake II  as well as many other games, most of them using this  engine, including SiN and Soldier of Fortune.&lt;br /&gt;&lt;br /&gt;The format is  primarily used for animated player models although it can also be used  for static models.&lt;br /&gt;&lt;br /&gt;Blender automatically exports 199 frames (in Md2) unless you load a  framelist.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;USING BLENDER 2.49b&lt;/span&gt;&lt;br /&gt;Problem exporting to MD2 format:&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_lYg70zdQa3I/THEe6oXpe6I/AAAAAAAAAc8/R073Az9f8ew/s1600/untitled2.JPG"&gt;&lt;img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 400px; height: 220px;" src="http://3.bp.blogspot.com/_lYg70zdQa3I/THEe6oXpe6I/AAAAAAAAAc8/R073Az9f8ew/s400/untitled2.JPG" alt="" id="BLOGGER_PHOTO_ID_5508217811868679074" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Title: &lt;b&gt;Blender 2.49b Bugfix Release&lt;br /&gt;&lt;/b&gt;* Quake MD2 Export, Fix for vertex normals [patch #19206]&lt;br /&gt;&lt;br /&gt;so its already fixed...what to do?&lt;br /&gt;&lt;span style="font-size:130%;"&gt;md2 requires the whole model be a single object &amp;amp; everything must be  assigned a UV&lt;/span&gt;&lt;br /&gt;Follow this tutorial to make it happen and try to convert again.&lt;br /&gt;&lt;br /&gt;http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro/UV_Map_Basics&lt;br /&gt;&lt;br /&gt;Remember each Vertex should have an image... that means selecting a face and then moving the vertex based on the view&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/THErhW7MswI/AAAAAAAAAdk/vo3K1fPipHU/s1600/untitled5.JPG"&gt;&lt;img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 400px; height: 300px;" src="http://1.bp.blogspot.com/_lYg70zdQa3I/THErhW7MswI/AAAAAAAAAdk/vo3K1fPipHU/s400/untitled5.JPG" alt="" id="BLOGGER_PHOTO_ID_5508231671340380930" border="0" /&gt;&lt;/a&gt;After loading an image and moving the vertex of each face:&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/THEq-icjhII/AAAAAAAAAdU/1o3WyJbJv7w/s1600/untitled3.JPG"&gt;&lt;img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 400px; height: 300px;" src="http://1.bp.blogspot.com/_lYg70zdQa3I/THEq-icjhII/AAAAAAAAAdU/1o3WyJbJv7w/s400/untitled3.JPG" alt="" id="BLOGGER_PHOTO_ID_5508231073137656962" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;you can now convert to MD2... you will notice the command window showing the details of the conversion&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/THEq-2sK3gI/AAAAAAAAAdc/7d0xjJokfe8/s1600/untitled4.JPG"&gt;&lt;img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 400px; height: 300px;" src="http://1.bp.blogspot.com/_lYg70zdQa3I/THEq-2sK3gI/AAAAAAAAAdc/7d0xjJokfe8/s400/untitled4.JPG" alt="" id="BLOGGER_PHOTO_ID_5508231078571859458" border="0" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-1777556980523931806?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/1777556980523931806/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2010/08/convert-blender-model-to-md2-format.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/1777556980523931806'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/1777556980523931806'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2010/08/convert-blender-model-to-md2-format.html' title='Convert a blender model to an MD2 Format'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_lYg70zdQa3I/THEe6DgQJxI/AAAAAAAAAc0/MhQQ3mCPmsQ/s72-c/untitled.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-7519504685747839991</id><published>2010-04-16T03:20:00.000-07:00</published><updated>2010-04-16T03:22:54.520-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='blender'/><title type='text'>Blender Hot key Cheat sheet</title><content type='html'>http://www.blender.org/&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;                                      &lt;table border="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td width="50%"&gt;&lt;table border="1" width="100%"&gt;                 &lt;tbody&gt;&lt;tr&gt;                   &lt;td colspan="2"&gt;&lt;div class="p7AB" align="center"&gt;&lt;strong&gt;UNIVERSAL&lt;/strong&gt;&lt;/div&gt;&lt;/td&gt;                   &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td width="20%"&gt;ESC&lt;/td&gt;                   &lt;td width="80%"&gt;Stops Ongoing Procedure&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;SPACE&lt;/td&gt;                   &lt;td&gt;Opens Toolbox&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;TAB&lt;/td&gt;                   &lt;td&gt;Toggles Edit/Object Mode&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;CTRL-Z&lt;/td&gt;                   &lt;td&gt;Undo&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;CTRL-Y&lt;/td&gt;                   &lt;td&gt;Redo&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;ALT-U&lt;/td&gt;                   &lt;td&gt;Undo Menu&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;CTRL-W&lt;/td&gt;                   &lt;td&gt;Save File&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;F1&lt;/td&gt;                   &lt;td&gt;Open File&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;F2&lt;/td&gt;                   &lt;td&gt;Save File&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;F3&lt;/td&gt;                   &lt;td&gt;Save Rendered Image&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;F4&lt;/td&gt;                   &lt;td&gt;Logic Buttons&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;F5&lt;/td&gt;                   &lt;td&gt;Shading Buttons&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;F6&lt;/td&gt;                   &lt;td&gt;Texture Buttons&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;F7&lt;/td&gt;                   &lt;td&gt;Object Buttons&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;F8&lt;/td&gt;                   &lt;td&gt;World Buttons&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;F9&lt;/td&gt;                   &lt;td&gt;Editing Buttons&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;F10&lt;/td&gt;                   &lt;td&gt;Scene Buttons&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;F11&lt;/td&gt;                   &lt;td&gt;Show/Hide Rendering&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;F12&lt;/td&gt;                   &lt;td&gt;Starts Rendering&lt;/td&gt;                 &lt;/tr&gt;                &lt;/tbody&gt;&lt;/table&gt;                 &lt;table border="1" width="100%"&gt;                   &lt;tbody&gt;&lt;tr&gt;                     &lt;td colspan="2"&gt;&lt;div class="p7AB" align="center"&gt;&lt;strong&gt;Modeling&lt;/strong&gt;&lt;/div&gt;&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td width="22%"&gt;IKEY&lt;/td&gt;                     &lt;td width="78%"&gt;Insert Keyframe&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;ALT-C&lt;/td&gt;                     &lt;td&gt;Convert Menu&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;SHIFT-D&lt;/td&gt;                     &lt;td&gt;Duplicate&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;NKEY&lt;/td&gt;                     &lt;td&gt;Object Properties Panel&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;CTRL-J&lt;/td&gt;                     &lt;td&gt;Join Objects&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;ALT-J&lt;/td&gt;                     &lt;td&gt;Join Faces&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;PKEY&lt;/td&gt;                     &lt;td&gt;Separate&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;MKEY&lt;/td&gt;                     &lt;td&gt;Layer Menu&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;CTRL-P&lt;/td&gt;                     &lt;td&gt;Parent&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;ALT-P&lt;/td&gt;                     &lt;td&gt;Clears Parent&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;WKEY&lt;/td&gt;                     &lt;td&gt;Specials Menu&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;XKEY&lt;/td&gt;                     &lt;td&gt;Delete&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;CTRL-H&lt;/td&gt;                     &lt;td&gt;Hooks Verticies&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;OKEY&lt;/td&gt;                     &lt;td&gt;Proportional Editing&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;EKEY&lt;/td&gt;                     &lt;td&gt;Extrude Menu&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;CTRL-N&lt;/td&gt;                     &lt;td&gt;Align Face Normals&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;FKEY&lt;/td&gt;                     &lt;td&gt;Make Face/Edge&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;KKEY&lt;/td&gt;                     &lt;td&gt;Knife Tool&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;CTRL-LMB&lt;/td&gt;                     &lt;td&gt;Create New Vertex&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;SHIFT-R&lt;/td&gt;                     &lt;td&gt;Face Loop Selection&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;CTRL-E&lt;/td&gt;                     &lt;td&gt;Edge Specials Menu&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;SHIFT-M&lt;/td&gt;                     &lt;td&gt;Mirror Menu&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt; &lt;/td&gt;                     &lt;td&gt; &lt;/td&gt;                   &lt;/tr&gt;                 &lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;               &lt;td width="50%"&gt;&lt;table border="1" width="100%"&gt;                 &lt;tbody&gt;&lt;tr&gt;                   &lt;td colspan="2"&gt;&lt;div class="p7AB" align="center"&gt;Navigation&lt;/div&gt;&lt;/td&gt;                   &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td width="30%"&gt;Home&lt;/td&gt;                   &lt;td width="70%"&gt;All Layers Displayed&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;CKEY&lt;/td&gt;                   &lt;td&gt;Centers View on 3D Cursor&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;ZKEY&lt;/td&gt;                   &lt;td&gt;Toggles Wire/Solid View&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;NUM.&lt;/td&gt;                   &lt;td&gt;View Selected&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;NUM1&lt;/td&gt;                   &lt;td&gt;Front View&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;NUM7&lt;/td&gt;                   &lt;td&gt;Top View&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;NUM3&lt;/td&gt;                   &lt;td&gt;Side View&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;NUM0&lt;/td&gt;                   &lt;td&gt;Camera View&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;CTRL-NUM1&lt;/td&gt;                   &lt;td&gt;Back View&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;CTRL-NUM7&lt;/td&gt;                   &lt;td&gt;Bottom View&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;CTRL-NUM3&lt;/td&gt;                   &lt;td&gt;Other Side View&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;CTRL-NUM4&lt;/td&gt;                   &lt;td&gt;Pan Display Right&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;CTRL-NUM6&lt;/td&gt;                   &lt;td&gt;Pan Display Left&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;CTRL-NUM2&lt;/td&gt;                   &lt;td&gt;Pan Display Up&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;CTRL-NUM8&lt;/td&gt;                   &lt;td&gt;Pan Dislay Down&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;NUM8&lt;/td&gt;                   &lt;td&gt;Oribt Up&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;NUM2&lt;/td&gt;                   &lt;td&gt;Orbit Down&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;NUM4&lt;/td&gt;                   &lt;td&gt;Orbit Counter-Clockwise&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;NUM6&lt;/td&gt;                   &lt;td&gt;Orbit Clockwise&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;MMB-SCROLL&lt;/td&gt;                   &lt;td&gt;Zoom In/Out&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;MMB-DRAG&lt;/td&gt;                   &lt;td&gt;Orbit View&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;NUM-&lt;/td&gt;                   &lt;td&gt;Zoom Out&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;NUM+&lt;/td&gt;                   &lt;td&gt;Zoom In&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;ALT-A&lt;/td&gt;                   &lt;td&gt;Play Animation&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;LEFT ARROW&lt;/td&gt;                   &lt;td&gt;Decrease Frame Number&lt;/td&gt;                 &lt;/tr&gt;                 &lt;tr&gt;                   &lt;td&gt;RIGHT ARROW&lt;/td&gt;                   &lt;td&gt;Increase Frame Number&lt;/td&gt;                 &lt;/tr&gt;               &lt;/tbody&gt;&lt;/table&gt;                 &lt;table border="1" width="100%"&gt;                   &lt;tbody&gt;&lt;tr&gt;                     &lt;td colspan="2"&gt;&lt;div class="p7AB" align="center"&gt;&lt;strong&gt;Selecting - Transforms&lt;/strong&gt;&lt;/div&gt;&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td width="33%"&gt;AKEY&lt;/td&gt;                     &lt;td width="67%"&gt;Selects/Deselects All&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;BKEY&lt;/td&gt;                     &lt;td&gt;Border/Box Select&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;BKEY-BKEY&lt;/td&gt;                     &lt;td&gt;Circle Select&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;GKEY&lt;/td&gt;                     &lt;td&gt;Grab Mode&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;GKEY-X or Y or Z&lt;/td&gt;                     &lt;td&gt;Grab Constrain to X-Y-Z&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;ALT-G&lt;/td&gt;                     &lt;td&gt;Object Set To 0 Location&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;RKEY&lt;/td&gt;                     &lt;td&gt;Rotate Mode&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;RKEY-X or Y or Z&lt;/td&gt;                     &lt;td&gt;Rotate Constrain to X-Y-Z&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;ALT-R&lt;/td&gt;                     &lt;td&gt;Object Set To 0 Rotation&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;SKEY&lt;/td&gt;                     &lt;td&gt;Scale Mode&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;SKEY-X or Y or Z&lt;/td&gt;                     &lt;td&gt;Scale Constrain to X-Y-Z&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;ALT-S&lt;/td&gt;                     &lt;td&gt;Object Set To 0 Scale&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;HKEY&lt;/td&gt;                     &lt;td&gt;Toggle Align/Free Handles&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;VKEY&lt;/td&gt;                     &lt;td&gt;Vector Handles&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;CTRL-SPACE&lt;/td&gt;                     &lt;td&gt;Toggles 3D Widget&lt;/td&gt;                   &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt;SHIFT-TAB&lt;/td&gt;                     &lt;td&gt;Use Snap/Grid&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-7519504685747839991?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/7519504685747839991/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2010/04/blender-hot-key-cheat-sheet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/7519504685747839991'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/7519504685747839991'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2010/04/blender-hot-key-cheat-sheet.html' title='Blender Hot key Cheat sheet'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-3514918066190040357</id><published>2010-01-20T19:13:00.000-08:00</published><updated>2010-01-20T19:16:18.271-08:00</updated><title type='text'>My toolbox for web development using .net</title><content type='html'>Resharper: Is one of those add-ins that once you start using it would be hard to give up – as it provides solutions to programming errors, helps out with refactoring, unit testing, code formatting and clean up. [&lt;a title="Resharper" href="http://www.jetbrains.com/resharper/" target="_blank"&gt;link&lt;/a&gt;]&lt;br /&gt;GhostDoc: This free extension automatically generates your documentation comments for your code. A must. [&lt;a title="ghostdoc" href="http://submain.com/products/ghostdoc.aspx" target="_blank"&gt;link&lt;/a&gt;]&lt;br /&gt;Clone Detective: This add-in tells you where you are repeating code. Very helpful but sometimes does not play well with others add-ins. [&lt;a title="Clone Detective" href="http://www.codeplex.com/CloneDetectiveVS" target="_blank"&gt;link&lt;/a&gt;]&lt;br /&gt;Dundas: Best graphing framework on .NET period. Only negative is that it is not cheap but you can accomplish most stuff with ASP.NET Charting Controls. [&lt;a title="Dundas" href="http://dundas.com/" target="_blank"&gt;link&lt;/a&gt;]&lt;br /&gt;Virtual Earth: Fun control to use Virtual Earth. [&lt;a title="Virtual Earth" href="http://msdn.microsoft.com/en-us/library/dd877180.aspx" target="_blank"&gt;link&lt;/a&gt;]&lt;br /&gt;Telerik Controls: Great controls and is a must but like Dundas is not cheap. [&lt;a title="telerik" href="http://www.telerik.com/" target="_blank"&gt;link&lt;/a&gt;]&lt;br /&gt;ASP.Net Ajax Framework: A must if you are still doing web forms page. [&lt;a title="ASP.NET Ajax" href="http://www.asp.net/ajax/"&gt;link&lt;/a&gt;]&lt;br /&gt;ASP.Net Ajax Toolkit: The bells and whistles for the framework. [&lt;a title="ASP.NET Ajax Toolkit" href="http://www.asp.net/ajax/AjaxControlToolkit/Samples/" target="_blank"&gt;link&lt;/a&gt;]&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-3514918066190040357?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/3514918066190040357/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2010/01/my-toolbox-for-web-development-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/3514918066190040357'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/3514918066190040357'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2010/01/my-toolbox-for-web-development-using.html' title='My toolbox for web development using .net'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-3344149196363197571</id><published>2009-12-28T23:01:00.000-08:00</published><updated>2009-12-28T23:05:57.275-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='heap sort'/><category scheme='http://www.blogger.com/atom/ns#' term='bubble sort'/><category scheme='http://www.blogger.com/atom/ns#' term='selection sort'/><category scheme='http://www.blogger.com/atom/ns#' term='quick sort'/><category scheme='http://www.blogger.com/atom/ns#' term='shell sort'/><category scheme='http://www.blogger.com/atom/ns#' term='source code'/><category scheme='http://www.blogger.com/atom/ns#' term='c#'/><category scheme='http://www.blogger.com/atom/ns#' term='merge sort'/><category scheme='http://www.blogger.com/atom/ns#' term='insertion sort'/><title type='text'>Most Common Sorting algorithms in C# class</title><content type='html'>&lt;blockquote style="font-style: italic;"&gt;&lt;p&gt;&lt;span style="font-size:78%;"&gt;&lt;br /&gt;&lt;/span&gt; &lt;span style="font-size:78%;"&gt;&lt;span style="font-family:arial,helvetica,sans-serif;"&gt;using System;&lt;br /&gt;&lt;br /&gt; using System.Collections.Generic;&lt;br /&gt;&lt;br /&gt; using System.Web;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; namespace ats.SortAlgo&lt;br /&gt;&lt;br /&gt; {&lt;br /&gt;&lt;br /&gt;     public class Sorters&lt;br /&gt;&lt;br /&gt;     {&lt;br /&gt;&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     public class QuickSort&lt;br /&gt;&lt;br /&gt;     {&lt;br /&gt;&lt;br /&gt;         // array of integers to hold values&lt;br /&gt;&lt;br /&gt;         private int[] a = new int[100];&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         // number of elements in array&lt;br /&gt;&lt;br /&gt;         private int x;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         // Quick Sort Algorithm&lt;br /&gt;&lt;br /&gt;         public void sortArray()&lt;br /&gt;&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;             q_sort(0, x - 1);&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         public void q_sort(int left, int right)&lt;br /&gt;&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;             int pivot, l_hold, r_hold;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             l_hold = left;&lt;br /&gt;&lt;br /&gt;             r_hold = right;&lt;br /&gt;&lt;br /&gt;             pivot = a[left];&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             while (left &amp;lt; right)&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 while ((a[right] &amp;gt;= pivot) &amp;amp;&amp;amp; (left &amp;lt; right))&lt;br /&gt;&lt;br /&gt;                 {&lt;br /&gt;&lt;br /&gt;                     right--;&lt;br /&gt;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;                 if (left != right)&lt;br /&gt;&lt;br /&gt;                 {&lt;br /&gt;&lt;br /&gt;                     a[left] = a[right];&lt;br /&gt;&lt;br /&gt;                     left++;&lt;br /&gt;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;                 while ((a[left] &amp;lt;= pivot) &amp;amp;&amp;amp; (left &amp;lt; right))&lt;br /&gt;&lt;br /&gt;                 {&lt;br /&gt;&lt;br /&gt;                     left++;&lt;br /&gt;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;                 if (left != right)&lt;br /&gt;&lt;br /&gt;                 {&lt;br /&gt;&lt;br /&gt;                     a[right] = a[left];&lt;br /&gt;&lt;br /&gt;                     right--;&lt;br /&gt;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             a[left] = pivot;&lt;br /&gt;&lt;br /&gt;             pivot = left;&lt;br /&gt;&lt;br /&gt;             left = l_hold;&lt;br /&gt;&lt;br /&gt;             right = r_hold;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             if (left &amp;lt; pivot)&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 q_sort(left, pivot - 1);&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             if (right &amp;gt; pivot)&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 q_sort(pivot + 1, right);&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     public class BubbleSort&lt;br /&gt;&lt;br /&gt;     {&lt;br /&gt;&lt;br /&gt;         // array of integers to hold values&lt;br /&gt;&lt;br /&gt;         private int[] a = new int[100];&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         // number of elements in array&lt;br /&gt;&lt;br /&gt;         private int x;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         // Bubble Sort Algorithm&lt;br /&gt;&lt;br /&gt;         public void sortArray()&lt;br /&gt;&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;             int i;&lt;br /&gt;&lt;br /&gt;             int j;&lt;br /&gt;&lt;br /&gt;             int temp;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             for (i = (x - 1); i &amp;gt;= 0; i--)&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 for (j = 1; j &amp;lt;= i; j++)&lt;br /&gt;&lt;br /&gt;                 {&lt;br /&gt;&lt;br /&gt;                     if (a[j - 1] &amp;gt; a[j])&lt;br /&gt;&lt;br /&gt;                     {&lt;br /&gt;&lt;br /&gt;                         temp = a[j - 1];&lt;br /&gt;&lt;br /&gt;                         a[j - 1] = a[j];&lt;br /&gt;&lt;br /&gt;                         a[j] = temp;&lt;br /&gt;&lt;br /&gt;                     }&lt;br /&gt;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     public class HeapSort&lt;br /&gt;&lt;br /&gt;     {&lt;br /&gt;&lt;br /&gt;         // array of integers to hold values&lt;br /&gt;&lt;br /&gt;         private int[] a = new int[100];&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         // number of elements in array&lt;br /&gt;&lt;br /&gt;         private int x;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         // Heap Sort Algorithm&lt;br /&gt;&lt;br /&gt;         public void sortArray()&lt;br /&gt;&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;             int i;&lt;br /&gt;&lt;br /&gt;             int temp;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             for (i = (x / 2) - 1; i &amp;gt;= 0; i--)&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 siftDown(i, x);&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             for (i = x - 1; i &amp;gt;= 1; i--)&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 temp = a[0];&lt;br /&gt;&lt;br /&gt;                 a[0] = a[i];&lt;br /&gt;&lt;br /&gt;                 a[i] = temp;&lt;br /&gt;&lt;br /&gt;                 siftDown(0, i - 1);&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         public void siftDown(int root, int bottom)&lt;br /&gt;&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;             bool done = false;&lt;br /&gt;&lt;br /&gt;             int maxChild;&lt;br /&gt;&lt;br /&gt;             int temp;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             while ((root * 2 &amp;lt;= bottom) &amp;amp;&amp;amp; (!done))&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 if (root * 2 == bottom)&lt;br /&gt;&lt;br /&gt;                     maxChild = root * 2;&lt;br /&gt;&lt;br /&gt;                 else if (a[root * 2] &amp;gt; a[root * 2 + 1])&lt;br /&gt;&lt;br /&gt;                     maxChild = root * 2;&lt;br /&gt;&lt;br /&gt;                 else&lt;br /&gt;&lt;br /&gt;                     maxChild = root * 2 + 1;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;                 if (a[root] &amp;lt; a[maxChild])&lt;br /&gt;&lt;br /&gt;                 {&lt;br /&gt;&lt;br /&gt;                     temp = a[root];&lt;br /&gt;&lt;br /&gt;                     a[root] = a[maxChild];&lt;br /&gt;&lt;br /&gt;                     a[maxChild] = temp;&lt;br /&gt;&lt;br /&gt;                     root = maxChild;&lt;br /&gt;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt;                 else&lt;br /&gt;&lt;br /&gt;                 {&lt;br /&gt;&lt;br /&gt;                     done = true;&lt;br /&gt;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     public class InsertionSort&lt;br /&gt;&lt;br /&gt;     {&lt;br /&gt;&lt;br /&gt;         // array of integers to hold values&lt;br /&gt;&lt;br /&gt;         private int[] a = new int[100];&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         // number of elements in array&lt;br /&gt;&lt;br /&gt;         private int x;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         // Insertion Sort Algorithm&lt;br /&gt;&lt;br /&gt;         public void sortArray()&lt;br /&gt;&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;             int i;&lt;br /&gt;&lt;br /&gt;             int j;&lt;br /&gt;&lt;br /&gt;             int index;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             for (i = 1; i &amp;lt; x; i++)&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 index = a[i];&lt;br /&gt;&lt;br /&gt;                 j = i;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;                 while ((j &amp;gt; 0) &amp;amp;&amp;amp; (a[j - 1] &amp;gt; index))&lt;br /&gt;&lt;br /&gt;                 {&lt;br /&gt;&lt;br /&gt;                     a[j] = a[j - 1];&lt;br /&gt;&lt;br /&gt;                     j = j - 1;&lt;br /&gt;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;                 a[j] = index;&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     public class MergeSort&lt;br /&gt;&lt;br /&gt;     {&lt;br /&gt;&lt;br /&gt;         // array of integers to hold values&lt;br /&gt;&lt;br /&gt;         private int[] a = new int[100];&lt;br /&gt;&lt;br /&gt;         private int[] b = new int[100];&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         // number of elements in array&lt;br /&gt;&lt;br /&gt;         private int x;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         // Merge Sort Algorithm&lt;br /&gt;&lt;br /&gt;         public void sortArray()&lt;br /&gt;&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;             m_sort(0, x - 1);&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         public void m_sort(int left, int right)&lt;br /&gt;&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;             int mid;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             if (right &amp;gt; left)&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 mid = (right + left) / 2;&lt;br /&gt;&lt;br /&gt;                 m_sort(left, mid);&lt;br /&gt;&lt;br /&gt;                 m_sort(mid + 1, right);&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;                 merge(left, mid + 1, right);&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         public void merge(int left, int mid, int right)&lt;br /&gt;&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;             int i, left_end, num_elements, tmp_pos;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             left_end = mid - 1;&lt;br /&gt;&lt;br /&gt;             tmp_pos = left;&lt;br /&gt;&lt;br /&gt;             num_elements = right - left + 1;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             while ((left &amp;lt;= left_end) &amp;amp;&amp;amp; (mid &amp;lt;= right))&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 if (a[left] &amp;lt;= a[mid])&lt;br /&gt;&lt;br /&gt;                 {&lt;br /&gt;&lt;br /&gt;                     b[tmp_pos] = a[left];&lt;br /&gt;&lt;br /&gt;                     tmp_pos = tmp_pos + 1;&lt;br /&gt;&lt;br /&gt;                     left = left + 1;&lt;br /&gt;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt;                 else&lt;br /&gt;&lt;br /&gt;                 {&lt;br /&gt;&lt;br /&gt;                     b[tmp_pos] = a[mid];&lt;br /&gt;&lt;br /&gt;                     tmp_pos = tmp_pos + 1;&lt;br /&gt;&lt;br /&gt;                     mid = mid + 1;&lt;br /&gt;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             while (left &amp;lt;= left_end)&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 b[tmp_pos] = a[left];&lt;br /&gt;&lt;br /&gt;                 left = left + 1;&lt;br /&gt;&lt;br /&gt;                 tmp_pos = tmp_pos + 1;&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             while (mid &amp;lt;= right)&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 b[tmp_pos] = a[mid];&lt;br /&gt;&lt;br /&gt;                 mid = mid + 1;&lt;br /&gt;&lt;br /&gt;                 tmp_pos = tmp_pos + 1;&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             for (i = 0; i &amp;lt; num_elements; i++)&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 a[right] = b[right];&lt;br /&gt;&lt;br /&gt;                 right = right - 1;&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     public class SelectionSort&lt;br /&gt;&lt;br /&gt;     {&lt;br /&gt;&lt;br /&gt;         // array of integers to hold values&lt;br /&gt;&lt;br /&gt;         private int[] a = new int[100];&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         // number of elements in array&lt;br /&gt;&lt;br /&gt;         private int x;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         // Selection Sort Algorithm&lt;br /&gt;&lt;br /&gt;         public void sortArray()&lt;br /&gt;&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;             int i, j;&lt;br /&gt;&lt;br /&gt;             int min, temp;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             for (i = 0; i &amp;lt; x - 1; i++)&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 min = i;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;                 for (j = i + 1; j &amp;lt; x; j++)&lt;br /&gt;&lt;br /&gt;                 {&lt;br /&gt;&lt;br /&gt;                     if (a[j] &amp;lt; a[min])&lt;br /&gt;&lt;br /&gt;                     {&lt;br /&gt;&lt;br /&gt;                         min = j;&lt;br /&gt;&lt;br /&gt;                     }&lt;br /&gt;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;                 temp = a[i];&lt;br /&gt;&lt;br /&gt;                 a[i] = a[min];&lt;br /&gt;&lt;br /&gt;                 a[min] = temp;&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     public class ShellSort&lt;br /&gt;&lt;br /&gt;     {&lt;br /&gt;&lt;br /&gt;         // array of integers to hold values&lt;br /&gt;&lt;br /&gt;         private int[] a = new int[100];&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         // number of elements in array&lt;br /&gt;&lt;br /&gt;         private int x;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;         // Shell Sort Algorithm&lt;br /&gt;&lt;br /&gt;         public void sortArray()&lt;br /&gt;&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;             int i, j, increment, temp;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             increment = 3;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;             while (increment &amp;gt; 0)&lt;br /&gt;&lt;br /&gt;             {&lt;br /&gt;&lt;br /&gt;                 for (i = 0; i &amp;lt; x; i++)&lt;br /&gt;&lt;br /&gt;                 {&lt;br /&gt;&lt;br /&gt;                     j = i;&lt;br /&gt;&lt;br /&gt;                     temp = a[i];&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;                     while ((j &amp;gt;= increment) &amp;amp;&amp;amp; (a[j - increment] &amp;gt; temp))&lt;br /&gt;&lt;br /&gt;                     {&lt;br /&gt;&lt;br /&gt;                         a[j] = a[j - increment];&lt;br /&gt;&lt;br /&gt;                         j = j - increment;&lt;br /&gt;&lt;br /&gt;                     }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;                     a[j] = temp;&lt;br /&gt;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;                 if (increment / 2 != 0)&lt;br /&gt;&lt;br /&gt;                 {&lt;br /&gt;&lt;br /&gt;                     increment = increment / 2;&lt;br /&gt;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt;                 else if (increment == 1)&lt;br /&gt;&lt;br /&gt;                 {&lt;br /&gt;&lt;br /&gt;                     increment = 0;&lt;br /&gt;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt;                 else&lt;br /&gt;&lt;br /&gt;                 {&lt;br /&gt;&lt;br /&gt;                     increment = 1;&lt;br /&gt;&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; }&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:78%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-3344149196363197571?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/3344149196363197571/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/12/most-common-sorting-algorithms-in-c.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/3344149196363197571'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/3344149196363197571'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/12/most-common-sorting-algorithms-in-c.html' title='Most Common Sorting algorithms in C# class'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-4445181279532650322</id><published>2009-10-03T20:04:00.000-07:00</published><updated>2009-10-03T22:04:49.700-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='electronics'/><category scheme='http://www.blogger.com/atom/ns#' term='basic weka'/><category scheme='http://www.blogger.com/atom/ns#' term='robotics'/><category scheme='http://www.blogger.com/atom/ns#' term='relay'/><category scheme='http://www.blogger.com/atom/ns#' term='capacitor'/><category scheme='http://www.blogger.com/atom/ns#' term='resistor'/><category scheme='http://www.blogger.com/atom/ns#' term='transistor'/><title type='text'>Basic of Electronics to build robots</title><content type='html'>&lt;span style="font-weight: bold;font-size:130%;" &gt;Transistor&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;a transistor is a semiconductor device commonly used to amplify or switch electronic signals. &lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_lYg70zdQa3I/SsgYxraW32I/AAAAAAAAAQM/Dore06-l5BM/s1600-h/Phototransistor_symbol.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 37px; height: 37px;" src="http://3.bp.blogspot.com/_lYg70zdQa3I/SsgYxraW32I/AAAAAAAAAQM/Dore06-l5BM/s200/Phototransistor_symbol.png" alt="" id="BLOGGER_PHOTO_ID_5388584195894730594" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;One of the Symbols used for transistors in schematic diagrams&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/SsgYxMUlfEI/AAAAAAAAAQE/gNaJ9fGC93o/s1600-h/tl431.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 93px;" src="http://4.bp.blogspot.com/_lYg70zdQa3I/SsgYxMUlfEI/AAAAAAAAAQE/gNaJ9fGC93o/s200/tl431.gif" alt="" id="BLOGGER_PHOTO_ID_5388584187549023298" border="0" /&gt;&lt;/a&gt;a common transistor that i use is the C945 transistor.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/SsgYx2vrPbI/AAAAAAAAAQU/sE_zeiLd8FM/s1600-h/200px-Transistorer_%28croped%29.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 149px; height: 200px;" src="http://1.bp.blogspot.com/_lYg70zdQa3I/SsgYx2vrPbI/AAAAAAAAAQU/sE_zeiLd8FM/s200/200px-Transistorer_%28croped%29.jpg" alt="" id="BLOGGER_PHOTO_ID_5388584198936935858" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Examples of Transistors&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Resistor&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;A resistor is a block of material that limits the flow of current. The greater the resistance, the lower the current will be.  on other words Resistors restrict the flow of electric current, for example a resistor is placed in series with a light-emitting diode (LED) to limit the current passing through the LED.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_lYg70zdQa3I/SsgSxy71D_I/AAAAAAAAAPc/eaKpq5jrO3E/s1600-h/resistor+Symbol.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 60px; height: 48px;" src="http://3.bp.blogspot.com/_lYg70zdQa3I/SsgSxy71D_I/AAAAAAAAAPc/eaKpq5jrO3E/s200/resistor+Symbol.png" alt="" id="BLOGGER_PHOTO_ID_5388577600844402674" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Resistor values are normally shown using coloured bands.&lt;br /&gt;Each colour represents a number as shown in the table. &lt;/p&gt;&lt;p&gt;Most resistors have 4 bands: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;The &lt;b&gt;first band&lt;/b&gt; gives the &lt;b&gt;first digit&lt;/b&gt;. &lt;/li&gt;&lt;li&gt;The &lt;b&gt;second band&lt;/b&gt; gives the &lt;b&gt;second digit&lt;/b&gt;. &lt;/li&gt;&lt;li&gt;The &lt;b&gt;third band&lt;/b&gt; indicates the &lt;b&gt;number of zeros&lt;/b&gt;. &lt;/li&gt;&lt;li&gt;&lt;i&gt;The fourth band is used to shows the tolerance (precision) of the resistor, this may be ignored for almost all circuits&lt;br /&gt;&lt;/i&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/SsgSxLeFxzI/AAAAAAAAAPU/YVXh2iBOOg4/s1600-h/resistorBands.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 38px;" src="http://4.bp.blogspot.com/_lYg70zdQa3I/SsgSxLeFxzI/AAAAAAAAAPU/YVXh2iBOOg4/s200/resistorBands.gif" alt="" id="BLOGGER_PHOTO_ID_5388577590250686258" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;table align="right" border="1" cellpadding="2"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td colspan="2"&gt;&lt;center&gt;&lt;b&gt;The Resistor&lt;br /&gt;Colour Code&lt;/b&gt;&lt;/center&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Colour&lt;/td&gt;&lt;td&gt;Number&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td bg="" style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;Black&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;center&gt;0&lt;/center&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td bg="" style="color: rgb(153, 102, 0);"&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;Brown&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;center&gt;1&lt;/center&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td bgcolor="#ff3333"&gt;Red&lt;/td&gt;  &lt;td&gt;&lt;center&gt;2&lt;/center&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td bgcolor="#ff9933"&gt;Orange&lt;/td&gt;&lt;td&gt;&lt;center&gt;3&lt;/center&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td bgcolor="#ffff00"&gt;Yellow&lt;/td&gt;&lt;td&gt;&lt;center&gt;4&lt;/center&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td bgcolor="#00cc00"&gt;Green&lt;/td&gt;&lt;td&gt;&lt;center&gt;5&lt;/center&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td bgcolor="#0066ff"&gt;Blue&lt;/td&gt;&lt;td&gt;&lt;center&gt;6&lt;/center&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td bgcolor="#ff00ff"&gt;Violet&lt;/td&gt;&lt;td&gt;&lt;center&gt;7&lt;/center&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td bgcolor="#999999"&gt;Grey&lt;/td&gt;&lt;td&gt;&lt;center&gt;8&lt;/center&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td bgcolor="#ffffff"&gt;White&lt;/td&gt;&lt;td&gt;&lt;center&gt;9&lt;/center&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/SsgSyu6Xd6I/AAAAAAAAAPs/hJRBeQb6YTc/s1600-h/types+resistors+1.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 150px;" src="http://4.bp.blogspot.com/_lYg70zdQa3I/SsgSyu6Xd6I/AAAAAAAAAPs/hJRBeQb6YTc/s200/types+resistors+1.jpg" alt="" id="BLOGGER_PHOTO_ID_5388577616944396194" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/SsgSyGe6hKI/AAAAAAAAAPk/hLqjiBxlJZE/s1600-h/resistors_tantalums_01.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 132px; height: 200px;" src="http://1.bp.blogspot.com/_lYg70zdQa3I/SsgSyGe6hKI/AAAAAAAAAPk/hLqjiBxlJZE/s200/resistors_tantalums_01.jpg" alt="" id="BLOGGER_PHOTO_ID_5388577606091834530" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Capacitors&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A capacitor (historically known as a "condenser") is a device that stores energy in an electric field, by accumulating an internal imbalance of electric charge.&lt;br /&gt;A &lt;em&gt;capacitor&lt;/em&gt; functions much like a battery, but charges and discharges much more efficiently (batteries, though, can store much more charge).&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_lYg70zdQa3I/SsgUkQiS15I/AAAAAAAAAP0/2Rgxpdb4UgE/s1600-h/capacitor+Symbol.jpeg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 61px; height: 57px;" src="http://2.bp.blogspot.com/_lYg70zdQa3I/SsgUkQiS15I/AAAAAAAAAP0/2Rgxpdb4UgE/s200/capacitor+Symbol.jpeg" alt="" id="BLOGGER_PHOTO_ID_5388579567295453074" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Capacitor Symbol&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/SsgUkml_xbI/AAAAAAAAAP8/tdUHCA1fMow/s1600-h/capacitors_parts.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 128px;" src="http://4.bp.blogspot.com/_lYg70zdQa3I/SsgUkml_xbI/AAAAAAAAAP8/tdUHCA1fMow/s200/capacitors_parts.gif" alt="" id="BLOGGER_PHOTO_ID_5388579573216560562" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Capacitors are labeled differently for a list please see http://www.twysted-pair.com/capidcds.htm&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;Relay&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;A &lt;b&gt;relay&lt;/b&gt; is an electrically operated switch.&lt;br /&gt;Relays are used to and for:&lt;br /&gt;&lt;br /&gt;* Control a high-voltage circuit with a low-voltage signal, as in some types of modems or audio amplifiers.&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_lYg70zdQa3I/SsgbHcgOD0I/AAAAAAAAAQk/cYeGX_gxlco/s1600-h/Relay_symbols.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 101px; height: 200px;" src="http://2.bp.blogspot.com/_lYg70zdQa3I/SsgbHcgOD0I/AAAAAAAAAQk/cYeGX_gxlco/s200/Relay_symbols.gif" alt="" id="BLOGGER_PHOTO_ID_5388586768873164610" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Relay Symbols&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/SsgbIYZhnJI/AAAAAAAAAQ0/Pt1MNbLZUi4/s1600-h/pulse_toggle_relays.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 146px;" src="http://1.bp.blogspot.com/_lYg70zdQa3I/SsgbIYZhnJI/AAAAAAAAAQ0/Pt1MNbLZUi4/s200/pulse_toggle_relays.gif" alt="" id="BLOGGER_PHOTO_ID_5388586784951213202" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;a typical 5 pin relay (different with 6 pin replay)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/SsgbHxtqkfI/AAAAAAAAAQs/WGRoIf1UqH8/s1600-h/relaygraphic01.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 146px; height: 200px;" src="http://4.bp.blogspot.com/_lYg70zdQa3I/SsgbHxtqkfI/AAAAAAAAAQs/WGRoIf1UqH8/s200/relaygraphic01.gif" alt="" id="BLOGGER_PHOTO_ID_5388586774566703602" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Other Examples&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-4445181279532650322?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/4445181279532650322/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/10/basic-of-electronics-to-build-robots.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/4445181279532650322'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/4445181279532650322'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/10/basic-of-electronics-to-build-robots.html' title='Basic of Electronics to build robots'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_lYg70zdQa3I/SsgYxraW32I/AAAAAAAAAQM/Dore06-l5BM/s72-c/Phototransistor_symbol.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-6514732489202085891</id><published>2009-08-20T02:56:00.000-07:00</published><updated>2009-08-20T04:00:30.171-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Web'/><category scheme='http://www.blogger.com/atom/ns#' term='hacks'/><category scheme='http://www.blogger.com/atom/ns#' term='Website'/><category scheme='http://www.blogger.com/atom/ns#' term='css'/><title type='text'>10 CSS Hacks</title><content type='html'>&lt;p&gt;If you are front end coder you must know how important is to make cross browses, valid CSS and xHTML code. And also you must know how much time we are spending in all those hacks and fixes for various browsers. I've written about some of them earlier on PNG transparency issues, Yellow fields in web form, Vertical align div etc..&lt;/p&gt;Here is the list of 10 hand picked CSS hacks and tricks which can help you in your CSS code and also save some time.&lt;br /&gt;&lt;p&gt;1. Vertical align div&lt;/p&gt;&lt;p&gt;One of current CSS left outs is vertical align div. And before CSS 3 comes we have to use some tricks to solve this problem. I looked over for some solutions and it all comes up to defining it as table and using vertical align. The second one appears a lot and it’s a nice solution, but it has two faults, I’ll tell you later about them, here’s the code first.&lt;/p&gt;&lt;p&gt;Idea is to place absolute div 50% left and top and then to move margin left and top half if it’s size.&lt;/p&gt;&lt;p&gt;Vector people&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; .wrapper {&lt;br /&gt;&lt;/p&gt;&lt;p&gt;width: 100px;&lt;/p&gt;height: 100px;&lt;br /&gt;&lt;p&gt;position: absolute;&lt;/p&gt;&lt;p&gt;top: 50%;&lt;/p&gt;&lt;p&gt;left: 50%;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;margin-left: -50px;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;margin-top: -50px;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;Problem?&lt;/p&gt;&lt;p&gt;This works only with defined height and when div height is less then browser height so you can’t have scroll. Now you’ll ask why do anyone want vertical align when there’s a vertical scroll? Well for example you have container height 820px and you have it vertically centered in all larger resolutions, simple.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Solution&lt;br /&gt;&lt;/p&gt;&lt;p&gt;In this problem (when browser height is less than div height) at smaller resolutions 1/3 of div is not visible, it’s in negative top margin. So idea is to place some relative div that will prevent div to go into negative margin. Here is the code.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;&amp;lt;div id="shim"/&amp;gt;&amp;lt;/div&amp;gt;&lt;/p&gt;&lt;p&gt;&amp;lt;div id="wrapper"&amp;gt;&lt;/p&gt;&lt;p&gt;Content&lt;/p&gt;&lt;p&gt;&amp;lt;/div&amp;gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;html, body {&lt;/p&gt;&lt;p&gt;height: 100%;&lt;/p&gt;&lt;p&gt;margin: 0;&lt;/p&gt;&lt;p&gt;padding: 0;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;* {&lt;/p&gt;&lt;p&gt;margin:0px auto;&lt;/p&gt;&lt;p&gt;padding:0;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;div#shim {&lt;/p&gt;&lt;p&gt;visibility: hidden;&lt;/p&gt;&lt;p&gt;width: 100%;&lt;/p&gt;&lt;p&gt;height: 50%;&lt;/p&gt;&lt;p&gt;margin-top: -200px;&lt;/p&gt;&lt;p&gt;float: left;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;div#wrapper {&lt;/p&gt;&lt;p&gt;width: 1000px;&lt;/p&gt;&lt;p&gt;height: 400px;&lt;/p&gt;&lt;p&gt;clear: both;&lt;/p&gt;&lt;p&gt;background:red;&lt;/p&gt;&lt;p&gt;position: relative;&lt;/p&gt;&lt;p&gt;top: -200px;&lt;/p&gt;&lt;p&gt;/* IE4ever Hack: Hide from IE4 **/&lt;/p&gt;&lt;p&gt;position: static;&lt;/p&gt;&lt;p&gt;/** end hack */&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt; &lt;/p&gt;/* Hide from IE5mac \*//*/&lt;br /&gt;&lt;p&gt;div#shim {&lt;/p&gt;&lt;p&gt;display: none;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;html, body {&lt;/p&gt;height: auto;}/* end hack */&lt;p&gt; &lt;/p&gt;&lt;p&gt;/* ]]&amp;gt; */&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;2. Min-Height&lt;/p&gt;&lt;p&gt; &lt;/p&gt;selector {&lt;br /&gt;&lt;p&gt;min-height:500px;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;height:auto; !important&lt;/p&gt;&lt;p&gt;height:500px;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;3. PNG transparency&lt;/p&gt;&lt;p&gt;First one is if you need just simple transparent image, without some special needs for example backgrounds etc. The solution would be png fix. I've used it many times but it has lots of faults, for example with padding, margins and absolute positioning. Sometimes i can mess up the rest of your JavaScript files, but anyway very useful script. You can download it here http://homepage.ntlworld.com/bobosola/pngfix.js and just include it in your &amp;lt;head&amp;gt; tag&lt;/p&gt;PNG&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&amp;lt;!--[if lt IE 7.]&amp;gt;&lt;/p&gt;&amp;lt;script defer type="text/javascript" src="pngfix.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;p&gt;&amp;lt;![endif]--&amp;gt;&lt;/p&gt;&lt;p&gt;The second one can partly handle issues from first and it's pure CSS solution. I mostly use this for backgrounds, because if your path for a background is from CSS file then png fix can't handle it.&lt;/p&gt;&lt;p&gt;PNG&lt;/p&gt;&lt;p&gt;.someelement {&lt;/p&gt;&lt;p&gt;background-image: url(images/image.png);&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;* html .someelemen {&lt;/p&gt;&lt;p&gt;background-color: #333;&lt;/p&gt;&lt;p&gt;back\ground-color: transparent;&lt;/p&gt;&lt;p&gt;background-image: url(images/blank.gif);&lt;/p&gt;&lt;p&gt;filter: progid:DXImageTransform.Microsoft.&lt;/p&gt;&lt;p&gt;AlphaImageLoader(src="images/image.png", sizingMethod="scale");&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;I found this very useful, and also when you add some hover effects for example some color or other image. You can see live example here&lt;/p&gt;&lt;p&gt;NOTE: This simple hover is just example and it doesn't work in IE6&lt;/p&gt;&lt;p&gt;.someelement:hover {&lt;/p&gt;&lt;p&gt;background: #333;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;.someelement:hover {&lt;/p&gt;&lt;p&gt;background-image: url(images/image2.gif);&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;Only problem I had with this was with &amp;lt;a&amp;gt; tag, link just don't work (when it's in div with this kind of background) and i don't know why (talking again for IE6). And only solution i could think of was to place another absolute div over it for the links, content etc... Yes i know it's not elegant but it works if content is not dynamic.&lt;/p&gt;&lt;p&gt;4. Autoclear&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;.container:after {&lt;/p&gt;&lt;p&gt;content: ".";&lt;/p&gt;&lt;p&gt;display: block;&lt;/p&gt;&lt;p&gt;height: 0;&lt;/p&gt;&lt;p&gt;clear: both;&lt;/p&gt;&lt;p&gt;visibility: hidden;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;.container {display: inline-table;}&lt;/p&gt;&lt;p&gt;/* Hides from IE-mac \*/&lt;/p&gt;&lt;p&gt;* html .container {height: 1%;}&lt;/p&gt;&lt;p&gt;.container {display: block;}&lt;/p&gt;&lt;p&gt;/* End hide from IE-mac */&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;5. Reset CSS&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {&lt;/p&gt;&lt;p&gt;border:0pt none;&lt;/p&gt;&lt;p&gt;font-family:inherit;&lt;/p&gt;&lt;p&gt;font-size:100%;&lt;/p&gt;&lt;p&gt;font-style:inherit;&lt;/p&gt;&lt;p&gt;font-weight:inherit;&lt;/p&gt;&lt;p&gt;margin:0pt;&lt;/p&gt;&lt;p&gt;outline-color:invert;&lt;/p&gt;&lt;p&gt;outline-style:none;&lt;/p&gt;&lt;p&gt;outline-width:0pt;&lt;/p&gt;&lt;p&gt;padding:0pt;&lt;/p&gt;&lt;p&gt;vertical-align:baseline;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;table {&lt;/p&gt;&lt;p&gt;border-collapse:separate;&lt;/p&gt;&lt;p&gt;border-spacing:0pt;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;caption, th, td {&lt;/p&gt;&lt;p&gt;font-weight:normal;&lt;/p&gt;&lt;p&gt;text-align:left;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;blockquote:before, blockquote:after, q:before, q:after {&lt;/p&gt;&lt;p&gt;content:"";&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;blockquote, q {&lt;/p&gt;&lt;p&gt;quotes:"" "";&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;strong {&lt;/p&gt;&lt;p&gt;font-weight:bold;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;em {&lt;/p&gt;&lt;p&gt;font-style:italic;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;* {&lt;/p&gt;&lt;p&gt;margin:0pt;&lt;/p&gt;&lt;p&gt;padding:0pt;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;6. Scrolling Render IE&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;html {&lt;/p&gt;&lt;p&gt;      background : url(null) fixed no-repeat;&lt;/p&gt;&lt;p&gt;     }&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;7. Opacity&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;#transdiv {&lt;/p&gt;&lt;p&gt;filter:alpha(opacity=75);&lt;/p&gt;&lt;p&gt;-moz-opacity:.75;&lt;/p&gt;&lt;p&gt;opacity:.75;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;8. PRE Tag&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;pre {&lt;/p&gt;&lt;p&gt;white-space: pre-wrap; /* css-3 */&lt;/p&gt;&lt;p&gt;white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */&lt;/p&gt;&lt;p&gt;white-space: -pre-wrap; /* Opera 4-6 */&lt;/p&gt;&lt;p&gt;white-space: -o-pre-wrap; /* Opera 7 */&lt;/p&gt;&lt;p&gt;word-wrap: break-word; /* Internet Explorer 5.5+ */&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;9. Li Background Repeat IE&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&amp;lt;!--[if lt IE 7]&amp;gt;&lt;br /&gt;&lt;p&gt;&amp;lt;style&amp;gt;&lt;/p&gt;&lt;p&gt;#leftnav li { zoom: 1;} /* haslayout=true */&lt;/p&gt;&lt;p&gt;&amp;lt;/style&amp;gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;&amp;lt;![endif]--&amp;gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;10. Good to know&lt;/p&gt;&lt;p&gt; &lt;/p&gt;@charset "UTF-8";&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;/* ----------------------------------------------------------------------&lt;/p&gt;&lt;p&gt;    WinIE7&lt;/p&gt;&lt;p&gt;---------------------------------------------------------------------- */&lt;/p&gt;&lt;p&gt;*:first-child+html selector{property:value;}&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;/* ----------------------------------------------------------------------&lt;/p&gt;&lt;p&gt;    WinIE6 &amp;amp; Mac IE&lt;/p&gt;&lt;p&gt;---------------------------------------------------------------------- */&lt;/p&gt;&lt;p&gt;* html selector{property:value;}&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;/* ----------------------------------------------------------------------&lt;/p&gt;&lt;p&gt;    WinIE6&lt;/p&gt;&lt;p&gt;---------------------------------------------------------------------- */&lt;/p&gt;&lt;p&gt;/*\*/&lt;/p&gt;&lt;p&gt;* html selector{property:value;}&lt;/p&gt;&lt;p&gt;/**/&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;/* ----------------------------------------------------------------------&lt;/p&gt;&lt;p&gt;    MacIE&lt;/p&gt;&lt;p&gt;---------------------------------------------------------------------- */&lt;/p&gt;&lt;p&gt;/*\*//*/&lt;/p&gt;&lt;p&gt;selector{property:value;}&lt;/p&gt;&lt;p&gt;/**/&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-6514732489202085891?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/6514732489202085891/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/08/10-css-hacks.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/6514732489202085891'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/6514732489202085891'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/08/10-css-hacks.html' title='10 CSS Hacks'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-929813184632439817</id><published>2009-08-10T10:50:00.000-07:00</published><updated>2009-08-10T11:13:03.816-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='weka commandline'/><category scheme='http://www.blogger.com/atom/ns#' term='weka'/><category scheme='http://www.blogger.com/atom/ns#' term='basic weka'/><category scheme='http://www.blogger.com/atom/ns#' term='weka basic tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='neural network weka'/><title type='text'>Weka Using Command Prompt</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_lYg70zdQa3I/SoBhJQIrfJI/AAAAAAAAAO0/_IAHkdWIHXU/s1600-h/cmdweka4.JPG"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Using the WEKA GUI is fun and easy, but there are more options when using the command line. also the command line allows you to incorporate any programming language by simply calling the function from the command prompt. Here is what you need to do to get things going.&lt;br /&gt;&lt;br /&gt;Download and install WINRAR (you will need to extract the classes)&lt;br /&gt;Download and install WEKA. go to the directory and create a new folder "EXEC"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_lYg70zdQa3I/SoBe-A8TYDI/AAAAAAAAAOc/AM5VmuO5hhw/s1600-h/cmdweka1.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 266px; height: 159px;" src="http://2.bp.blogspot.com/_lYg70zdQa3I/SoBe-A8TYDI/AAAAAAAAAOc/AM5VmuO5hhw/s200/cmdweka1.JPG" alt="" id="BLOGGER_PHOTO_ID_5368395175323459634" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Notice the default directory. and notice the WEKA.JAR file. aswell as the new folder that we created.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/SoBfrBryLtI/AAAAAAAAAOk/ak2V-ktGxbw/s1600-h/cmdweka2.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 120px;" src="http://1.bp.blogspot.com/_lYg70zdQa3I/SoBfrBryLtI/AAAAAAAAAOk/ak2V-ktGxbw/s200/cmdweka2.JPG" alt="" id="BLOGGER_PHOTO_ID_5368395948616724178" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Extract the contents of WEKA.JAR to EXEC folder&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/SoBf9CY-ftI/AAAAAAAAAOs/RfxmB_3qgGs/s1600-h/cmdweka3.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 120px;" src="http://1.bp.blogspot.com/_lYg70zdQa3I/SoBf9CY-ftI/AAAAAAAAAOs/RfxmB_3qgGs/s200/cmdweka3.JPG" alt="" id="BLOGGER_PHOTO_ID_5368396258043920082" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;going to the EXEC folder, you will notice 3 folders that were extracted. your all set to use the command line.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_lYg70zdQa3I/SoBhJQIrfJI/AAAAAAAAAO0/_IAHkdWIHXU/s1600-h/cmdweka4.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 190px;" src="http://3.bp.blogspot.com/_lYg70zdQa3I/SoBhJQIrfJI/AAAAAAAAAO0/_IAHkdWIHXU/s200/cmdweka4.JPG" alt="" id="BLOGGER_PHOTO_ID_5368397567403719826" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Try the following code&lt;br /&gt;&lt;br /&gt;C:/&gt; java weka.classifiers.functions.multilayerperceptron&lt;br /&gt;&lt;br /&gt;you will see a list of commands you can use.&lt;br /&gt;if your just starting and dont know what each command or keyword means. you can copy the exact from the GUI.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_lYg70zdQa3I/SoBiCb9WFSI/AAAAAAAAAPE/_bpUKS_YDHU/s1600-h/weka6.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 149px;" src="http://2.bp.blogspot.com/_lYg70zdQa3I/SoBiCb9WFSI/AAAAAAAAAPE/_bpUKS_YDHU/s200/weka6.JPG" alt="" id="BLOGGER_PHOTO_ID_5368398549829948706" border="0" /&gt;&lt;/a&gt;How will you know what classifier is where? experience.&lt;br /&gt;&lt;br /&gt;but you can start with the GUI. multilayerperceptron is located under weka &gt; Classifiers &gt; functions&lt;br /&gt;&lt;br /&gt;once you click you will see a set of commands you can edit via GUI but there are more from the command line. lastly -T tells java what file to look for&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/SoBix2OHHoI/AAAAAAAAAPM/AHsyrGWEO5c/s1600-h/cmdweka6.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 126px;" src="http://1.bp.blogspot.com/_lYg70zdQa3I/SoBix2OHHoI/AAAAAAAAAPM/AHsyrGWEO5c/s200/cmdweka6.JPG" alt="" id="BLOGGER_PHOTO_ID_5368399364333444738" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;the following is an example of running a neural network from the command line&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_lYg70zdQa3I/SoBhJ-V8JaI/AAAAAAAAAO8/ELFdSAzIar4/s1600-h/cmdweka5.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 192px;" src="http://2.bp.blogspot.com/_lYg70zdQa3I/SoBhJ-V8JaI/AAAAAAAAAO8/ELFdSAzIar4/s200/cmdweka5.JPG" alt="" id="BLOGGER_PHOTO_ID_5368397579807368610" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;the following is the result of the command.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-929813184632439817?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/929813184632439817/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/08/weka-using-command-prompt.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/929813184632439817'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/929813184632439817'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/08/weka-using-command-prompt.html' title='Weka Using Command Prompt'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_lYg70zdQa3I/SoBe-A8TYDI/AAAAAAAAAOc/AM5VmuO5hhw/s72-c/cmdweka1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-8524429566662340311</id><published>2009-08-08T12:20:00.000-07:00</published><updated>2009-08-08T19:54:09.108-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='backpropagation'/><category scheme='http://www.blogger.com/atom/ns#' term='AI'/><category scheme='http://www.blogger.com/atom/ns#' term='neural network'/><category scheme='http://www.blogger.com/atom/ns#' term='weka'/><category scheme='http://www.blogger.com/atom/ns#' term='basic weka'/><category scheme='http://www.blogger.com/atom/ns#' term='weka tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='weka basic tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='weka gui'/><category scheme='http://www.blogger.com/atom/ns#' term='neural network weka'/><category scheme='http://www.blogger.com/atom/ns#' term='artificial Intelligence'/><title type='text'>Introduction to WEKA (GUI)</title><content type='html'>What is WEKA?&lt;br /&gt;Collection of machine learning algorithms for solving data mining problems implemented in Java and open sourced under the GPL.&lt;br /&gt;you can download it from&lt;br /&gt;http://www.cs.waikato.ac.nz/ml/weka/&lt;br /&gt;&lt;br /&gt;data files have an extension of ARFF&lt;br /&gt;when creating a file which holds all your data, use the following in sequence:&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;@relation -&gt; holds the name of the data and how its related to your research&lt;/li&gt;&lt;li&gt;@attribute -&gt; informs you of what attribute each of your data is about(ex. its a real number)&lt;/li&gt;&lt;li&gt;@data -&gt; your main data which should be the same length as the number of attributes separated by a comma.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;example:&lt;br /&gt;&lt;blockquote&gt;@relation MusicGenre&lt;br /&gt;@attribute BitRate real&lt;br /&gt;@attribute Music {Jazz, Rock, Country, Classical}&lt;br /&gt;&lt;br /&gt;@data&lt;br /&gt;12.51,Jazz&lt;br /&gt;45.23,Pop&lt;br /&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;the weka version im using is 3.6.1. lets start off with opening weka, you will see the following once the program starts running&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_lYg70zdQa3I/Sn40pRfo29I/AAAAAAAAANA/g_L7Au9l1Ys/s1600-h/weka1.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 133px;" src="http://2.bp.blogspot.com/_lYg70zdQa3I/Sn40pRfo29I/AAAAAAAAANA/g_L7Au9l1Ys/s200/weka1.JPG" alt="" id="BLOGGER_PHOTO_ID_5367785689547594706" border="0" /&gt;&lt;/a&gt; Our Start-up screen. you start by selecting explorer.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/Sn40ps2NsqI/AAAAAAAAANI/bsDih6Hgtp4/s1600-h/weka2.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 149px;" src="http://4.bp.blogspot.com/_lYg70zdQa3I/Sn40ps2NsqI/AAAAAAAAANI/bsDih6Hgtp4/s200/weka2.JPG" alt="" id="BLOGGER_PHOTO_ID_5367785696890040994" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;The explorer window will open, select choose a file for your data input&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_lYg70zdQa3I/Sn40p_lvURI/AAAAAAAAANQ/G2QRN1uyZ0Y/s1600-h/weka3.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 131px;" src="http://3.bp.blogspot.com/_lYg70zdQa3I/Sn40p_lvURI/AAAAAAAAANQ/G2QRN1uyZ0Y/s200/weka3.JPG" alt="" id="BLOGGER_PHOTO_ID_5367785701921214738" border="0" /&gt;&lt;/a&gt;Select the ARFF file which holds your data and open&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/Sn40qDy7HNI/AAAAAAAAANY/wqTm5cNeFJ4/s1600-h/weka4.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 149px;" src="http://4.bp.blogspot.com/_lYg70zdQa3I/Sn40qDy7HNI/AAAAAAAAANY/wqTm5cNeFJ4/s200/weka4.JPG" alt="" id="BLOGGER_PHOTO_ID_5367785703050255570" border="0" /&gt;&lt;/a&gt;Once the data is opened, it will look like so, showing all the data attributes in your set of data and the distribution. select the classify tab from the top tabs in your explorer&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_lYg70zdQa3I/Sn40qd50eJI/AAAAAAAAANg/-JtBH_cHmi4/s1600-h/weka5.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 149px;" src="http://2.bp.blogspot.com/_lYg70zdQa3I/Sn40qd50eJI/AAAAAAAAANg/-JtBH_cHmi4/s200/weka5.JPG" alt="" id="BLOGGER_PHOTO_ID_5367785710058502290" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;select choose for the type of classifier&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/Sn407ep3yJI/AAAAAAAAANo/uFetqaCyIEw/s1600-h/weka6.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 149px;" src="http://1.bp.blogspot.com/_lYg70zdQa3I/Sn407ep3yJI/AAAAAAAAANo/uFetqaCyIEw/s200/weka6.JPG" alt="" id="BLOGGER_PHOTO_ID_5367786002317822098" border="0" /&gt;&lt;/a&gt;a drop down will appear, select function -&gt; multilayerperceptron&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_lYg70zdQa3I/Sn407h-T-CI/AAAAAAAAANw/R8tkOy-LVDs/s1600-h/weka7.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 149px;" src="http://2.bp.blogspot.com/_lYg70zdQa3I/Sn407h-T-CI/AAAAAAAAANw/R8tkOy-LVDs/s200/weka7.JPG" alt="" id="BLOGGER_PHOTO_ID_5367786003208861730" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;once the type of classifier appeas,  right click on it and an option list will appear for settings&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_lYg70zdQa3I/Sn4079XbJaI/AAAAAAAAAN4/wzlI7M-v3IA/s1600-h/weka8.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 172px;" src="http://3.bp.blogspot.com/_lYg70zdQa3I/Sn4079XbJaI/AAAAAAAAAN4/wzlI7M-v3IA/s200/weka8.JPG" alt="" id="BLOGGER_PHOTO_ID_5367786010561947042" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;adjust the settings to your desired needs. as you can see all settings are default. click OK when done&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_lYg70zdQa3I/Sn408fM0mxI/AAAAAAAAAOA/pyH72g74gZE/s1600-h/weka9.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 150px;" src="http://2.bp.blogspot.com/_lYg70zdQa3I/Sn408fM0mxI/AAAAAAAAAOA/pyH72g74gZE/s200/weka9.JPG" alt="" id="BLOGGER_PHOTO_ID_5367786019644283666" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Press Start to run the classifier. we are using a back-propagation with sigmoid function&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/Sn408rrd_qI/AAAAAAAAAOI/C631FC44sqA/s1600-h/weka10.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 104px;" src="http://4.bp.blogspot.com/_lYg70zdQa3I/Sn408rrd_qI/AAAAAAAAAOI/C631FC44sqA/s200/weka10.JPG" alt="" id="BLOGGER_PHOTO_ID_5367786022994050722" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;The GUI option ON will give you the following output, allowing you to train your neural network per build since we are running at 10 folds. you can edit and move your neurons (see weka documentation) once your done with your training, accept and continue&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_lYg70zdQa3I/Sn41CWYoBFI/AAAAAAAAAOQ/yrsNBMzGOjY/s1600-h/weka11.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 162px;" src="http://2.bp.blogspot.com/_lYg70zdQa3I/Sn41CWYoBFI/AAAAAAAAAOQ/yrsNBMzGOjY/s200/weka11.JPG" alt="" id="BLOGGER_PHOTO_ID_5367786120357086290" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;the following shows the output either using the GUI ON/OFF feature. as you can see our classifier was able to classify 90% of the time.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-8524429566662340311?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/8524429566662340311/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/08/introduction-to-weka.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/8524429566662340311'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/8524429566662340311'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/08/introduction-to-weka.html' title='Introduction to WEKA (GUI)'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_lYg70zdQa3I/Sn40pRfo29I/AAAAAAAAANA/g_L7Au9l1Ys/s72-c/weka1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-9153892672883632369</id><published>2009-07-24T21:14:00.000-07:00</published><updated>2009-07-24T22:14:34.299-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming paradigms'/><category scheme='http://www.blogger.com/atom/ns#' term='notes'/><category scheme='http://www.blogger.com/atom/ns#' term='class'/><title type='text'>Lecture 1: Programming paradigms (notes)</title><content type='html'>I have several language but only one concept that i will write down here. this will represent my introduction to this class:&lt;br /&gt;&lt;br /&gt;C&lt;br /&gt;Assembly&lt;br /&gt;C++ / Java&lt;br /&gt;Concurrent programming ( not a  language)&lt;br /&gt;Lisp&lt;br /&gt;Python&lt;br /&gt;&lt;br /&gt;i want to give u all some mileage and some very relevant knowledge and languages that you can use for research and the industry however the real intellectual value in learning all these languages is to study the paradigms they represent.&lt;br /&gt;&lt;br /&gt;to program in C or C++/Java is following a totally different thought process than in Lisp or Python. Im sure many of you already know C and C++, all you have to do is remove the Object oriented way of programming and you will be left with C. When u program in C and pure C with no classes and ur very procedure oriented you think of a main function as being a high level outline of sub functions and sub sub function. your oriented around procedures and you program with side effects, you pass around pointers and references with the idea of updating shared data. you do that in both C and C++.  but as far as C is concerned you call it the procedural or sometimes the imperative paradigm. its verb oriented. the first thing you see is the function call. and the function call is so strong that it will let you know what the function will accomplish.&lt;br /&gt;&lt;br /&gt;but in C++ all of a sudden rather than calling "Do this and Pass the address with some object". you do my object arrow do this. in java its my object dot do this. so the first thing you see is the data or the object thats being manipulated. and thats why its object oriented.&lt;br /&gt;&lt;br /&gt;in between i have assembly here.  now i have yet to decide on the direction to go however there is an assembly language called "MIPS"  its very easy as far as assembly language goes. however im not really interested in teaching you assembly but im going to use it as a tool to show you how C and C++ files compile and eventually become binaries.  im interesting in teaching u how a line like a=0 or a++ will translate to binary (one and zero). ill give u some insight on how C is translated in to assembly and how your variables functions all boil down to a collection of zeros and ones and a little for C++ aswell. while it turns out that C and C++ represent different paradigms; that they really also compile to 0 and 1. and after u get a hand at the manual computation and find out of a C or C++ code will look like in assembly; your really going to see almost look like the same language as far as the zeros and ones are concerned.&lt;br /&gt;&lt;br /&gt;so by the end of this ill be able to do something like&lt;br /&gt;****&amp;amp;*P arrow ***** = 7&lt;br /&gt;and you will know exactly what it means.&lt;br /&gt;it will take a little work but when it compiles it means something and when it runs it actually does something. and you will know why it crashes rather it is crashing.&lt;br /&gt;&lt;br /&gt;now ill spend some time talking about concurrent programing. we actually do that in C however in concurrent programming we will get two functions to run seemingly simultaneously. please note the "seamless". because if we have a single CPU  the process goes back and forth on the two functions. since its so fast u wont be able to say they dont run concurrently. Also there are some problems you will encounter that u might not think about for example the atm machine with data integrity issues.&lt;br /&gt;&lt;br /&gt;Lisp Represents the functional paradigms. its very interesting because when you program you rely on a return value of a function to move forward. now whats nice about it is that there are no side effects. when you code in C or C++ u always have side effects. the return value doesnt tell you very much because it might be a number of a boolean but when you pass in a data structure by reference to a function and you update it so the original data structure has been changed, thats programing by side effects. while in Lisp you dont have that at all. you always synthesize the result or partial result that become larger results. and only then you see the answer on the screen. but we will get there. its a fun language and the easiest of all others.&lt;br /&gt;&lt;br /&gt;python has been around for 17 or 18 years. it has a good library for dealing with web programming. and python being a scripting language is interpreted. so your going to write a small dynamic web server in python for the final project, it wont be that hard. you wont write all of Apache but you will write something that u have a web server making decisions on how to construct an HTML page and serve it to a client. you can program procedurally, OOP, functionally.&lt;br /&gt;&lt;br /&gt;now there are some other paradigms that i will not cover but these are most likely what you will see for the next 10 to 15 years.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-9153892672883632369?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/9153892672883632369/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/07/lecture-1-programming-paradigms-notes.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/9153892672883632369'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/9153892672883632369'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/07/lecture-1-programming-paradigms-notes.html' title='Lecture 1: Programming paradigms (notes)'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-4875036655409089218</id><published>2009-07-11T20:42:00.000-07:00</published><updated>2009-08-12T19:51:08.641-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Rabin-Karp'/><category scheme='http://www.blogger.com/atom/ns#' term='Boyer-Moore'/><category scheme='http://www.blogger.com/atom/ns#' term='Prim&apos;s'/><category scheme='http://www.blogger.com/atom/ns#' term='Ford-Fulkerson'/><category scheme='http://www.blogger.com/atom/ns#' term='Prim-Jarnik'/><category scheme='http://www.blogger.com/atom/ns#' term='Floyd-Warshall'/><category scheme='http://www.blogger.com/atom/ns#' term='Knuth-Morris-Pratt'/><category scheme='http://www.blogger.com/atom/ns#' term='Push-Relabel'/><category scheme='http://www.blogger.com/atom/ns#' term='Kruskal&apos;s'/><category scheme='http://www.blogger.com/atom/ns#' term='Dijkstra&apos;s'/><category scheme='http://www.blogger.com/atom/ns#' term='Baruvka&apos;s'/><category scheme='http://www.blogger.com/atom/ns#' term='Johnsons'/><category scheme='http://www.blogger.com/atom/ns#' term='Strassen&apos;s'/><category scheme='http://www.blogger.com/atom/ns#' term='Bellman-Ford'/><category scheme='http://www.blogger.com/atom/ns#' term='Relabel-to-front'/><title type='text'>algorithms - How they Work</title><content type='html'>A Path length is the sum of all edges in a path&lt;br /&gt;Relaxation:&lt;br /&gt;For each vertex v in the graph, we maintain v.d(), the estimate of the shortest path from s, initialized to ¥ at the start&lt;br /&gt;Relaxing an edge (u,v) means testing whether we can improve the shortest path to v found so far by going through u&lt;br /&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold;font-family:georgia;" &gt;Breath First Search&lt;/span&gt;&lt;br /&gt;A graph Search algorithm that works like the following example: using a QUEUE or First In is First Out&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/Sm1zwgeKpjI/AAAAAAAAAMI/haduXrbSI4c/s1600-h/bfs.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5363070008455505458" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 135px" alt="" src="http://4.bp.blogspot.com/_lYg70zdQa3I/Sm1zwgeKpjI/AAAAAAAAAMI/haduXrbSI4c/s200/bfs.JPG" border="0" /&gt;&lt;/a&gt;Given the following and we start from Vertex A&lt;br /&gt;&lt;?xml:namespace prefix = p /&gt;&lt;p:colorscheme colors="#ffffff,#000000,#010000,#808080,#a50021,#ffffcc,#ff6600,#660066"&gt;&lt;/p:colorscheme&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/Sm10Tsyv8YI/AAAAAAAAAMQ/bbpm5h8Repc/s1600-h/bfs.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5363070613058482562" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 135px" alt="" src="http://1.bp.blogspot.com/_lYg70zdQa3I/Sm10Tsyv8YI/AAAAAAAAAMQ/bbpm5h8Repc/s200/bfs.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;We En-queue A and we look at connecting vertices. on a directed graph we only take note of the connection out of the vertice.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/Sm10n2PVavI/AAAAAAAAAMY/ImH502uCPps/s1600-h/bfs.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5363070959191681778" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 135px" alt="" src="http://4.bp.blogspot.com/_lYg70zdQa3I/Sm10n2PVavI/AAAAAAAAAMY/ImH502uCPps/s200/bfs.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;from A we en-queue B and C. either can be first. in this case i picked B over C.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/Sm108Wt0onI/AAAAAAAAAMg/0OiVnJbVeq8/s1600-h/bfs.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5363071311506874994" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 135px" alt="" src="http://1.bp.blogspot.com/_lYg70zdQa3I/Sm108Wt0onI/AAAAAAAAAMg/0OiVnJbVeq8/s200/bfs.JPG" border="0" /&gt;&lt;/a&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;br /&gt;&lt;/span&gt;From B we can connect to D and C however we have already been to C so we will only put D inside our queue.&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/Sm11UGuQGAI/AAAAAAAAAMo/CFHIXt-VaCM/s1600-h/bfs.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5363071719530567682" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 135px" alt="" src="http://4.bp.blogspot.com/_lYg70zdQa3I/Sm11UGuQGAI/AAAAAAAAAMo/CFHIXt-VaCM/s200/bfs.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;we de-queue the next, C. From C we can connect to D and E but we have already entered D in our Queue, so we will disregard the path and en-queue E.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/Sm11lwLhpZI/AAAAAAAAAMw/XZLzukY_u2o/s1600-h/bfs.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5363072022716982674" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 135px" alt="" src="http://4.bp.blogspot.com/_lYg70zdQa3I/Sm11lwLhpZI/AAAAAAAAAMw/XZLzukY_u2o/s200/bfs.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/Sm11tlgb0lI/AAAAAAAAAM4/lv1KjEkNMxA/s1600-h/bfs.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5363072157290844754" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 135px" alt="" src="http://1.bp.blogspot.com/_lYg70zdQa3I/Sm11tlgb0lI/AAAAAAAAAM4/lv1KjEkNMxA/s200/bfs.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;So on and so forth&lt;span style="FONT-WEIGHT: bold"&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Depth First Search&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;also done in the same way however we use a stack for LIFO (Last In is First Out) to go through the graph&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold"&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Johnson's algorithm&lt;/span&gt;&lt;br /&gt;Johnson's algorithm is a way to find shortest paths between all pairs of vertices in a sparse directed graph. It allows some of the edge weights to be negative numbers, but no negative-weight cycles may exist. It works by using the Bellman-Ford algorithm to compute a transformation of the input graph that removes all negative weights, allowing Dijkstra's algorithm to be used on the transformed graph.&lt;br /&gt;&lt;br /&gt;Johnson's algorithm consists of the following steps:&lt;br /&gt;&lt;br /&gt;1. First, a new node q is added to the graph, connected by zero-weight edge to each other node.&lt;br /&gt;2. Second, the Bellman-Ford algorithm is used, starting from the new vertex q, to find for each vertex v the least weight h(v) of a path from q to v. If this step detects a negative cycle, the algorithm is terminated.&lt;br /&gt;3. Next the edges of the original graph are reweighted using the values computed by the Bellman-Ford algorithm: an edge from u to v, having length w(u,v), is given the new length &lt;span style="FONT-WEIGHT: bold; FONT-STYLE: italic"&gt;w(u,v) + h(u) −h(v).&lt;/span&gt;&lt;br /&gt;4. Finally, for each node s, Dijkstra's algorithm is used to find the shortest paths from s to each other vertex in the reweighted graph.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_lYg70zdQa3I/SmAUCYKHLHI/AAAAAAAAALo/AGQtdRA8iv0/s1600-h/jhonsons.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5359305587648048242" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 194px; CURSOR: pointer; HEIGHT: 200px" alt="" src="http://3.bp.blogspot.com/_lYg70zdQa3I/SmAUCYKHLHI/AAAAAAAAALo/AGQtdRA8iv0/s200/jhonsons.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/SmAUQ7-26hI/AAAAAAAAALw/KtrKg5gQC3A/s1600-h/jhonsons.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5359305837782690322" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 195px" alt="" src="http://4.bp.blogspot.com/_lYg70zdQa3I/SmAUQ7-26hI/AAAAAAAAALw/KtrKg5gQC3A/s200/jhonsons.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Use the Bellman-Ford algorithm for computation&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/SmAXIPwaAAI/AAAAAAAAAL4/H7h5YZh-UrU/s1600-h/jhonsons.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5359308987006844930" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 194px" alt="" src="http://1.bp.blogspot.com/_lYg70zdQa3I/SmAXIPwaAAI/AAAAAAAAAL4/H7h5YZh-UrU/s200/jhonsons.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/SmAXZ_aGYmI/AAAAAAAAAMA/MG66VnnOel8/s1600-h/jhonsons.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5359309291855962722" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 189px; CURSOR: pointer; HEIGHT: 200px" alt="" src="http://4.bp.blogspot.com/_lYg70zdQa3I/SmAXZ_aGYmI/AAAAAAAAAMA/MG66VnnOel8/s200/jhonsons.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Compute weights from '&lt;span style="FONT-STYLE: italic"&gt;w(u,v) + h(u) −h(v).'&lt;br /&gt;from 0 to -5 this is how its computed&lt;br /&gt;previous weight was 8 :&lt;/span&gt;&lt;br /&gt;8 + 0 - (-5) = 13&lt;br /&gt;&lt;br /&gt;for -4 to 0 (bottom edge):&lt;br /&gt;6 + (-4) - 0 = 2&lt;br /&gt;&lt;br /&gt;after reweighing all edges, use Dijkstra's algorithm to compute the shortest path&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Kruskal's algorithm&lt;/span&gt;&lt;br /&gt;Kruskal's algorithm is an algorithm in graph theory that finds a minimum spanning tree for a connected weighted graph.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/Slr0f910BTI/AAAAAAAAAKI/Fmgm7qJAYcw/s1600-h/kruskal.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357863536724018482" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 132px" alt="" src="http://4.bp.blogspot.com/_lYg70zdQa3I/Slr0f910BTI/AAAAAAAAAKI/Fmgm7qJAYcw/s200/kruskal.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;We start off by looking at the edge with the smallest weight. in this case the edge connecting B and D. and the edge connecting C and E.&lt;span style="FONT-WEIGHT: bold"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_lYg70zdQa3I/Slr0yzzmTrI/AAAAAAAAAKQ/uWNsN-UyAck/s1600-h/kruskal.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357863860447891122" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 129px" alt="" src="http://2.bp.blogspot.com/_lYg70zdQa3I/Slr0yzzmTrI/AAAAAAAAAKQ/uWNsN-UyAck/s200/kruskal.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We Select either edge B-D or C-E. in this case we selected C-E.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_lYg70zdQa3I/Slr0_coRJCI/AAAAAAAAAKY/78UnxDXiCZ0/s1600-h/kruskal.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357864077564650530" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 129px" alt="" src="http://3.bp.blogspot.com/_lYg70zdQa3I/Slr0_coRJCI/AAAAAAAAAKY/78UnxDXiCZ0/s200/kruskal.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;we then select the next smallest edge, taking note the vertices were not connected before. since B-D and C-E are separate we can select B-D.&lt;span style="FONT-WEIGHT: bold"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="FONT-WEIGHT: bold"&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/Slr1K5fFMQI/AAAAAAAAAKg/ULgS7Bsjsm4/s1600-h/kruskal.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357864274289307906" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 129px" alt="" src="http://1.bp.blogspot.com/_lYg70zdQa3I/Slr1K5fFMQI/AAAAAAAAAKg/ULgS7Bsjsm4/s200/kruskal.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Next look for the next smallest weight on an edge. A-C is 3. since A is not connected to C in any path we can choose to use A-C. however if A-B was connected and D-C or B-C were connected, we couldnt use it.&lt;span style="FONT-WEIGHT: bold"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="FONT-WEIGHT: bold"&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/Slr1Vjr24YI/AAAAAAAAAKo/IZzvq8bXT9Q/s1600-h/kruskal.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357864457415876994" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 124px" alt="" src="http://1.bp.blogspot.com/_lYg70zdQa3I/Slr1Vjr24YI/AAAAAAAAAKo/IZzvq8bXT9Q/s200/kruskal.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_lYg70zdQa3I/Slr1hea0gjI/AAAAAAAAAKw/DVMOT-Qsfzg/s1600-h/kruskal.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357864662160671282" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 134px" alt="" src="http://2.bp.blogspot.com/_lYg70zdQa3I/Slr1hea0gjI/AAAAAAAAAKw/DVMOT-Qsfzg/s200/kruskal.JPG" border="0" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="FONT-WEIGHT: bold"&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/Slr1s-y5llI/AAAAAAAAAK4/nubocD5CKmo/s1600-h/kruskal.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357864859830163026" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 126px" alt="" src="http://1.bp.blogspot.com/_lYg70zdQa3I/Slr1s-y5llI/AAAAAAAAAK4/nubocD5CKmo/s200/kruskal.JPG" border="0" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Bellman-Ford algorithm&lt;/span&gt;&lt;br /&gt;The BellmanFord algorithm is a Dynamic Programming algorithm that solves the "shortest path problem". It looks at the structure of the graph, and iteratively generates a better solution from a previous one, until it reaches the best solution. BellmanFord can handle negative weights readily, because it uses the entire graph to improve a solution.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_lYg70zdQa3I/Sl_73VDEGBI/AAAAAAAAALA/T-h5buENC5c/s1600-h/bellman-ford.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5359279009555552274" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 150px" alt="" src="http://3.bp.blogspot.com/_lYg70zdQa3I/Sl_73VDEGBI/AAAAAAAAALA/T-h5buENC5c/s200/bellman-ford.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/Sl_8hsbNTeI/AAAAAAAAALI/i1oYfhm6Vas/s1600-h/bellman-ford.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5359279737385340386" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 151px" alt="" src="http://1.bp.blogspot.com/_lYg70zdQa3I/Sl_8hsbNTeI/AAAAAAAAALI/i1oYfhm6Vas/s200/bellman-ford.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Distance to T and Y is computed&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/Sl_83KCC7NI/AAAAAAAAALQ/c3a9Kxkmf3k/s1600-h/bellman-ford.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5359280106110119122" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 147px" alt="" src="http://4.bp.blogspot.com/_lYg70zdQa3I/Sl_83KCC7NI/AAAAAAAAALQ/c3a9Kxkmf3k/s200/bellman-ford.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;distance is computed from both T and Y to X and Z&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/Sl_9KmTcRRI/AAAAAAAAALY/wKRRQnz7syc/s1600-h/bellman-ford.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5359280440116790546" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 151px" alt="" src="http://4.bp.blogspot.com/_lYg70zdQa3I/Sl_9KmTcRRI/AAAAAAAAALY/wKRRQnz7syc/s200/bellman-ford.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;T is recomputed from X since its smaller we disregard the 6 and replace is with the new computation&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/Sl_9crJpgzI/AAAAAAAAALg/VSy70M_fCFo/s1600-h/bellman-ford.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5359280750655537970" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 154px" alt="" src="http://1.bp.blogspot.com/_lYg70zdQa3I/Sl_9crJpgzI/AAAAAAAAALg/VSy70M_fCFo/s200/bellman-ford.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;we examine the rest and our final answer.&lt;br /&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Prim's Algorithm / Prim-Jarnik algorithm&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A solution for the "minimum spanning tree problem" for a connected weighted graph. Sometimes called the DJP algorithm, the Jarník algorithm, or the Prim-Jarník algorithm.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;blockquote&gt;Steps: &lt;ol&gt;&lt;li&gt;Select the initial Vertex and compute the distance to connected vertices.&lt;/li&gt;&lt;li&gt;Select the shortest path and shade the vertex traversed.&lt;/li&gt;&lt;li&gt;from the new vertex compute connected vertices as if its your starting point.&lt;/li&gt;&lt;li&gt;continue until all vertices have been traveled.&lt;/li&gt;&lt;/ol&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/Sloo9XX-6XI/AAAAAAAAAJg/feVRcoi6NtA/s1600-h/Prim.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357639741422365042" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 145px" alt="" src="http://4.bp.blogspot.com/_lYg70zdQa3I/Sloo9XX-6XI/AAAAAAAAAJg/feVRcoi6NtA/s200/Prim.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Select A as the starting Vertex&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_lYg70zdQa3I/SlopPE3Bw_I/AAAAAAAAAJo/hQCk8pvcsfE/s1600-h/Prim.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357640045689947122" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 150px" alt="" src="http://2.bp.blogspot.com/_lYg70zdQa3I/SlopPE3Bw_I/AAAAAAAAAJo/hQCk8pvcsfE/s200/Prim.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;we start with A. we compute for B and C. we select the shortest path which is C.&lt;br /&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;br /&gt;&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/Slon1gplHkI/AAAAAAAAAJI/MlWzD_nc9QQ/s1600-h/Prim.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357638506961509954" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 152px" alt="" src="http://4.bp.blogspot.com/_lYg70zdQa3I/Slon1gplHkI/AAAAAAAAAJI/MlWzD_nc9QQ/s200/Prim.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;From C we compute for B which is 4. however we computed for B. since 4 is less than 10 we update. we compute for D and E.&lt;br /&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold; FONT-STYLE: italic"&gt;Note: we do not add the weight to the already computed vertex. so we dont add 3+4. we consider it as a point blank!&lt;/span&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="FONT-WEIGHT: bold"&gt; &lt;/p&gt;&lt;br /&gt;&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_lYg70zdQa3I/SloqOuLcMgI/AAAAAAAAAJw/f3VDMUzOGHo/s1600-h/Prim.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357641139113177602" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 149px" alt="" src="http://3.bp.blogspot.com/_lYg70zdQa3I/SloqOuLcMgI/AAAAAAAAAJw/f3VDMUzOGHo/s200/Prim.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;We select the shortest path which is E. Recompute other vertex connecting to E. since 8 is less than 9 we keep 8 as is. between B and D. we select B.&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="FONT-WEIGHT: bold"&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/SloqyLikuFI/AAAAAAAAAJ4/Wpaxu1NHHKk/s1600-h/Prim.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357641748290254930" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 153px" alt="" src="http://1.bp.blogspot.com/_lYg70zdQa3I/SloqyLikuFI/AAAAAAAAAJ4/Wpaxu1NHHKk/s200/Prim.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;From B we compute to the connected vertices. since we have already been to C, we disregard it and update D with 2. We travel D since its the only remaining path.&lt;span style="FONT-WEIGHT: bold"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="FONT-WEIGHT: bold"&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="FONT-WEIGHT: bold"&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/Slorm48s97I/AAAAAAAAAKA/TW8ybdgzN1E/s1600-h/Prim.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357642653832640434" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 151px" alt="" src="http://4.bp.blogspot.com/_lYg70zdQa3I/Slorm48s97I/AAAAAAAAAKA/TW8ybdgzN1E/s200/Prim.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;we select D as the final vertex and we are DONE.&lt;span style="FONT-WEIGHT: bold"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Dijkstra's algorithm&lt;/span&gt;&lt;br /&gt;a Solution for the "Single Source Shortest Path Problem"&lt;br /&gt;Given a weighted graph G and a source vertex v in G, determine the shortest paths from v to all other vertices in G. Find the shortest Path:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;blockquote&gt;Steps: &lt;ol&gt;&lt;li&gt;Repeatedly select the vertex (u) with shortest path length&lt;/li&gt;&lt;li&gt;update other lengths by considering the path that passes through that vertex&lt;/li&gt;&lt;li&gt;select the shortest path while updating.&lt;br /&gt;(ex. Path A to B is 5 however B was computed at 6. replace 5 with 6. if not keep the smallest number&lt;br /&gt;&lt;/li&gt;&lt;li&gt;stop when all vertices have been selected&lt;/li&gt;&lt;/ol&gt;&lt;/blockquote&gt;&lt;ol&gt;&lt;li&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;span style="FONT-STYLE: italic"&gt;EXAMPLE&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/SllegKtlI4I/AAAAAAAAAHw/TI9kfO1wnh8/s1600-h/dijkstra.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357417138458272642" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 121px" alt="" src="http://1.bp.blogspot.com/_lYg70zdQa3I/SllegKtlI4I/AAAAAAAAAHw/TI9kfO1wnh8/s200/dijkstra.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Given a graph with a NON NEGATIVE edge weight:&lt;br /&gt;Start from vertex A&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/SllfR9YWJxI/AAAAAAAAAH4/657h4eupqMg/s1600-h/dijkstra.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357417993873008402" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 143px" alt="" src="http://1.bp.blogspot.com/_lYg70zdQa3I/SllfR9YWJxI/AAAAAAAAAH4/657h4eupqMg/s200/dijkstra.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;First Step: Initialize the first vertex to zero and all the other vertex to UNKNOWN.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_lYg70zdQa3I/Sllf6iVCQdI/AAAAAAAAAIA/MoYyYk0xQTs/s1600-h/dijkstra.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357418690986000850" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 147px" alt="" src="http://4.bp.blogspot.com/_lYg70zdQa3I/Sllf6iVCQdI/AAAAAAAAAIA/MoYyYk0xQTs/s200/dijkstra.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Next Step is to look at the edges connecting to other vertices. Compute the distance until that vertex. so B is 10 and C is 3. D and E are still UNKNOWN. Take the shortest Path. The shortest Path is C.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/SllgrFvxN1I/AAAAAAAAAII/qoB934HWpks/s1600-h/dijkstra.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357419525127092050" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 150px" alt="" src="http://1.bp.blogspot.com/_lYg70zdQa3I/SllgrFvxN1I/AAAAAAAAAII/qoB934HWpks/s200/dijkstra.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We have already gone through A and C. A is Zero, B is 10,C is 3, D is UNKNOWN, E is UNKNOWN.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_lYg70zdQa3I/SllhRqqp7LI/AAAAAAAAAIQ/EOsBIiGStOE/s1600-h/dijkstra.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357420187872783538" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 147px" alt="" src="http://3.bp.blogspot.com/_lYg70zdQa3I/SllhRqqp7LI/AAAAAAAAAIQ/EOsBIiGStOE/s200/dijkstra.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;From C: there are 3 paths to B to D and to E.&lt;br /&gt;in B : 3+4 =7 however we computed B at 10 since 7 is less we update it to the shortest path.&lt;br /&gt;in D: 3+8 = 11&lt;br /&gt;in E: 3+2= 5&lt;br /&gt;Between 5,7 and 11 the shortest path is?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_lYg70zdQa3I/SlljTBOWCCI/AAAAAAAAAIY/jBPj-6BUMoc/s1600-h/dijkstra.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357422410131179554" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 152px" alt="" src="http://2.bp.blogspot.com/_lYg70zdQa3I/SlljTBOWCCI/AAAAAAAAAIY/jBPj-6BUMoc/s200/dijkstra.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The shortest Path is E. so we have updated and we have a path to all vertices. But we havent passed vertex B and D. so we look for the next shortest Path.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_lYg70zdQa3I/SllkD71vNxI/AAAAAAAAAIg/NbT5iLvlrZQ/s1600-h/dijkstra.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357423250499385106" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 157px" alt="" src="http://2.bp.blogspot.com/_lYg70zdQa3I/SllkD71vNxI/AAAAAAAAAIg/NbT5iLvlrZQ/s200/dijkstra.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;From E we can go to D. from C we can go to D and B. we have already computed D from C. lets compute D again from E.&lt;br /&gt;in E: 5+9 = 14 since 11 is less than 14, we keep 11.&lt;br /&gt;so we have a choice between going to B or D thats 7 and 11. the shortest path between 7 and 11 is? B&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_lYg70zdQa3I/Sllk1Id3XxI/AAAAAAAAAIo/XCxLo0fAWcM/s1600-h/dijkstra.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357424095702507282" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 151px" alt="" src="http://3.bp.blogspot.com/_lYg70zdQa3I/Sllk1Id3XxI/AAAAAAAAAIo/XCxLo0fAWcM/s200/dijkstra.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;We Select B since its the shortest path between 7 and 11. Now we compute for D to update the path to D.&lt;br /&gt;in B: 7+2 = 9. so we update 11 with 9 in D.&lt;br /&gt;there is another path to C. However we have already been to C so we dont need to recompute it.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/Slllo7riMoI/AAAAAAAAAIw/1-QKl4JWUiM/s1600-h/dijkstra.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5357424985623376514" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; WIDTH: 200px; CURSOR: pointer; HEIGHT: 148px" alt="" src="http://1.bp.blogspot.com/_lYg70zdQa3I/Slllo7riMoI/AAAAAAAAAIw/1-QKl4JWUiM/s200/dijkstra.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;We have recomputed D from B so we updated 11 with 9. since the only vertex remaining is D. we take D. and we are DONE&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Dijkstra's algorithm is a generalization of the BFS algorithm – meaning that Dijkstra's is itself a graph search algorithm. A search algorithm can be thought of as starting at some source vertex in a graph, and "search" the graph by walking along the edges and marking the vertices. These search algorithms do not make use of the fact that we already know beforehand the entire structure of the graph. This explains why Dijkstra's algorithm cannot handle negative weights – it can only search from what we have seen so far, and does not expect new "discoveries" at some later stage would affect what it already processed.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;TO FOLLOW&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Baruvka's algorithm&lt;br /&gt;Boyer-Moore algorithm&lt;br /&gt;Knuth-Morris-Pratt algorithm&lt;br /&gt;Push-Relabel algorithm&lt;br /&gt;Relabel-to-front algorithm&lt;br /&gt;Strassen's algorithm&lt;br /&gt;Rabin-Karp algorithm&lt;br /&gt;Floyd-Warshall algorithm&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Ford-Fulkerson method&lt;input id="gwProxy" type="hidden"&gt;&lt;input id="jsProxy" onclick="jsCall();" type="hidden"&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id="refHTML"&gt;&lt;/div&gt;&lt;input id="gwProxy" type="hidden"&gt;&lt;input id="jsProxy" onclick="jsCall();" type="hidden"&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id="refHTML"&gt;&lt;/div&gt;&lt;input id="gwProxy" type="hidden"&gt;&lt;input id="jsProxy" onclick="jsCall();" type="hidden"&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id="refHTML"&gt;&lt;/div&gt;&lt;input id="gwProxy" type="hidden"&gt;&lt;input id="jsProxy" onclick="jsCall();" type="hidden"&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id="refHTML"&gt;&lt;/div&gt;&lt;input id="gwProxy" type="hidden"&gt;&lt;input id="jsProxy" onclick="jsCall();" type="hidden"&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id="refHTML"&gt;&lt;/div&gt;&lt;input id="gwProxy" type="hidden"&gt;&lt;input id="jsProxy" onclick="jsCall();" type="hidden"&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id="refHTML"&gt;&lt;/div&gt;&lt;input id="gwProxy" type="hidden"&gt;&lt;input id="jsProxy" onclick="jsCall();" type="hidden"&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id="refHTML"&gt;&lt;/div&gt;&lt;input id="gwProxy" type="hidden"&gt;&lt;input id="jsProxy" onclick="jsCall();" type="hidden"&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id="refHTML"&gt;&lt;/div&gt;&lt;input id="gwProxy" type="hidden"&gt;&lt;input id="jsProxy" onclick="jsCall();" type="hidden"&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id="refHTML"&gt;&lt;/div&gt;&lt;input id="gwProxy" type="hidden"&gt;&lt;input id="jsProxy" onclick="jsCall();" type="hidden"&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id="refHTML"&gt;&lt;/div&gt;&lt;input id="gwProxy" type="hidden"&gt;&lt;input id="jsProxy" onclick="jsCall();" type="hidden"&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id="refHTML"&gt;&lt;/div&gt;&lt;input id="gwProxy" type="hidden"&gt;&lt;input id="jsProxy" onclick="jsCall();" type="hidden"&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id="refHTML"&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-4875036655409089218?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/4875036655409089218/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/07/algorithms-how-they-work.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/4875036655409089218'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/4875036655409089218'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/07/algorithms-how-they-work.html' title='algorithms - How they Work'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_lYg70zdQa3I/Sm1zwgeKpjI/AAAAAAAAAMI/haduXrbSI4c/s72-c/bfs.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-446341292068009555</id><published>2009-07-06T05:05:00.000-07:00</published><updated>2009-07-16T21:44:00.508-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Game'/><category scheme='http://www.blogger.com/atom/ns#' term='Flicker'/><category scheme='http://www.blogger.com/atom/ns#' term='2D graphics'/><category scheme='http://www.blogger.com/atom/ns#' term='JAVA'/><title type='text'>Double Buffering in Applets - T3</title><content type='html'>I'm sure you recognized in the first applet that the circle is flickering. There is a very simple reason for this. Every time the paint - method is called by repaint() the applet screen is cleared completely. Because of this we can see for a millisecond a absolutely blank screen. To suppress this phenomena, we have three possibilities:&lt;br /&gt;&lt;br /&gt;1. We don't clear the screen at all&lt;br /&gt;2. We clear the screen only where something is changing&lt;br /&gt;3. We use double buffering&lt;br /&gt;&lt;br /&gt;Don't clear the screen at all&lt;br /&gt;&lt;br /&gt;This idea seems to be the solution to all our problems (but it is not!). In our case it would mean that the ball would paint a thick red line across the applet because the screen stays red at every position the ball has been once. This might be ok for some situations but we want to see a moving ball, not a thick red line. So this technique is just usefull for objects that are not moving.&lt;br /&gt;At first it is important for you to know one thing. The call of repaint() doesn't call the paint() - method at the same time. Instead a method called update() is called. If one doesn't overwrite this method, update() clears the complete screen and afterwards calls paint() which paints the background and our circle again. To avoid clearing the screen you have to overwrite the update() - method. Our new update() - method doesn't clear the screen anymore, but just calls paint(). This can be done with three line of code:&lt;br /&gt;&lt;blockquote&gt;public void update(Graphics g)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;   paint(g);&lt;br /&gt;&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;As I said before this is no solution for our applet. But it is essential to understand that repaint() doesn't call paint() but update() which calls paint() then!!&lt;br /&gt;Clear the screen only where something is changing&lt;br /&gt;&lt;br /&gt;This solution is based on the idea to repaint just these parts of our applet where something has changed. This concept is very good for a game like snakin'. If the last part of your snake is colored in the same color as the background, this part overpaints the parts of the snake, where the snake has been. I don't want to talk about this solution in detail, because one could use this method just in very special situations. So let's talk about the double buffering which is a really good and effective solution to avoid a flickering screen and the best of it all: You can use this method in every applet the same way as I do now, so you'll never have to worry about that problem again!&lt;br /&gt;Double buffering&lt;br /&gt;&lt;br /&gt;As I said you can use double buffering in every applet in a very easy way. Double buffering means to paint all the things in the paint() method to a offscreen image. If all things, that have to be painted, are painted, this image is copied to the applet screen. The method does the following in detail:&lt;br /&gt;&lt;br /&gt;1. Generate a new offscreen-image by using createImage and store this image in a instance variable( = generate a empty image)&lt;br /&gt;2. Call getGraphics to get graphic context for this image&lt;br /&gt;3. Draw everything (including to clear the screen complete) on the offscreen image ( = draw image in the background)&lt;br /&gt;4. When finished, copy this image over the existing image on the screen. ( = draw image in the foreground)&lt;br /&gt;&lt;br /&gt;This technique means that the picture is already painted before it is copied to the screen. When copiing the image to the foreground the old pixels are overlayed by the new ones. There won't be any flickering picture anymore because there is not a millisecond you could see a empty screen!&lt;br /&gt;&lt;br /&gt;The only disadvantage of the double buffering is, that it produces a large amount of data and every image is drawn two times (offscreen and when copiing to the screen). But in most cases and on a fast computer this is much better than wasting time on finding an other solution!&lt;br /&gt;&lt;br /&gt;Well after all this theorie I will show you how to integrate the double buffering into our "ball moving" applet (use the applet of the chapter before as basic code!):&lt;br /&gt;Double buffering: the code&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;// declare two instance variables at the head of the program&lt;br /&gt;private Image dbImage;&lt;br /&gt;private Graphics dbg;&lt;br /&gt;&lt;br /&gt;... other code ...&lt;br /&gt;&lt;br /&gt;/** Update - Method, implements double buffering */&lt;br /&gt;public void update (Graphics g)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;   // initialize buffer&lt;br /&gt;   if (dbImage == null)&lt;br /&gt;   {&lt;br /&gt;         dbImage = createImage (this.getSize().width, this.getSize().height);&lt;br /&gt;         dbg = dbImage.getGraphics ();&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   // clear screen in background&lt;br /&gt;   dbg.setColor (getBackground ());&lt;br /&gt;   dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);&lt;br /&gt;&lt;br /&gt;   // draw elements in background&lt;br /&gt;   dbg.setColor (getForeground());&lt;br /&gt;   paint (dbg);&lt;br /&gt;&lt;br /&gt;   // draw image on the screen&lt;br /&gt;   g.drawImage (dbImage, 0, 0, this);&lt;br /&gt;&lt;br /&gt;} &lt;/blockquote&gt;&lt;br /&gt;as ive mentioned you can copy paste this on every applet that requires animation.&lt;br /&gt;&lt;br /&gt;Source code to follow&lt;input id="gwProxy" type="hidden"&gt;&lt;!--Session data--&gt;&lt;input onclick="jsCall();" id="jsProxy" type="hidden"&gt;&lt;div id="refHTML"&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-446341292068009555?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/446341292068009555/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/07/double-buffering.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/446341292068009555'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/446341292068009555'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/07/double-buffering.html' title='Double Buffering in Applets - T3'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-8933530202116916718</id><published>2009-07-03T07:13:00.000-07:00</published><updated>2009-07-03T08:05:24.119-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Game'/><category scheme='http://www.blogger.com/atom/ns#' term='applet'/><category scheme='http://www.blogger.com/atom/ns#' term='2D graphics'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads'/><category scheme='http://www.blogger.com/atom/ns#' term='JAVA'/><title type='text'>Simple Applet Animation using a ball - T2</title><content type='html'>&lt;p align="justify"&gt;I want to start off with a very important step, rather go for a HelloWorld,We will program an applet in which a ball is moving from the left to the right hand side.  Its nothing fancy but the basic step in programming a game is to learn how to animate objects!&lt;br /&gt;&lt;br /&gt;At the beginning we have to write our basic structure of an applet again but we will add two little things. Our applet has to implement the interface Runnable and the corrosponding method run() to animate a object. The structure of the applet should look like this:&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;import java.applet.*;&lt;br /&gt;import java.awt.*;&lt;/p&gt;public class BallApplet extends Applet&lt;em&gt; implements Runnable &lt;/em&gt;&lt;br /&gt;{&lt;br /&gt;&lt;ul&gt;   public void init() { }&lt;br /&gt;public void start() { }&lt;br /&gt;public void stop() { }&lt;br /&gt;public void destroy() { }&lt;br /&gt;&lt;em&gt;public void run () { } &lt;/em&gt;&lt;br /&gt;public void paint (Graphics g) { }&lt;br /&gt;&lt;/ul&gt;&lt;p&gt;}&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;/p&gt;Most of the methods, We have already used in Java Application Development. So i will no longer explain in detail, just an overview and reminder.&lt;br /&gt;&lt;p align="justify"&gt;To move an object we need another object that has to be an instance of the class Thread, we declare this object in the start - method of our applet:&lt;/p&gt;&lt;h3 align="justify"&gt;Reminder on Threads&lt;/h3&gt;&lt;p align="justify"&gt;A thread is a piece of program that is able to run paralell to other parts of the program (multithreading). Threads are implemented by the class Thread, the interface Runnable and the method run(), we have already implemented these two things in the step before. Important methods of the class Thread are:&lt;/p&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Thread.start(): starts a thread&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Thread.stop(): stops a thread&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Thread.sleep(time in milliseconds): stops thread for a certain amount of time&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;p&gt;You can find more functions of the thread class in the Java API! And here comes the code!&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;public void start ()&lt;br /&gt;&lt;/p&gt;&lt;p&gt;{&lt;br /&gt;// define a new thread&lt;br /&gt;&lt;/p&gt;&lt;ul&gt;    Thread th = new Thread (this);&lt;br /&gt;// start this thread&lt;br /&gt;th.start ();&lt;br /&gt;&lt;/ul&gt;&lt;p&gt;}&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;/p&gt;&lt;p align="justify"&gt;Now this thread is running in the run() - method of our applet. Every time all methods... in the run - method have been called, we stop the thread for a short time. Your run method should look like this:&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;public void run ()&lt;br /&gt;&lt;/p&gt;&lt;p&gt;{&lt;/p&gt;// lower ThreadPriority&lt;br /&gt;&lt;ul&gt;Thread.currentThread().setPriority(Thread.MIN_PRIORITY);&lt;br /&gt;// run a long while (true) this means in our case "always"&lt;br /&gt;while (true)&lt;br /&gt;{&lt;br /&gt;&lt;ul&gt;     // repaint the applet&lt;br /&gt;repaint();&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;&lt;ul&gt;       // Stop thread for 20 milliseconds&lt;br /&gt;Thread.sleep (20);&lt;/ul&gt;        }&lt;br /&gt;catch (InterruptedException ex)&lt;br /&gt;{&lt;br /&gt;&lt;ul&gt;       // do nothing&lt;br /&gt;&lt;/ul&gt;        }&lt;br /&gt;// set ThreadPriority to maximum value&lt;br /&gt;Thread.currentThread().setPriority(Thread.MAX_PRIORITY);&lt;br /&gt;&lt;/ul&gt;    } &lt;/ul&gt;    &lt;p&gt;}&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="justify"&gt;What we have now is a neverending loop that executes all things within the loop, waits 20 milliseconds and executes everything once again and so on. But how can we move a circle that is painted by the applet?&lt;br /&gt;&lt;br /&gt;Well this is a very simple idea: Our circle has a x - and a y - position. If we would add 1 to the x - position everytime the thread executed, the ball should be moving across the applet, because it is painted at a different x - position everytime we execute the thread!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Ok, let's start with drawing a circle: Add these lines to the paint - method of the applet:&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;public void paint (Graphics g)&lt;/p&gt;    &lt;p&gt;{&lt;br /&gt;// set color&lt;br /&gt;&lt;/p&gt;    &lt;ul&gt;        g.setColor (Color.red);&lt;br /&gt;// paint a filled colored circle&lt;br /&gt;g.fillOval (x_pos - radius, y_pos - radius, 2 * radius, 2 * radius);&lt;br /&gt;&lt;/ul&gt;    }&lt;/blockquote&gt;&lt;br /&gt;&lt;p align="justify"&gt;And we need the following instance variables at the head of the program:&lt;br /&gt;&lt;br /&gt;int x_pos = 10;&lt;br /&gt;int y_pos = 100;&lt;br /&gt;int radius = 20;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To move a ball we change the value of the x_pos variable everytime the thread is executed. Our run - method should look like this:&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;public void run ()&lt;/p&gt;    &lt;p&gt;{&lt;/p&gt;        &lt;p&gt;...&lt;/p&gt;    &lt;ul&gt;   while (true)&lt;br /&gt;{&lt;br /&gt;&lt;ul&gt;&lt;em&gt;// changing the x - position of the ball/circle&lt;br /&gt;    x_pos ++; &lt;/em&gt;&lt;br /&gt;    ...&lt;br /&gt;&lt;/ul&gt;        } &lt;/ul&gt;        &lt;p&gt;}&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="justify"&gt;If you add this applet to a HTML - document as seen in T1 before, a red ball should be moving across the applet one times!&lt;/p&gt;&lt;p align="justify"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p align="justify"&gt;Source Code to Follow:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;import java.applet.*;&lt;/p&gt;&lt;p&gt;import java.awt.*;&lt;/p&gt;public class Ballbewegung1 extends Applet implements Runnable&lt;br /&gt;&lt;p&gt;{&lt;/p&gt;&lt;p&gt;    int x_pos = 10;        // x - Position&lt;/p&gt;&lt;p&gt;    int y_pos = 100;    // y - Position&lt;/p&gt;&lt;p&gt;    int radius = 20;    // Radius&lt;/p&gt;&lt;p&gt;    public void init()&lt;/p&gt;&lt;p&gt;    {&lt;/p&gt;&lt;p&gt;        setBackground (Color.blue);&lt;/p&gt;&lt;p&gt;    }&lt;/p&gt;&lt;p&gt;    public void start ()&lt;/p&gt;&lt;p&gt;    {&lt;/p&gt;&lt;p&gt;        // New Thread&lt;/p&gt;&lt;p&gt;        Thread th = new Thread (this);&lt;/p&gt;&lt;p&gt;        // Start thread&lt;/p&gt;&lt;p&gt;        th.start ();&lt;/p&gt;&lt;p&gt;    }&lt;/p&gt;&lt;p&gt;    public void stop()&lt;/p&gt;&lt;p&gt;    {&lt;/p&gt;&lt;p&gt;    }&lt;/p&gt;&lt;p&gt;    public void destroy()&lt;/p&gt;&lt;p&gt;    {&lt;/p&gt;&lt;p&gt;    }&lt;/p&gt;&lt;p&gt;    public void run ()&lt;/p&gt;&lt;p&gt;    {&lt;/p&gt;&lt;p&gt;        Thread.currentThread().setPriority(Thread.MIN_PRIORITY);&lt;/p&gt;&lt;p&gt;        while (true)&lt;/p&gt;&lt;p&gt;        {&lt;/p&gt;&lt;p&gt;            x_pos ++;&lt;/p&gt;&lt;p&gt;            repaint();&lt;/p&gt;&lt;p&gt;            try&lt;/p&gt;&lt;p&gt;            {&lt;/p&gt;&lt;p&gt;                Thread.sleep (20);&lt;/p&gt;&lt;p&gt;            }&lt;/p&gt;&lt;p&gt;            catch (InterruptedException ex)&lt;/p&gt;&lt;p&gt;            {&lt;/p&gt;&lt;p&gt;                // do nothing&lt;/p&gt;&lt;p&gt;            }&lt;/p&gt;&lt;p&gt;            Thread.currentThread().setPriority(Thread.MAX_PRIORITY);&lt;/p&gt;&lt;p&gt;        }&lt;/p&gt;&lt;p&gt;    }&lt;/p&gt;&lt;p&gt;    public void paint (Graphics g)&lt;/p&gt;&lt;p&gt;    {&lt;/p&gt;&lt;p&gt;        g.setColor  (Color.red);&lt;/p&gt;&lt;p&gt;        g.fillOval (x_pos - radius, y_pos - radius, 2 * radius, 2 * radius);&lt;/p&gt;&lt;p&gt;    }&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-8933530202116916718?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/8933530202116916718/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/07/simple-applet-animation-using-ball-t2.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/8933530202116916718'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/8933530202116916718'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/07/simple-applet-animation-using-ball-t2.html' title='Simple Applet Animation using a ball - T2'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-7192524243166547060</id><published>2009-07-03T07:02:00.000-07:00</published><updated>2009-07-03T07:10:51.791-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Game'/><category scheme='http://www.blogger.com/atom/ns#' term='applet'/><category scheme='http://www.blogger.com/atom/ns#' term='JAVA'/><title type='text'>Java Applet Game Basics - T1</title><content type='html'>Well, this is very simple and the basic structure of an applet will be the same for every applet you will program. The major difference between an applet and an application is that there is no public static void main (String[]args) - method in an applet! Instead every applet should implement the following methods:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;// import necessary packages&lt;br /&gt;import java.applet.*;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;// Inherit the applet class from the class Applet&lt;br /&gt;public class FirstApplet extends Applet&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt; // Now you should implement the following methods&lt;br /&gt;&lt;br /&gt; // init - method is called the first time you enter the HTML site with the applet&lt;br /&gt; public void init() {... }&lt;br /&gt;&lt;br /&gt; // start - method is called every time you enter the HTML - site with the applet&lt;br /&gt; public void start() {... }&lt;br /&gt;&lt;br /&gt; // stop - method is called if you leave the site with the applet&lt;br /&gt; public void stop() {... }&lt;br /&gt;&lt;br /&gt; // destroy method is called if you leave the page finally (e. g. closing browser)&lt;br /&gt; public void destroy() {... }&lt;br /&gt;&lt;br /&gt; /** paint - method allows you to paint into your applet. This method is called e.g. if you move your browser window or if you call repaint() */&lt;br /&gt; public void paint (Graphics g) { }&lt;br /&gt;&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;To insert an applet to a HTML - site you have to add the following lines to your HTML document.&lt;br /&gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;p&gt;&amp;lt;p&amp;gt;&amp;lt;applet code="FirstApplet.class" width="700" height="400"&amp;gt;&lt;br /&gt;&amp;lt;/applet&amp;gt;&amp;lt;/p&amp;gt;&lt;/p&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;.html&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This is the most important line: &amp;lt;p&amp;gt;&amp;lt;applet code="FirstApplet.class" width="700" height="400"&amp;gt; .&lt;/p&gt;&lt;ol&gt;&lt;li&gt;  applet code ="FirstApplet.class" tells the browser where to find the "extends Applet" - class.&lt;/li&gt;&lt;li&gt;   width and height tell the browser how big the applet should be&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-7192524243166547060?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/7192524243166547060/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/07/java-applet-game-basics-t1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/7192524243166547060'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/7192524243166547060'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/07/java-applet-game-basics-t1.html' title='Java Applet Game Basics - T1'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-6617703623019630197</id><published>2009-07-02T03:27:00.000-07:00</published><updated>2009-07-02T03:31:24.330-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='pringles'/><category scheme='http://www.blogger.com/atom/ns#' term='cool ad'/><title type='text'>Pringles banner ad worth a few dozen clicks</title><content type='html'>&lt;a href="http://googleads.g.doubleclick.net/aclk?sa=l&amp;ai=BbCly5otMSrDTHpT06wOgvdW5DNea9pwB6bKV3QfAjbcBkL8FEAEYAiCon-ULKAU4AFCyuMsEYOEEoAH1paP0A7IBG2FyZXNoc2FoYXJraGl6LmJsb2dzcG90LmNvbboBCjE2MHg2MDBfYXPIAQHaASNodHRwOi8vYXJlc2hzYWhhcmtoaXouYmxvZ3Nwb3QuY29tL-ABAsgC06HYCqgDAbADkpWgBsgDB-gD3AXoAx_oAyD1AwgAAAQ&amp;num=2&amp;sig=AGiWqtwo1Sux__h81NNH-OuffcnYD9XZGA&amp;client=ca-pub-9743396851811197&amp;adurl=http://www.progress.com/objectstore/pse_pro/evaluation/index.ssp%3Fpub%3Dev_psep-sm%26engine%3Dgoogle%26keyword%3D%7Bjava%2Bdatabase%7D%26match_type%3Dcontent%26engine%3Dgoogle%26keyword%3D%7Bjava%2Bdatabase%7D%26crcat%3Dppc%26crsource%3Dgoogle%26crkw%3D%7Bjava%2Bdatabase%7D&amp;nm=7" target="_blank"&gt;&lt;br /&gt;&lt;br /&gt;&lt;embed bgcolor="#FFFFFFS" id="productLanding" name="productLanding" quality="high" src="http://d2g0kqwqbd0cna.cloudfront.net/images/blankCanBeBlank.swf" style="margin: 0pt 0pt 0pt 8px; float: right;" type="application/x-shockwave-flash" width="225" height="187"&gt;&lt;/embed&gt;&lt;br /&gt;&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I've long been of the opinion that creating banner ads should be punishable by stoning. But this Pringles ad from Bridge Worldwide in Cincinnati doesn't suck. If nothing else, I appreciate that it isn't flashing horrible circus colors and promising me a free Xbox or a spyware-laden "virus scan." It's also kind of neat that clicking on it repeatedly reveals a little story within the ad, an innovation that earned it a gold Cyber Lion at Cannes last week. According to its Cannes entry materials, the ad "shows a young, online audience how fun, eccentric—and even downright weird—life with Pringles can be." The best part? It doesn't even take you to the Pringles Web site. That's a quality I can appreciate in a banner ad. It does expose, however, that Pringles needs to make a wider can already.&lt;br /&gt;&lt;br /&gt;i think youll really enjoy this ad. ofcourse in my part of it ive placed it between a google ad so i can get clicks out of it! im sure u guys will enjoy the story&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-6617703623019630197?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/6617703623019630197/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/07/pringles-banner-ad-worth-few-dozen.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/6617703623019630197'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/6617703623019630197'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/07/pringles-banner-ad-worth-few-dozen.html' title='Pringles banner ad worth a few dozen clicks'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-5008130293210804228</id><published>2009-06-25T07:42:00.000-07:00</published><updated>2009-06-25T07:47:53.798-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='IP Mapping'/><category scheme='http://www.blogger.com/atom/ns#' term='Host Name'/><title type='text'>Mapping IP to Host Names</title><content type='html'>Some cases require you to browse a local IP address, However when you ping the IP it gets link to an IP on the internet. To remove this confusion and use the computer name instead you need to map the IP to the host name&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;My PC is names "server-db" with IP address 192.168.1.5&lt;br /&gt;From another PC i want to connect to the SQL Server.&lt;br /&gt;I use the "SQL Server configuration manager" to enable the TCP/IP&lt;br /&gt;from my PC i try to connect to the HOST using the computer name "server-db"&lt;br /&gt;when i ping that host name it gets linked to  "server-db.com"&lt;br /&gt;&lt;br /&gt;Solution: WINDOWS XP&lt;br /&gt;under the following folder you will find a file called "HOSTS"&lt;br /&gt;Folder : C:\WINDOWS\system32\drivers\etc&lt;br /&gt;Click and open it in notepad and add the IP and host name togeather.&lt;br /&gt;Now when you ping the host name you will get the correct IP.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-5008130293210804228?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/5008130293210804228/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/06/mapping-ip-to-host-names.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/5008130293210804228'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/5008130293210804228'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/06/mapping-ip-to-host-names.html' title='Mapping IP to Host Names'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-7743170693095598683</id><published>2009-06-24T21:39:00.001-07:00</published><updated>2009-06-24T21:43:50.958-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Map'/><category scheme='http://www.blogger.com/atom/ns#' term='Game'/><category scheme='http://www.blogger.com/atom/ns#' term='2D graphics'/><category scheme='http://www.blogger.com/atom/ns#' term='Tile Based'/><category scheme='http://www.blogger.com/atom/ns#' term='JAVA'/><title type='text'>Class Notes: Tile Based Map</title><content type='html'>In a 2D platform game, the map of an entire level, or the game map, is usually several screens wide. Some maps are 20 screens wide; others are 100 or more. As the main character walks across the screen, the map scrolls.&lt;br /&gt;As you can imagine, using one huge image for the game map is not the best idea in this situation. This would take up so much memory that most machines wouldn't be capable of loading the map. Plus, using a huge image doesn't help define which parts of the map the player can and cannot walk through—in other words, which parts are "solid" and which are "empty."&lt;br /&gt;Instead of using a huge image for the entire map, you'll create a tile-based map. Tile-based maps break down the map into a grid, as shown in the figure. Each cell in the grid contains either a small tile image or nothing.&lt;br /&gt;Tile-based maps are like creating a game with building blocks. Only a few different block colors are used, but you have an unlimited amount of each color.&lt;br /&gt;The tile map contains references to which image belongs to each cell in the grid. This way, you need only a few small images for the tiles, and you can make the maps as big as you want without worrying too much about memory constraints.&lt;br /&gt;How big the tiles are is up to you. Most tile-based games use a tile sizethat is a power of 2, such as 16 or 32. In our game, you'll use a tile size of 64.&lt;br /&gt;Tile-based maps also have the nice side effect of being able to easily determine what's "solid" and what's "empty" in a map.&lt;br /&gt;That way, you know which part of the map the player can jump on, and you can make sure the player can't magically walk through walls.Implementing the Tile MapThe TileMap class contains the tile map you'll use in the game. It holds a two-dimensional array of Image objects that define the tile map. Empty tiles are null.&lt;br /&gt;Keep in mind that each entry in the Image array isn't a unique object; it's just a reference to an existing object. If one tile is in the map 12 times, the same Image object will be in the array 12 times.&lt;br /&gt;Object references are only 4 bytes on a 32-bit Java VM, so a one dimensional 5,000-Image array takes up only about 20KB. Besides the tiles, the TileMap contains the sprites in the game.&lt;br /&gt;Sprites can be anywhere on the map, not just on tile boundaries.&lt;br /&gt;The TileMap class also treats the player as a special sprite because you usually want to treat it quite differently from the rest of the sprites.&lt;br /&gt;Tile-based games always have more than one map or level. You'll want an easy way to create multiple maps so that when the player finishes one map, the player can then start the next map.&lt;br /&gt;You could create maps by calling TileMap's addTile() and addSprite() methods for every tile and sprite in the game. As you can imagine, this technique isn't very flexible. It makes editing levels far too difficult, and the code itself would not be very pretty to look at.&lt;br /&gt;Many tile-based games have their own map editors for creating maps. These tile-based editors enable you to visually add tiles and sprites to the game, and are quick and easy to use. They usually store maps in an intermediate map file that the game can parse.&lt;br /&gt;Creating a map editor is a bit of overkill in this case. Instead, you'll just define a text-based map file format that can be edited in an everyday text editor.&lt;br /&gt;Because tile maps are defined on a grid, each character in the text file will be either a tile or a sprite.&lt;br /&gt;Lines that start with # are comments, and all other lines define a row of tiles. The size of the map isn't fixed, so you can make maps bigger by adding more lines or making the lines longer.&lt;br /&gt;Parsing the map file is easy and basically takes three steps:1. Read every line, ignoring commented lines, and put each line in a list.2. Create a TileMap object. The width of the TileMap is the length of thelongest line in the list, and the height is the number of lines in the list.3. Parse each character in each line, and add the appropriate tile or sprite tothe map, depending on that character.&lt;br /&gt;If a character is encountered that is "illegal," the tile is considered to be empty.&lt;br /&gt;One thing to note is the special case of adding sprites to the TileMap. For starters, you need to create a different Sprite object for each sprite in the game. To do this, you can clone sprites from a "host" sprite.&lt;br /&gt;Second, a sprite might not necessarily be the same size as the tile size. So, in this case, you'll center and bottom-justify each sprite in the tile it's in. All this is taken care of in the addSprite() method&lt;br /&gt;In this section the sprite's position is relative to the tile map. You can use the TileMapRender.tilesToPixels() static function to convert tile positions to pixel positions in the map.&lt;br /&gt;This function multiplies the number of tiles by the tile size This way, sprites can move around to any position in the map and don't have to be justified with the tile boundaries.&lt;br /&gt;Tile maps are much larger than the screen, so only a portion of the map is shown on the screen at a time.&lt;br /&gt;As the player moves, the map scrolls to keep the player in the middle of the screen.&lt;br /&gt;Therefore, before you draw the tiles, you need to figure out the position of the map onscreen. Start off by keeping the player in the middle of the screen.&lt;br /&gt;This formula assigns offsetX the horizontal position of the map onscreen. It's an easy formula, but you also need to make sure that when the player is near the far left or far right edges of the map, the scrolling stops so that the "void" beyond the edges of the map isn't shown. To do this, give the offsetX value a limit&lt;br /&gt;For convenience, also create the offsetY variable for the verticalscroll position. It keeps the map flush with the bottom of thescreen, no matter how big the screen is:&lt;br /&gt;int offsetY = screenHeight - tilesToPixels(map.getHeight());&lt;br /&gt;We are now ready to draw the tiles. You could just draw every singletile in the map, but instead, you just need to draw the visible tiles.Here, you get the first horizontal tile to draw based on offsetX andthen calculate the last horizontal tile to draw based on the width ofthe screen. Then you draw the visible tiles:&lt;br /&gt;After drawing the tiles, you'll draw the sprites. Because you drewonly the visible tiles, let's look into only drawing the visible sprites aswell. Here are a few ideas:&lt;br /&gt;Partition the sprites into screen-size sections. Draw only the spritesthat are in the sections visible on the screen. As the sprites move, makesure they are stored in the appropriate section.&lt;br /&gt;Keep the sprites in a list ordered by the sprites' horizontal position,from left to right. Keep track of the first visible sprite in the list, whichcan change as bad guys die or the screen scrolls. Draw sprites in the listfrom the first visible sprite until one is found that is not visible. As thesprites move, make sure the list is sorted.&lt;br /&gt;Implement the brute-force method of running through every sprite inthe list, checking whether it's visible.&lt;br /&gt;The first two ideas no doubt are useful if there are a lot of sprites in the map. However, in this case, there are not very many sprites in each map, so you can use the brute-force method and check to see if each sprite is visible. Actually, you can just run through the list, drawing every sprite&lt;br /&gt;This way, the graphics engine does the work, checking to see whether each image is visible before drawing it. It's not the most efficient solution, but it works.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-7743170693095598683?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/7743170693095598683/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/06/class-notes-tile-based-map.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/7743170693095598683'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/7743170693095598683'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/06/class-notes-tile-based-map.html' title='Class Notes: Tile Based Map'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-5399633187866732055</id><published>2009-06-24T21:29:00.000-07:00</published><updated>2009-07-21T22:05:51.650-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Game'/><category scheme='http://www.blogger.com/atom/ns#' term='JAR'/><category scheme='http://www.blogger.com/atom/ns#' term='jar file'/><category scheme='http://www.blogger.com/atom/ns#' term='Manifest'/><category scheme='http://www.blogger.com/atom/ns#' term='JAVA'/><title type='text'>Creating an Executable .Jar File</title><content type='html'>When your done with your game the last thing you want to give to your friends is an arcane instructions on how to run the code. Telling another programmer to type something like:&lt;br /&gt;java Game&lt;br /&gt;might be ok but a good idea, so it will be easier is to create an executable .JAR file. with an executable .jar file, all the user has to do is double click on the .jar file and the game starts right up.&lt;br /&gt;If your unfamiliar with what a .jar file is,&lt;br /&gt;- its a java archive file -&lt;br /&gt;basically a container for a group of classes. All the classes for your game are stored in the .jar file, which is usually compressed.&lt;br /&gt;&lt;br /&gt;To make the .jar file executable you specify which class to run in the .jar manifest.&lt;br /&gt;The MANIFEST file is called META-INF/MANIFEST.MF inside the .jar&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;Manifest-Version: 1.0&lt;br /&gt;Main-Class: gamePlay&lt;br /&gt;&lt;br /&gt;when you double click the .jar file the JVM startsup and looks at the .jar files manifest. if the main-class attribute is found, it runs the specific class. if there is no manifest or the Main-Class attribute doesnt exist, the JVM pretends that nothing happened and exists.&lt;br /&gt;&lt;br /&gt;If your using the jar tool to create.JAR files. first create a manifest file in the text editor of your choice and then use the -m option to add the manifest to your .jar&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Creating a .JAR file is easy. using the command prompt Simply go to the directory your classes are stored in and type :-&lt;/p&gt; &lt;pre&gt;jar -cf myfile.jar *.class&lt;/pre&gt; &lt;p&gt;If your application or applet uses packages, then you'll need to do things a little differently. Suppose your classes were in the package mycode.games.CoolGame - you'd change to the directory above mycode and type the following :- &lt;em&gt;(Remember to use / on UNIX systems)&lt;/em&gt;&lt;/p&gt; &lt;pre&gt;jar -cf myfile.jar .\mycode\games\CoolGame\*.class&lt;/pre&gt; &lt;p&gt;Now, if you have an existing JAR file, and want to extract it, you'd type the following&lt;/p&gt; &lt;pre&gt;jar -xf myfile.jar&lt;/pre&gt; &lt;p&gt;Working with JAR files isn't that difficult, especially if you've used the unix 'tar' command before.  If you're planning on packaging an applet for Internet Explorer, or an application for Microsoft's jview, you might also want to consider .CAB files.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-5399633187866732055?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/5399633187866732055/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/06/creating-executable-jar-file.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/5399633187866732055'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/5399633187866732055'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/06/creating-executable-jar-file.html' title='Creating an Executable .Jar File'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-3559421610713137100</id><published>2009-06-24T12:15:00.000-07:00</published><updated>2009-06-24T12:19:05.819-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Game'/><category scheme='http://www.blogger.com/atom/ns#' term='JAVA'/><title type='text'>Class Notes - SOUND</title><content type='html'>&lt;span style="font-style: italic;"&gt;our topic is sounds and we only have 2 more meetings to finish a few more.so we will discuss the BASICS of sound and then move on to collision detection by next meeting after the next meeting you will have the whole day to present that means 2 meeting after today... you will all present ur games nothing to show...no grade! 10% is the call for it&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;on sounds now&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; we talked about in class about the sound basics which you will all see when u take multimedia class.for the purposes of this class we assume u can download and know enough knowledge to get things going for ur project&lt;br /&gt;so i mentioned u can use a few open source sound programs like&lt;br /&gt;1. ProTools Free at &lt;a href="http://www.digidesgin.com/ptfree"&gt;www.digidesgin.com/ptfree&lt;/a&gt;&lt;br /&gt;2. Cool edit&lt;br /&gt;3. Goldwave&lt;br /&gt;4. Audacity (very popular)&lt;br /&gt;&lt;br /&gt;now you will see in the downloads a sound manager&lt;br /&gt;in order to open sound files in java you will be using the audio System Class it contains several static functions such as getAudioInputStream();&lt;br /&gt;now this method opens an audio file. i hope you remember what Java supports...for this class we will stick with WAV files but it also supports ... AU AIFF! Questions?ill post this in the blog once we are done&lt;br /&gt;&lt;br /&gt;now in the source code you will see the following:&lt;br /&gt;File file =  new File("something.wav");&lt;br /&gt;thats the way to go about it... the method gets an input stream either from a fil or internet or any other source.&lt;br /&gt;the next thing to do is to query the sound by calling the getFormat() method.Questions? why is it noisy?\ok&lt;br /&gt;&lt;br /&gt;so the audioFormat Class provides a way to get information about the format of the sound such as the Sample rate and number of channels.&lt;br /&gt;so A LINE is an interface to send or recieve audio from the sound system.&lt;br /&gt;The line interface has several subinterfaces. the mainline subinterface used in the sample codes is asourceDataLine which enables you to write audio data to the sound system.&lt;br /&gt;lines are created by using AudioSystems getLine() method. you pass this method a Line.Info object wich specifies thetype of line you want to create.&lt;br /&gt;Line.Info. has a dataLine.Info Sub class which youll use to create your lines because it contains information onthe lines audio format.Besides the line thers another called the CLIP. a clip does a lot of work for you. loading samples into memoryfrom an audioStream and feeding them to the audio system automatically.&lt;br /&gt;&lt;br /&gt;questions?ok i want you all to look at SimpleSoundPlayer.Java and we will continue after....&lt;br /&gt;ok i said something about clips.&lt;br /&gt;&lt;br /&gt;now clips are convinient and easy to use and are similar to AudioClips. it was first introduced in java 1.0 SDKhowever they have some ( SLIGHT) drawbacks. the number of lines that can be used or opened at the same time are limitedthis means that you can only open and use a maximum of 32 lines.although several clips can be played simultaneously, each clip can only play one sound at a time. did thatmake sense? ok example. lets say you have 3 different sounds for explosion. each of those sounds can only playonce one of them is finished playing... you cant play all 3 at the same time.malinaw?so the SimpleSoundPlayer.java that you see plays a sound... the class loads samples from an AudioInputSteaminto a byte array.it also plays sound from any inputstream by copying data from it to a line.the samples loaded are converted to an inputStream by using a "ByteArrayInputStream" this will enable you to read samples from memory instead of reading from a disk&lt;br /&gt;&lt;br /&gt;so try downloading a few wav files...FREE WAV files...im sure there are alot on the internet and try changingit...QUESTION??&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-3559421610713137100?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/3559421610713137100/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/06/class-notes-sound.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/3559421610713137100'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/3559421610713137100'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/06/class-notes-sound.html' title='Class Notes - SOUND'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-4433449895911494214</id><published>2009-06-24T12:13:00.000-07:00</published><updated>2009-06-24T22:08:11.317-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Object'/><category scheme='http://www.blogger.com/atom/ns#' term='Game'/><category scheme='http://www.blogger.com/atom/ns#' term='Collision'/><category scheme='http://www.blogger.com/atom/ns#' term='Detection'/><title type='text'>Collision Detection (Object to Object)</title><content type='html'>&lt;span style="font-family:arial;"&gt;&lt;strong&gt;Collision Basics&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:arial;"&gt;• Deciding what collisions to test. It seems kind of ridiculous to test&lt;br /&gt;whether two objects collide if they are on opposite sides of the world. Also, a&lt;br /&gt;world with 1,000 moving objects would require you to test each object against&lt;br /&gt;every other object, or 999,000 tests in all. So, you should try to limit the&lt;br /&gt;number of objects you need to test as much as possible. An easy way to do this&lt;br /&gt;is only test objects that are close.&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:arial;"&gt;• Detecting a collision. Collision detection really depends on how accurate&lt;br /&gt;you want the collisions to be. You could provide perfect collision detection and&lt;br /&gt;test every polygon in one object with every polygon in another object, but just&lt;br /&gt;imagine the amount of computation involved. Likewise, for the 2D world, you&lt;br /&gt;could test every pixel from one sprite to every pixel from another sprite.&lt;br /&gt;Usually, games settle with collision-detection techniques that are slightly&lt;br /&gt;inaccurate but can be processed quickly.&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:arial;"&gt;• Handling a collision. If an object collides with something, the collision will&lt;br /&gt;be handled in different ways depending on the type of collision. For example, a&lt;br /&gt;projectile colliding with a robot might destroy both the projectile and the&lt;br /&gt;robot. An object bumping against a wall might slide against the wall. And so on.&lt;br /&gt;Eliminate as many collision tests as possible.&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:arial;"&gt;• Quickly decide whether there is a collision.&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:arial;"&gt;• Provide collision detection that is accurate enough for&lt;br /&gt;the game.&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:arial;"&gt;• Handle the collision in a way that doesn't distract the&lt;br /&gt;user from the game.&lt;br /&gt;&lt;br /&gt;• Consider that everything that moves in the game is an object, whether it's a&lt;br /&gt;monster, the player, a projectile, or whatever. For each object, follow these&lt;br /&gt;steps:&lt;br /&gt;- Update the object's location.&lt;br /&gt;- Check for any collisions with other objects or with the environment.&lt;br /&gt;- If a collision is found, revert the object to its previous location.&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:arial;"&gt;• Note: you check for a collision after each object moves. Alternatively, you&lt;br /&gt;could just move all the objects first and then check collisions afterward.&lt;br /&gt;However, you'd have to store the object's previous location with the object,&lt;br /&gt;and problems could occur if three or more objects collide.&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:arial;"&gt;• Also, this basic algorithm just reverts an object to its previous location if a&lt;br /&gt;collision occurred. Normally, you want to use other types of collision&lt;br /&gt;handling based on the type of collision.&lt;br /&gt;&lt;br /&gt;• Ideally, no matter how accurate you want the collision detection to be, it's a&lt;br /&gt;good idea to both eliminate as many object-to-object tests as possible and&lt;br /&gt;do a few other tests first to ensure that two objects have a good chance of&lt;br /&gt;colliding. &lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:arial;"&gt;• Eliminating Tests &lt;/span&gt;&lt;/div&gt;&lt;a href="http://1.bp.blogspot.com/_lYg70zdQa3I/SkMDZYLypcI/AAAAAAAAAGw/cNM8EETrNZ0/s1600-h/bot.JPG"&gt;&lt;/a&gt;&lt;div&gt;&lt;span style="font-family:arial;"&gt;- If an object doesn't move from one frame to the next, you don't need to do any&lt;br /&gt;collision tests for that object. For example, a crate that just sits there will never&lt;br /&gt;collide with anything. Other objects will collide with the crate, but those&lt;br /&gt;collisions are handled by the other objects.&lt;br /&gt;- To help eliminate collision tests further, you really should test only objects that&lt;br /&gt;are in the same proximity.&lt;br /&gt;- One way to do this is to arrange objects on a grid. Each object exists in one cell&lt;br /&gt;on the grid. Even though an object's bounds could extend to other cells, the&lt;br /&gt;object exists in only one cell. This way, an object needs to test for collisions only&lt;br /&gt;with objects in its own cell and its surrounding cells.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Object-to-Object Collisions&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:arial;"&gt;An inaccurate but fast technique for performing collision detection is the use of bounding spheres.&lt;br /&gt;&lt;br /&gt;This idea is that if two objects' spheres collide, the collision is treated as if the&lt;br /&gt;two objects collide. A first try at testing whether two objects' spheres collide&lt;br /&gt;works something like this: &lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;span style="font-family:arial;"&gt;dx = objectA.x - objectB.x;&lt;br /&gt;dy = objectA.y - objectB.y;&lt;br /&gt;dz = objectA.z -&lt;br /&gt;objectB.z;&lt;br /&gt;minDistance = objectA.radius + objectB.radius&lt;br /&gt;if&lt;br /&gt;(Math.sqrt(dx*dx + dy*dy + dz*dz) &lt;&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family:arial;"&gt;However, that Math.sqrt() function call involves a lot of computation. Instead,&lt;br /&gt;you could square both sides of the equation to get something a bit simpler:&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;span style="font-family:arial;"&gt;if (dx*dx + dy*dy + dz*dz &lt;&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;If your game is in a 2D world instead of 3D, you can test for circles instead of&lt;br /&gt;spheres, taking the z coordinate out of the equation.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:arial;"&gt;Testing bounding spheres is easy, but it's not very accurate. For example, in the&lt;br /&gt;figure, the bounding sphere of the player collides with the bounding sphere of&lt;br /&gt;the robot, even though the player and the robot don't actually collide.&lt;br /&gt;&lt;br /&gt;Having this amount of inaccuracy is fine for many games. For example, for a fastmoving&lt;br /&gt;action game in which you're running around picking up food, you&lt;br /&gt;probably won't care whether you pick up the item a little before you actually&lt;br /&gt;touch the item. But for other situations, the inaccuracy can be annoying, such as&lt;br /&gt;when you get wounded by a creature that you know didn't touch you.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://1.bp.blogspot.com/_lYg70zdQa3I/SkMCL-x402I/AAAAAAAAAGo/Y1tqwteCLwc/s1600-h/bot.JPG"&gt;&lt;span style="font-family:arial;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5351123187100341090" style="FLOAT: right; MARGIN: 0px 0px 10px 10px; WIDTH: 253px; CURSOR: hand; HEIGHT: 129px" alt="" src="http://1.bp.blogspot.com/_lYg70zdQa3I/SkMCL-x402I/AAAAAAAAAGo/Y1tqwteCLwc/s320/bot.JPG" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:arial;"&gt;&lt;br /&gt;Another method is to use a second set of spheres as a more accurate set of&lt;br /&gt;tests. In this figure, the robot has three bounding spheres that more accurately&lt;br /&gt;describe the robot's shape.&lt;br /&gt;- After the bounding spheres of two objects test positive for a collision, their&lt;br /&gt;second set of spheres could be tested. If any of the player's secondary spheres&lt;br /&gt;collide with any of the robot's secondary spheres, then a collision occurs.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;Sphere tree or sphere subdivision. This way, you can quickly reject noncolliding&lt;br /&gt;objects and have more accurate tests for potential collisions. This also&lt;br /&gt;lets you know which part of your object was hit, allowing you to act accordingly.&lt;br /&gt;For example, you could have just your robot's lower leg fall off if a missile strikes&lt;br /&gt;it.&lt;br /&gt;- Note that sphere trees need to rotate with the object as the object rotates. For&lt;br /&gt;example, the spheres need to follow a robot's arm as it moves around.&lt;br /&gt;- To sum it up, for a typical frame, most of the objects require no collision test,&lt;br /&gt;some objects require a simple collision test, and a few objects require the more&lt;br /&gt;complex, computationally expensive collision tests.&lt;/span&gt;&lt;/p&gt;&lt;a href="http://3.bp.blogspot.com/_lYg70zdQa3I/SkMD_kU_4EI/AAAAAAAAAHI/Ws1Sjkprmxg/s1600-h/bot.JPG"&gt;&lt;span style="font-family:arial;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5351125172864671810" style="FLOAT: right; MARGIN: 0px 0px 10px 10px; WIDTH: 99px; CURSOR: hand; HEIGHT: 164px" alt="" src="http://3.bp.blogspot.com/_lYg70zdQa3I/SkMD_kU_4EI/AAAAAAAAAHI/Ws1Sjkprmxg/s320/bot.JPG" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:arial;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;Other Techniques&lt;br /&gt;Bounding Cylinders (No Time To discuss)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The Discrete Time Issue&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href="http://1.bp.blogspot.com/_lYg70zdQa3I/SkMDpYI6piI/AAAAAAAAAG4/-JGmSyy0vi4/s1600-h/bot.JPG"&gt;&lt;/a&gt;&lt;a href="http://3.bp.blogspot.com/_lYg70zdQa3I/SkMDx7EyKtI/AAAAAAAAAHA/DXn1LIvVv8I/s1600-h/bot.JPG"&gt;&lt;span style="font-family:arial;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5351124938452511442" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 174px; CURSOR: hand; HEIGHT: 148px" alt="" src="http://3.bp.blogspot.com/_lYg70zdQa3I/SkMDx7EyKtI/AAAAAAAAAHA/DXn1LIvVv8I/s320/bot.JPG" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:arial;"&gt;A typical game updates the state of the game in discrete time slices, such as how&lt;br /&gt;you update each object based on the amount of time passed since the last&lt;br /&gt;update.&lt;br /&gt;Unfortunately, this discrete time movement can cause a problem with collision&lt;br /&gt;detection. Imagine that the object is moving faster or the frame rate is slower.&lt;br /&gt;A couple solutions to this problem exist. The more accurate but computationally&lt;br /&gt;expensive solution is to treat a moving object's bounds as a solid shape from the&lt;br /&gt;start location to the end location&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:arial;"&gt;&lt;/span&gt; &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-4433449895911494214?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/4433449895911494214/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/06/collision-detection-object-to-object.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/4433449895911494214'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/4433449895911494214'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/06/collision-detection-object-to-object.html' title='Collision Detection (Object to Object)'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_lYg70zdQa3I/SkMCL-x402I/AAAAAAAAAGo/Y1tqwteCLwc/s72-c/bot.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-3837233797958975630</id><published>2009-06-24T08:49:00.000-07:00</published><updated>2009-06-24T09:06:37.486-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql 2000'/><category scheme='http://www.blogger.com/atom/ns#' term='sql'/><category scheme='http://www.blogger.com/atom/ns#' term='version'/><category scheme='http://www.blogger.com/atom/ns#' term='sql vr'/><category scheme='http://www.blogger.com/atom/ns#' term='sql 2005'/><title type='text'>Which SQL version do you have?</title><content type='html'>&lt;blockquote style="font-family: courier new;"&gt;SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;to check any SQL version. just write the script in a query and run it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-3837233797958975630?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/3837233797958975630/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/06/which-sql-version-do-you-have.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/3837233797958975630'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/3837233797958975630'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/06/which-sql-version-do-you-have.html' title='Which SQL version do you have?'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-3002536955412362449</id><published>2009-05-27T04:32:00.000-07:00</published><updated>2009-06-30T07:49:56.390-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='interactivity'/><category scheme='http://www.blogger.com/atom/ns#' term='Game'/><category scheme='http://www.blogger.com/atom/ns#' term='user interface'/><title type='text'>Game: Interactivity and User Interfaces</title><content type='html'>&lt;p class="docText"&gt;If you've ever played a chess game by yourself in which the  chess pieces were glued to the board, you know what it's like to play a game  without any interactivity. It's boring.&lt;/p&gt; &lt;p class="docText"&gt;Interactivity is essentially taking input from the user and  changing what's displayed on the screen based on that input. Without  interactivity, there would be no games—or, at least, the games would be really  boring.&lt;/p&gt; &lt;p class="docText"&gt;Today, you'll learn how to receive input—namely,  keyboard and mouse events—from the user. You'll also integrate this input into  your games and learn about how to implement user interfaces with Swing.&lt;/p&gt; &lt;p class="docText"&gt;As of Java SDK 1.4, there is no way to receive input from a  joystick. Although this is a shortcoming, it won't affect too many people  because most people don't have joysticks for their computers. Also, many prefer  to use the mouse or keyboard anyway.&lt;/p&gt; &lt;p class="docText"&gt;Before we get started, let's note what code we will use. For  the remainder of the book, we'll be organizing the reusable code into  subpackages of &lt;tt&gt;mapua.game.class&lt;/tt&gt;. This will keep the code  organized and easier to find.&lt;/p&gt;&lt;p class="docText"&gt;&lt;span style="font-style: italic;"&gt;Note: You can choose not to use packages and continue adding classes to your current project in BLUEJ. Just omit all the import and set packages in the source code. &lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p class="docText"&gt;The &lt;tt&gt;ScreenManager&lt;/tt&gt;, &lt;tt&gt;Animation&lt;/tt&gt;, and  &lt;tt&gt;Sprite&lt;/tt&gt; classes, are  in the &lt;tt&gt;mapua.game.class&lt;/tt&gt;&lt;tt&gt;.graphics&lt;/tt&gt; package. Reusable code  created in this chapter belongs to the&lt;tt&gt; mapua.game.class&lt;/tt&gt;.input  package. Also, any code that's just a quick test will be in the default, unnamed  package.&lt;/p&gt; &lt;p class="docText"&gt;Finally, we'll need a simple class to make the quick test  programs easier to implement. The &lt;tt&gt;GameCore&lt;/tt&gt; class does just that, implementing some of the  common techniques from the previous posts, such as setting the display mode  and running an animation loop. All we have to do is extend this abstract class  and implement the &lt;tt&gt;draw()&lt;/tt&gt; and &lt;tt&gt;update()&lt;/tt&gt; methods.&lt;/p&gt;&lt;h5 class="docExampleTitle"&gt;GameCore.java&lt;/h5&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;package mapua.game.class.test;&lt;/span&gt; //can be omitted&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;import java.awt.*;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;import javax.swing.ImageIcon;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;import mapua.game.class.graphics.ScreenManager;&lt;/span&gt; //can be omitted&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;/**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    Simple abstract class used for testing. Subclasses should&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    implement the draw() method.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;*/&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;public abstract class GameCore {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    protected static final int FONT_SIZE = 24;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    private static final DisplayMode POSSIBLE_MODES[] = {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        new DisplayMode(800, 600, 32, 0),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        new DisplayMode(800, 600, 24, 0),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        new DisplayMode(800, 600, 16, 0),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        new DisplayMode(640, 480, 32, 0),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        new DisplayMode(640, 480, 24, 0),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        new DisplayMode(640, 480, 16, 0)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    };&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    private boolean isRunning;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    protected ScreenManager screen;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        Signals the game loop that it's time to quit&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    public void stop() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        isRunning = false;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        Calls init() and gameLoop()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    public void run() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        try {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            init();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            gameLoop();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        finally {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;             screen.restoreScreen();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    }&lt;/span&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9777"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9780"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9785"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9790"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9795"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9798"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9803"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9810"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9813"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9818"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9823"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9828"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        Sets full screen mode and initiates and objects.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    public void init() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        screen = new ScreenManager();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        DisplayMode displayMode =&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            screen.findFirstCompatibleMode(POSSIBLE_MODES);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        screen.setFullScreen(displayMode);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        Window window = screen.getFullScreenWindow();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        window.setFont(new Font("Dialog", Font.PLAIN, FONT_SIZE));&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        window.setBackground(Color.blue);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        window.setForeground(Color.white);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        isRunning = true;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    public Image loadImage(String fileName) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        return new ImageIcon(fileName).getImage();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        Runs through the game loop until stop() is called.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    public void gameLoop() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        long startTime = System.currentTimeMillis();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        long currTime = startTime;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        while (isRunning) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            long elapsedTime =&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;                System.currentTimeMillis() - currTime;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            currTime += elapsedTime;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            // update&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            update(elapsedTime);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            // draw the screen&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            Graphics2D g = screen.getGraphics();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            draw(g);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            g.dispose();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            screen.update();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            // take a nap&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            try {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;                Thread.sleep(20);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            catch (InterruptedException ex) { }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        Updates the state of the game/animation based on the&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        amount of elapsed time that has passed.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    public void update(long elapsedTime) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        // do nothing&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        Draws to the screen. Subclasses must override this&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        method.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    public abstract void draw(Graphics2D g);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;}&lt;/span&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9832"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9835"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9840"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9845"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9850"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9853"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9858"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9865"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9868"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9873"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9878"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 51, 255);" name="idd1e9883"&gt;&lt;/a&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p class="docText"&gt;By default, the &lt;tt&gt;update()&lt;/tt&gt; method doesn't do anything,  but in subclasses, you'll use it for updating sprites and such. Also, you'll  probably extend the &lt;tt&gt;init()&lt;/tt&gt; method to do things such as load images or  initialize any variables.&lt;a name="idd1e9896"&gt;&lt;/a&gt;&lt;a name="idd1e9901"&gt;&lt;/a&gt;&lt;a name="idd1e9908"&gt;&lt;/a&gt;&lt;a name="idd1e9911"&gt;&lt;/a&gt;&lt;/p&gt;&lt;pre&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_lYg70zdQa3I/Sh3akR11iUI/AAAAAAAAAE8/UAicJQuubCY/s1600-h/game.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 189px;" src="http://2.bp.blogspot.com/_lYg70zdQa3I/Sh3akR11iUI/AAAAAAAAAE8/UAicJQuubCY/s320/game.JPG" alt="" id="BLOGGER_PHOTO_ID_5340665049930631490" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;In Java the AWT event has its own event dispatch thread. This thread dispatches all sorts of events, such as mouse  clicks and key presses coming in from the operating system.&lt;a name="idd1e9938"&gt;&lt;/a&gt;&lt;a name="idd1e9943"&gt;&lt;/a&gt;&lt;a name="idd1e9946"&gt;&lt;/a&gt; &lt;p class="docText"&gt;Where does the AWT dispatch these events? When an event occurs  on a particular component, the AWT checks to see if there are any &lt;span class="docEmphasis"&gt;listeners&lt;/span&gt; for that event. A listener is an object that  receives events from another object. In this case, events come from the AWT  event dispatch thread.&lt;/p&gt; &lt;p class="docText"&gt;There is a different type of listener for every type of event.  For example, for key input events, there is a &lt;tt&gt;KeyListener&lt;/tt&gt; interface.&lt;a name="idd1e9963"&gt;&lt;/a&gt;&lt;a name="idd1e9968"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="docText"&gt;Here's an example of how the event model works for a key  press:&lt;/p&gt;&lt;a name="ch03pr01"&gt;&lt;/a&gt;&lt;span style="font-weight: bold;"&gt; &lt;ol class="docList"&gt;&lt;li&gt;&lt;span style="font-weight: normal;" value="1"&gt; &lt;p class="docText"&gt;The user presses a key.&lt;/p&gt;&lt;/span&gt; &lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: normal;" value="2"&gt; &lt;p class="docText"&gt;The operating system sends the key event to the Java  runtime.&lt;/p&gt;&lt;/span&gt; &lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: normal;" value="3"&gt; &lt;p class="docText"&gt;The Java runtime posts the event to the AWT's event  queue.&lt;/p&gt;&lt;/span&gt; &lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: normal;" value="4"&gt; &lt;p class="docText"&gt;The AWT event dispatch thread dispatches the event to any  &lt;tt&gt;KeyListener&lt;/tt&gt;s.&lt;/p&gt;&lt;/span&gt; &lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: normal;" value="5"&gt; &lt;p class="docText"&gt;The &lt;tt&gt;KeyListener&lt;/tt&gt; receives the key event and does  whatever it wants with it.&lt;a name="idd1e10002"&gt;&lt;/a&gt;&lt;a name="idd1e10007"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/span&gt; &lt;p class="docText"&gt;All listeners are interfaces, so any object can be a listener  by implementing a listener interface. Also note that there can be several  listeners for the same event type. For example, several objects could be  listening for mouse events. This can be a useful feature, but you won't need to  deal with multiple listeners for the same type of event in your code.&lt;/p&gt; &lt;p class="docText"&gt;There is a way to capture all AWT events. Although doing this  isn't useful for a real game, it can be helpful for debugging your code or  seeing what events get dispatched. The following code captures all the events by  creating an &lt;tt&gt;AWTEventListener&lt;/tt&gt; and prints the events to the console:&lt;a name="idd1e10019"&gt;&lt;/a&gt;&lt;/p&gt;&lt;pre&gt;Toolkit.getDefaultToolkit().addAWTEventListener(&lt;br /&gt;new AWTEventListener() {&lt;br /&gt;   public void eventDispatched(AWTEvent event) {&lt;br /&gt;       System.out.println(event);&lt;br /&gt;   }&lt;br /&gt;}, -1);&lt;br /&gt;&lt;/pre&gt; &lt;p class="docText"&gt;Remember, don't use something like this in a real game; use it  only for debugging.&lt;/p&gt;&lt;p class="docText"&gt;For a game, you want to use lots of keys, such as the arrow  keys for movement and maybe the Control key for firing a weapon. We really  aren't going to deal with things like text input—we can leave that for Swing  components discussed later in this chapter.&lt;a name="idd1e10037"&gt;&lt;/a&gt;&lt;a name="idd1e10042"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="docText"&gt;To capture key events, you need to do two things: create a  &lt;tt&gt;KeyListener&lt;/tt&gt; and register the listener to receive events. To register a  listener, just call the &lt;tt&gt;addKeyListener()&lt;/tt&gt; method on the component that  you want to receive key events on. For games here, that component is the  full-screen window:&lt;a name="idd1e10054"&gt;&lt;/a&gt;&lt;a name="idd1e10057"&gt;&lt;/a&gt;&lt;/p&gt;&lt;pre&gt;&lt;blockquote&gt;Window window = screen.getFullScreenWindow();&lt;br /&gt;window.addKeyListener(keyListener);&lt;/blockquote&gt;&lt;br /&gt;&lt;/pre&gt; &lt;p class="docText"&gt;To create a &lt;tt&gt;KeyListener&lt;/tt&gt;, you just need to create an  object that implements the &lt;tt&gt;KeyListener&lt;/tt&gt; interface. The  &lt;tt&gt;KeyListener&lt;/tt&gt; interface has three methods: &lt;tt&gt;keyPressed()&lt;/tt&gt;,  &lt;tt&gt;keyReleased()&lt;/tt&gt;, and &lt;tt&gt;keyTyped()&lt;/tt&gt;. The "typed" event occurs when a  key is first pressed and then repeatedly based on the key repeat rate. Receiving  events when a key is "typed" is pretty useless for a game, so we just focus on  the key presses and releases.&lt;a name="idd1e10088"&gt;&lt;/a&gt;&lt;a name="idd1e10091"&gt;&lt;/a&gt;&lt;a name="idd1e10096"&gt;&lt;/a&gt;&lt;a name="idd1e10099"&gt;&lt;/a&gt;&lt;a name="idd1e10104"&gt;&lt;/a&gt;&lt;a name="idd1e10107"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="docText"&gt;Each of these three methods takes a &lt;tt&gt;KeyEvent&lt;/tt&gt; as a  parameter. The &lt;tt&gt;KeyEvent&lt;/tt&gt; object enables you to inspect what key was  actually pressed or released, in the form of a &lt;span class="docEmphasis"&gt;virtual  key code&lt;/span&gt;. A virtual key code is the Java-defined code to a particular  keyboard key, but it is not the same as the character. For example, although  &lt;tt&gt;Q&lt;/tt&gt; and &lt;tt&gt;q&lt;/tt&gt; are different characters, they have the same key  code.&lt;a name="idd1e10130"&gt;&lt;/a&gt;&lt;a name="idd1e10135"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="docText"&gt;All the virtual key codes are defined in &lt;tt&gt;KeyEvent&lt;/tt&gt; in  the form &lt;tt&gt;VK_xxx&lt;/tt&gt;. For example, the Q key has the key code  &lt;tt&gt;KeyEvent.VK_Q&lt;/tt&gt;. Most of the time, you can guess the name of a key code  (such as &lt;tt&gt;VK_ENTER&lt;/tt&gt; or &lt;tt&gt;VK_1&lt;/tt&gt;), but be sure to look up the  &lt;tt&gt;KeyEvent&lt;/tt&gt; class in the Java API documentation for the full list of  virtual key codes.&lt;/p&gt;&lt;p class="docText"&gt;URL: &lt;span style="font-style: italic;"&gt;http://java.sun.com/j2se/1.4.2/docs/api/java/awt/event/KeyEvent.html&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p class="docText"&gt;Now let's try it out. The &lt;tt&gt;KeyTest&lt;/tt&gt; class is an implementation of the  &lt;tt&gt;KeyListener&lt;/tt&gt; interface. It simply displays key press and release events  to the screen. Press Escape to exit the program.&lt;/p&gt;&lt;p class="docText"&gt;&lt;/p&gt;&lt;h5 class="docExampleTitle"&gt;KeyTest.java&lt;/h5&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;import java.awt.event.KeyListener;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;import java.awt.event.KeyEvent;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;import java.util.LinkedList;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;import &lt;/span&gt;&lt;tt style="color: rgb(0, 0, 153);"&gt;mapua.game.class&lt;/tt&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;.graphics.*;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;import &lt;/span&gt;&lt;tt style="color: rgb(0, 0, 153);"&gt;mapua.game.class&lt;/tt&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;.test.GameCore;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;/**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    A simple keyboard test. Displays keys pressed and released to&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    the screen. Useful for debugging key input, too.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;*/&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;public class KeyTest extends GameCore implements KeyListener {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    public static void main(String[] args) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        new KeyTest().run();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    private LinkedList messages = new LinkedList();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    public void init() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        super.init();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        Window window = screen.getFullScreenWindow();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        // allow input of the TAB key and other keys normally&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        // used for focus traversal&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        window.setFocusTraversalKeysEnabled(false);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        // register this object as a key listener for the window&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        window.addKeyListener(this);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        addMessage("KeyInputTest. Press Escape to exit");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    // a method from the KeyListener interface&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    public void keyPressed(KeyEvent e) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        int keyCode = e.getKeyCode();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        // exit the program&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        if (keyCode == KeyEvent.VK_ESCAPE) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;             stop();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        else {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;            addMessage("Pressed: " +&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;                KeyEvent.getKeyText(keyCode));&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;            // make sure the key isn't processed for anything else&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;            e.consume();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    // a method from the KeyListener interface&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    public void keyReleased(KeyEvent e) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        int keyCode = e.getKeyCode();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        addMessage("Released: " + KeyEvent.getKeyText(keyCode));&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        // make sure the key isn't processed for anything else&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        e.consume();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    // a method from the KeyListener interface&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    public void keyTyped(KeyEvent e) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        // this is called after the key is released - ignore it&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        // make sure the key isn't processed for anything else&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        e.consume();&lt;/span&gt;&lt;a style="color: rgb(0, 0, 153);" name="idd1e10221"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 0, 153);" name="idd1e10228"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 0, 153);" name="idd1e10231"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 0, 153);" name="idd1e10236"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 0, 153);" name="idd1e10239"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 0, 153);" name="idd1e10244"&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        Add a message to the list of messages.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    public synchronized void addMessage(String message) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        messages.add(message);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        if (messages.size() &amp;gt;= screen.getHeight() / FONT_SIZE) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;            messages.remove(0);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        Draw the list of messages&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    public synchronized void draw(Graphics2D g) {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        Window window = screen.getFullScreenWindow();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        g.setRenderingHint(&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;            RenderingHints.KEY_TEXT_ANTIALIASING,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        // draw background&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        g.setColor(window.getBackground());&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        g.fillRect(0, 0, screen.getWidth(), screen.getHeight());&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        // draw messages&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        g.setColor(window.getForeground());&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        int y = FONT_SIZE;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        for (int i=0; i&amp;lt;messages.size(); i++) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;            g.drawString((String)messages.get(i), 5, y);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;            y+=FONT_SIZE;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;}&lt;/span&gt;&lt;a style="color: rgb(0, 0, 153);" name="idd1e10248"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 0, 153);" name="idd1e10255"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 0, 153);" name="idd1e10258"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 0, 153);" name="idd1e10263"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 0, 153);" name="idd1e10266"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 0, 153);" name="idd1e10271"&gt;&lt;/a&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p class="docText"&gt;You should note a couple things about this code. First, the  &lt;tt&gt;init()&lt;/tt&gt; method uses this line:&lt;a name="idd1e10281"&gt;&lt;/a&gt;&lt;a name="idd1e10284"&gt;&lt;/a&gt;&lt;/p&gt;&lt;pre&gt;&lt;blockquote&gt;window.setFocusTraversalKeysEnabled(false);&lt;/blockquote&gt;&lt;br /&gt;&lt;/pre&gt; &lt;p class="docText"&gt;This, of course, disables focus traversal keys. Focus traversal  keys are the keys pressed to change the keyboard focus from one component to  another. For example, on a web page, you've probably pressed Tab to move from  field to field in a form. Normally, the Tab key event is swallowed up by the  AWT's focus traversal code, but in this case we want to receive the Tab key  event. Calling this method allows us to do so.&lt;a name="idd1e10297"&gt;&lt;/a&gt;&lt;a name="idd1e10300"&gt;&lt;/a&gt;&lt;a name="idd1e10305"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="docText"&gt;If you're curious what the various focus traversal keys are,  call the &lt;tt&gt;getFocusTraversalKeys()&lt;/tt&gt; method.&lt;a name="idd1e10314"&gt;&lt;/a&gt;&lt;a name="idd1e10317"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="docText"&gt;The Tab key isn't the only key that can cause some strange  behavior. The Alt key can also cause a problem. On most systems, the Alt key is  used to activate a &lt;span class="docEmphasis"&gt;mnemonic&lt;/span&gt;. A mnemonic is a  shortcut or accelerator key for a particular user interface element. For  example, pressing Alt+F activates the File menu on most applications that have a  menu bar. The AWT thinks the next key pressed after Alt is a mnemonic and  ignores the key. To disable this, in &lt;tt&gt;KeyTest&lt;/tt&gt; you stop every  &lt;tt&gt;KeyEvent&lt;/tt&gt; in each &lt;tt&gt;KeyListener&lt;/tt&gt; from being processed in the  default manner by calling this:&lt;a name="idd1e10337"&gt;&lt;/a&gt;&lt;a name="idd1e10340"&gt;&lt;/a&gt;&lt;a name="idd1e10343"&gt;&lt;/a&gt;&lt;a name="idd1e10346"&gt;&lt;/a&gt;&lt;a name="idd1e10351"&gt;&lt;/a&gt;&lt;a name="idd1e10354"&gt;&lt;/a&gt;&lt;a name="idd1e10359"&gt;&lt;/a&gt;&lt;a name="idd1e10362"&gt;&lt;/a&gt;&lt;a name="idd1e10367"&gt;&lt;/a&gt;&lt;/p&gt;&lt;pre&gt;&lt;blockquote&gt;e.consume();&lt;/blockquote&gt;&lt;br /&gt;&lt;/pre&gt; &lt;p class="docText"&gt;This makes sure no other object processes the Alt key (or  whatever modifier key activates a mnemonic), so the Alt key is treated like a  normal key.&lt;a name="idd1e10378"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="docText"&gt;A side effect to &lt;tt&gt;KeyTest&lt;/tt&gt; is that it's a useful program  for testing how keys behave on different systems. "Gasp! You mean key input  isn't the same on all systems?" Unfortunately, no, it's not.&lt;/p&gt; &lt;p class="docText"&gt;Let's take key repetition for an example. When the user holds  down a key, the operating system sends multiple events for that key. In a text  editor, for example, when you hold down the Q key, several Qs appear. On some  systems (such as Linux), both the key press and the key release event are sent  for each key repeat. On other systems (such as Windows), only the key press  event is sent for each repetition, and the key release event isn't sent until  the user actually releases the key.&lt;/p&gt; &lt;p class="docText"&gt;Also, there could be other subtle differences, such as the  Windows Start key behaving differently depending on what version of Windows is  running. Or, the key behavior could be different depending on what Java VM is  running.&lt;/p&gt; &lt;p class="docText"&gt;Luckily, these differences aren't drastic; most of the time,  you won't have to deal with them.&lt;a name="idd1e10396"&gt;&lt;/a&gt;&lt;a name="idd1e10401"&gt;&lt;/a&gt;&lt;a name="idd1e10404"&gt;&lt;/a&gt;&lt;a name="idd1e10409"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="docText"&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-3002536955412362449?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/3002536955412362449/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/05/interactivity-and-user-interfaces.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/3002536955412362449'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/3002536955412362449'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/05/interactivity-and-user-interfaces.html' title='Game: Interactivity and User Interfaces'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_lYg70zdQa3I/Sh3akR11iUI/AAAAAAAAAE8/UAicJQuubCY/s72-c/game.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-3135198759374043738</id><published>2009-05-21T18:51:00.000-07:00</published><updated>2009-05-21T19:18:45.600-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SSL'/><category scheme='http://www.blogger.com/atom/ns#' term='IIS6'/><category scheme='http://www.blogger.com/atom/ns#' term='Website'/><title type='text'>Website: Configure SSL (HTTPS)</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/ShYK_uBut3I/AAAAAAAAADA/5hR_p07rhlw/s1600-h/IIS.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 320px; height: 197px;" src="http://1.bp.blogspot.com/_lYg70zdQa3I/ShYK_uBut3I/AAAAAAAAADA/5hR_p07rhlw/s320/IIS.JPG" alt="" id="BLOGGER_PHOTO_ID_5338466498097624946" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Because of the way that the SSL protocol works, it is normally necessary to have a unique IP address for each SSL certificate that you are using. This is because the host header information that tells the server which website to serve up and therefore which SSL certificate to use is encrypted and can't be unencrypted unless it knows which SSL certificate to use. It's like the "Chicken and Egg" problem.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If you have to use the same IP address for multiple sites, one simple solution is to just use different port numbers. For example:&lt;/p&gt; &lt;p&gt;https://site1.mysite.com&lt;br /&gt;https://site2.mysite.com:8081&lt;br /&gt;https://myothersite.com:8082&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;But doing it this way requires that you always visit the site using the port number and always reference it in links with the port number.&lt;/p&gt; &lt;p&gt;There is a more elegant method, if you have IIS 6.0 or later. That method is to use &lt;strong&gt;SSL Host Headers&lt;/strong&gt;.&lt;/p&gt; &lt;p&gt;With SSL Host Headers, you will essentially use one SSL certificate for all of the sites that use SSL on a particular IP address. For this to work then, you will need to have either a WildCard Certificate or a Unified Communications Certificated. If all of the websites are subdomains of one domain name (e.g. site1.mysite.com, site2.mysite.com), you can use a Wildcard certificate. If there are completely different domain names (e.g. mysite.com, myothersite.com), you will need to use a Unified Communications Certificate.&lt;/p&gt; &lt;p&gt;The first step, if you haven't already done it, is to set up each of the websites with normal http host header values. You can do this by clicking the Advanced button next to the IP address when editing each website's properties in IIS. Just click the Edit button and add a domain name as the host header value.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Next, you will need to create a pending request on one of the websites and order the Wildcard or UC certificate from the certificate authority of your choice. Once you have a Wildcard or UC certificate that will work for all of the hostnames that are on the same IP address, you need to use it to complete the pending request on the website that you created it on. Then you just need to configure the SecureBindings metabase property on each of the other sites so it contains the host header name of the site. To do so, follow these steps:&lt;/p&gt; &lt;ol&gt;&lt;li&gt;Click Start, click Run, type "&lt;code&gt;cmd&lt;/code&gt;" in the Open box, and then click OK.&lt;/li&gt;&lt;li&gt;Navigate to your IIS scripts directory by typing "&lt;code&gt;cd C:\Inetpub\AdminScripts&lt;/code&gt;". Adjust the path to where the adsutil.vbs file is, if necessary.&lt;/li&gt;&lt;li&gt;Type the following command at the command prompt:&lt;br /&gt;   &lt;br /&gt;    &lt;code&gt;     cscript.exe adsutil.vbs set /w3svc/&lt;site&gt;/SecureBindings ":443:&lt;host&gt;"&lt;/code&gt;&lt;br /&gt;   &lt;br /&gt;&lt;host&gt; is the host header value for the Web site (www.myothersite.com). &lt;site&gt; is the IIS site ID displayed when looking at all the websites in IIS.&lt;/li&gt;&lt;/ol&gt;Run that command for each of the websites that need to use that certificate. They will then use the same certificate that was install to the first site on the IP.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-3135198759374043738?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/3135198759374043738/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/05/website-configure-ssl-https.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/3135198759374043738'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/3135198759374043738'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/05/website-configure-ssl-https.html' title='Website: Configure SSL (HTTPS)'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_lYg70zdQa3I/ShYK_uBut3I/AAAAAAAAADA/5hR_p07rhlw/s72-c/IIS.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-4855911496755254759</id><published>2009-05-20T22:04:00.000-07:00</published><updated>2009-06-30T07:51:48.618-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Game'/><category scheme='http://www.blogger.com/atom/ns#' term='Sprites'/><category scheme='http://www.blogger.com/atom/ns#' term='Animation'/><category scheme='http://www.blogger.com/atom/ns#' term='2D graphics'/><category scheme='http://www.blogger.com/atom/ns#' term='JAVA'/><title type='text'>Game: Using Sprites</title><content type='html'>&lt;p class="docText"&gt;The animation is now running smoothly, but it's not that  exciting to see something animate in one place on the screen. Let's make it move  by creating a sprite.&lt;a name="idd1e8739"&gt;&lt;/a&gt;&lt;a name="idd1e8744"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="docText"&gt;A &lt;span class="docEmphasis"&gt;sprite&lt;/span&gt; is a graphic that moves  independently around the screen. In this case, the sprite is also animated, so  it can animate and move at the same time.&lt;/p&gt; &lt;p class="docText"&gt;Besides an animation, the sprites will be composed of two  things: a position and a velocity. If you were sleeping the day they told you  about velocity in school, a velocity is both a speed (such as 55mph) and a  direction (such as north). In this case, we'll break down velocity into  horizontal and vertical components. Instead of miles per hour or meters per  second, we'll use pixels per millisecond.&lt;a name="idd1e8756"&gt;&lt;/a&gt;&lt;a name="idd1e8759"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="docText"&gt;You might be asking, "Why use velocity? Why not just update the  sprite's position a certain amount each frame?" Well, if you did that, the  sprite would move at different speeds depending on the speed of the machine. A  faster frame rate would mean a faster-moving sprite. Tying the sprite's movement  to real time causes the sprite to move at a consistent pace, whether the time  between frames is short or long.&lt;/p&gt; &lt;p class="docText"&gt;As with the animation, the sprite updates based on the number  of milliseconds that have passed since the last time the sprite was drawn.  You'll say, "Hey, sprite, 50 milliseconds have passed," and the sprite will  update its position (based on its velocity) and its animation.&lt;/p&gt; &lt;p class="docText"&gt;The &lt;tt&gt;Sprite&lt;/tt&gt; class, has an animation, a position, and a  velocity.&lt;a name="idd1e8778"&gt;&lt;/a&gt;&lt;a name="idd1e8783"&gt;&lt;/a&gt;&lt;a name="idd1e8786"&gt;&lt;/a&gt;&lt;a name="idd1e8789"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="docText"&gt;You could make the sprite's position an integer, but what if a  sprite is moving slowly? For example, imagine a sprite moving a tenth of a pixel  every time the &lt;tt&gt;update()&lt;/tt&gt; method is called. That means the sprite would  have nonvisible movement on 9 out of 10 calls to &lt;tt&gt;update()&lt;/tt&gt;. If the  sprite's position were an integer, the sprite would never move because the  result would be rounded each time.&lt;a name="idd1e8803"&gt;&lt;/a&gt;&lt;a name="idd1e8808"&gt;&lt;/a&gt;&lt;a name="idd1e8811"&gt;&lt;/a&gt;&lt;a name="idd1e8814"&gt;&lt;/a&gt;&lt;a name="idd1e8819"&gt;&lt;/a&gt;&lt;a name="idd1e8824"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="docText"&gt;If the sprite's position is a floating-point value, the sprite  position could increment these nonvisible movements, and the sprite would move 1  pixel on every tenth call to &lt;tt&gt;update()&lt;/tt&gt;, as expected. For this reason,  you'll make the sprites' position a floating-point value. To get its exact pixel  position, use &lt;tt&gt;Math.round()&lt;/tt&gt;.&lt;/p&gt;&lt;h5 class="docExampleTitle"&gt;&lt;a name="ch02list09"&gt;&lt;/a&gt;Listing  Sprite.java&lt;br /&gt;&lt;/h5&gt;&lt;pre&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;import java.awt.Image;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;public class Sprite {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   private Animation anim;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   // position (pixels)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   private float x;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   private float y;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   // velocity (pixels per millisecond)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   private float dx;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   private float dy;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       Creates a new Sprite object with the specified Animation.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   public Sprite(Animation anim) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       this.anim = anim;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       Updates this Sprite's Animation and its position based&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       on the velocity.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   public void update(long elapsedTime) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       x += dx * elapsedTime;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       y += dy * elapsedTime;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       anim.update(elapsedTime);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       Gets this Sprite's current x position.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   public float getX() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       return x;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       Gets this Sprite's current y position.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   public float getY() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       return y;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       Sets this Sprite's current x position.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   public void setX(float x) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       this.x = x;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       Sets this Sprite's current y position.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   public void setY(float y) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       this.y = y;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       Gets this Sprite's width, based on the size of the&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       current image.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   public int getWidth() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       return anim.getImage().getWidth(null);&lt;/span&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e8899"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e8904"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e8907"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e8910"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e8915"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e8920"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e8927"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e8934"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e8937"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e8940"&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       Gets this Sprite's height, based on the size of the&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       current image.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   public int getHeight() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       return anim.getImage().getHeight(null);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       Gets the horizontal velocity of this Sprite in pixels&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       per millisecond.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   public float getVelocityX() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       return dx;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       Gets the vertical velocity of this Sprite in pixels&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       per millisecond.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   public float getVelocityY() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       return dy;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       Sets the horizontal velocity of this Sprite in pixels&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       per millisecond.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   public void setVelocityX(float dx) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       this.dx = dx;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       Sets the vertical velocity of this Sprite in pixels&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       per millisecond.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   public void setVelocityY(float dy) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       this.dy = dy;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       Gets this Sprite's current image.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   public Image getImage() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       return anim.getImage();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;   }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;}&lt;/span&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e8944"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e8949"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e8952"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e8955"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e8960"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e8965"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e8972"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e8979"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e8982"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e8985"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p class="docText"&gt;The &lt;tt&gt;Sprite&lt;/tt&gt; class is fairly simple. Mostly it's a just  bunch of &lt;tt&gt;get&lt;/tt&gt; and &lt;tt&gt;set&lt;/tt&gt; methods. All the work is done in the  &lt;tt&gt;update()&lt;/tt&gt; method, which updates the sprite's position based on its  velocity and the amount of time elapsed.&lt;/p&gt; &lt;p class="docText"&gt;Now let's have some fun. Let's use the &lt;tt&gt;Sprite&lt;/tt&gt; class to  make the character animate and bounce around the screen. &lt;tt&gt;SpriteTest1&lt;/tt&gt;, does just that. Every  time the sprite hits the edge of the screen, its velocity is changed to reflect  the bounce.&lt;/p&gt;&lt;pre&gt;&lt;br /&gt;&lt;/pre&gt;&lt;h5 class="docExampleTitle"&gt;&lt;a name="ch02list10"&gt;&lt;/a&gt;Listing SpriteTest1.java&lt;/h5&gt;&lt;pre&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;import java.awt.*;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;import javax.swing.ImageIcon;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;public class SpriteTest1 {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    public static void main(String args[]) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        SpriteTest1 test = new SpriteTest1();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        test.run();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    private static final DisplayMode POSSIBLE_MODES[] = {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        new DisplayMode(800, 600, 32, 0),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        new DisplayMode(800, 600, 24, 0),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        new DisplayMode(800, 600, 16, 0),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        new DisplayMode(640, 480, 32, 0),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        new DisplayMode(640, 480, 24, 0),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        new DisplayMode(640, 480, 16, 0)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    };&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    private static final long DEMO_TIME = 10000;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    private ScreenManager screen;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    private Image bgImage;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    private Sprite sprite;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    public void loadImages() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        // load images&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        bgImage = loadImage("images/background.jpg");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        Image player1 = loadImage("images/player1.png");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        Image player2 = loadImage("images/player2.png");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        Image player3 = loadImage("images/player3.png");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        // create sprite&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        Animation anim = new Animation();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        anim.addFrame(player1, 250);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        anim.addFrame(player2, 150);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        anim.addFrame(player1, 150);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        anim.addFrame(player2, 150);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        anim.addFrame(player3, 200);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        anim.addFrame(player2, 150);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        sprite = new Sprite(anim);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        // start the sprite off moving down and to the right&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        sprite.setVelocityX(0.2f);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        sprite.setVelocityY(0.2f);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    private Image loadImage(String fileName) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        return new ImageIcon(fileName).getImage();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    public void run() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        screen = new ScreenManager();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        try {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            DisplayMode displayMode =&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;                screen.findFirstCompatibleMode(POSSIBLE_MODES);&lt;/span&gt;&lt;a style="color: rgb(0, 153, 0);" name="idd1e9064"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0);" name="idd1e9069"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0);" name="idd1e9074"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0);" name="idd1e9077"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0);" name="idd1e9082"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0);" name="idd1e9089"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0);" name="idd1e9092"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0);" name="idd1e9097"&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            screen.setFullScreen(displayMode);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            loadImages();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            animationLoop();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        finally {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            screen.restoreScreen();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    public void animationLoop() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        long startTime = System.currentTimeMillis();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        long currTime = startTime;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        while (currTime - startTime &amp;lt; DEMO_TIME) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            long elapsedTime =&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;                System.currentTimeMillis() - currTime;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            currTime += elapsedTime;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            // update the sprites&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            update(elapsedTime);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            // draw and update the screen&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            Graphics2D g = screen.getGraphics();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            draw(g);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            g.dispose();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            screen.update();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            // take a nap&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            try {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;                Thread.sleep(20);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            catch (InterruptedException ex) { }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    public void update(long elapsedTime) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        // check sprite bounds&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        if (sprite.getX() &amp;lt; 0) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            sprite.setVelocityX(Math.abs(sprite.getVelocityX()));&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        else if (sprite.getX() + sprite.getWidth() &amp;gt;=&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            screen.getWidth())&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            sprite.setVelocityX(-Math.abs(sprite.getVelocityX()));&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        if (sprite.getY() &amp;lt; 0) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            sprite.setVelocityY(Math.abs(sprite.getVelocityY()));&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        else if (sprite.getY() + sprite.getHeight() &amp;gt;=&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            screen.getHeight())&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            sprite.setVelocityY(-Math.abs(sprite.getVelocityY()));&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        // update sprite&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        sprite.update(elapsedTime);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    public void draw(Graphics g) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        // draw background&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        g.drawImage(bgImage, 0, 0, null);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        // draw sprite&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;        g.drawImage(sprite.getImage(),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            Math.round(sprite.getX()),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            Math.round(sprite.getY()),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;            null);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;}&lt;/span&gt;&lt;a style="color: rgb(0, 153, 0);" name="idd1e9105"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0);" name="idd1e9110"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0);" name="idd1e9115"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0);" name="idd1e9118"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0);" name="idd1e9123"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0);" name="idd1e9130"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0);" name="idd1e9133"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0);" name="idd1e9138"&gt;&lt;/a&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p class="docText"&gt;Because the &lt;tt&gt;Sprite&lt;/tt&gt; object handles its own movement,  there's not much new happening in the &lt;tt&gt;SpriteTest1&lt;/tt&gt; class. The newest  thing is the &lt;tt&gt;update()&lt;/tt&gt; method, which causes the sprite to "bounce" when  it hits the edge of the screen. If the sprite hits the left or right edge of the  screen, the horizontal velocity is reversed. If the sprite hits the top or  bottom edge of the screen, the vertical velocity is reversed.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-4855911496755254759?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/4855911496755254759/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/05/game-using-sprites.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/4855911496755254759'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/4855911496755254759'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/05/game-using-sprites.html' title='Game: Using Sprites'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-4327421197075958643</id><published>2009-05-20T21:22:00.000-07:00</published><updated>2009-06-30T07:52:23.395-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='BLUEJ'/><category scheme='http://www.blogger.com/atom/ns#' term='Buffering'/><category scheme='http://www.blogger.com/atom/ns#' term='Animation'/><category scheme='http://www.blogger.com/atom/ns#' term='Flicker'/><category scheme='http://www.blogger.com/atom/ns#' term='2D graphics'/><category scheme='http://www.blogger.com/atom/ns#' term='JAVA'/><title type='text'>Game: Getting Rid of Flicker and Tearing</title><content type='html'>&lt;span style="font-family:times new roman;"&gt;When you run AnimationTest1, you probably notice a big problem: The  animated character flickers. And it's annoying. Why does this happen, and how  can you get rid of it?&lt;/span&gt;&lt;br /&gt;&lt;p class="docText" style="font-family: times new roman;"&gt;This is happening because you're constantly drawing directly to  the screen. That  means you erase the character with the background and then redraw the character,  so there are sometimes brief moments that you see the background where the  character should be. Because it's happening so fast, it appears as flicker.&lt;/p&gt;&lt;span style="font-weight: bold;font-family:times new roman;" &gt;How can you get rid of the flicker? The answer is to use &lt;span style="font-style: italic;"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;double buffering&lt;/span&gt;.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;p class="docText" style="font-family: times new roman;"&gt;The back buffer can be just a normal Java image. You can use  Component's&lt;/p&gt;&lt;p  class="docText" style="font-family:times new roman;"&gt; &lt;/p&gt;&lt;blockquote&gt;createImage(int w, int h) &lt;/blockquote&gt;&lt;p&gt;&lt;/p&gt;&lt;p face="times new roman" class="docText"&gt;method to create a back  buffer. For example, if you want to double buffer an applet that isn't using  active rendering, you could override the update() method to use a  double buffer and call the paint() method with the double buffer's  graphics context:&lt;a name="idd1e7869"&gt;&lt;/a&gt;&lt;a name="idd1e7872"&gt;&lt;/a&gt;&lt;a name="idd1e7877"&gt;&lt;/a&gt;&lt;a name="idd1e7880"&gt;&lt;/a&gt;&lt;a name="idd1e7885"&gt;&lt;/a&gt;&lt;a name="idd1e7888"&gt;&lt;/a&gt;&lt;a name="idd1e7893"&gt;&lt;/a&gt;&lt;a name="idd1e7896"&gt;&lt;/a&gt;&lt;a name="idd1e7901"&gt;&lt;/a&gt;&lt;a name="idd1e7906"&gt;&lt;/a&gt;&lt;a name="idd1e7909"&gt;&lt;/a&gt;&lt;/p&gt;&lt;pre  style="font-family:times new roman;"&gt;&lt;blockquote&gt;private Image doubleBuffer;&lt;br /&gt;...&lt;br /&gt;public void update(Graphics g) {&lt;br /&gt;Dimension size = getSize();&lt;br /&gt;if (doubleBuffer == null ||&lt;br /&gt;doubleBuffer.getWidth(this) != size.width ||&lt;br /&gt;doubleBuffer.getHeight(this) != size.height)&lt;br /&gt;{&lt;br /&gt;doubleBuffer = createImage(size.width, size.height);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;if (doubleBuffer != null) {&lt;br /&gt;// paint to double buffer&lt;br /&gt;Graphics g2 = doubleBuffer.getGraphics();&lt;br /&gt;paint(g2);&lt;br /&gt;g2.dispose();&lt;br /&gt;&lt;br /&gt;// copy double buffer to screen&lt;br /&gt;g.drawImage(doubleBuffer, 0, 0, null);&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;// couldn't create double buffer, just paint to screen&lt;br /&gt;paint(g);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void paint(Graphics g) {&lt;br /&gt;// do drawing here&lt;br /&gt;...&lt;br /&gt;}&lt;a name="idd1e7919"&gt;&lt;/a&gt;&lt;a name="idd1e7924"&gt;&lt;/a&gt;&lt;a name="idd1e7927"&gt;&lt;/a&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0); font-weight: bold;"&gt;Page Flipping&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p face="times new roman" class="docText"&gt;One drawback to using double buffering is the amount of time it  takes to copy the back buffer to the screen. A display resolution of 800x600 at  a bit depth of 16 takes 800x600x2 bytes, or 938KB. That's nearly a megabyte of  memory that has to get shuffled around at 30 frames per second. Although copying  that amount of memory is fast enough for many games, what if you didn't have to  copy a buffer at all and could instantly make the back buffer the display  buffer?&lt;a name="idd1e7940"&gt;&lt;/a&gt;&lt;a name="idd1e7943"&gt;&lt;/a&gt;&lt;a name="idd1e7948"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p face="times new roman" class="docText"&gt;&lt;span class="docEmphRoman"&gt;You can&lt;/span&gt;: This technique is  called &lt;span class="docEmphasis"&gt;page flipping&lt;/span&gt;. With page flipping, you use  two buffers, one as a back buffer and the other as a display buffer.&lt;/p&gt;&lt;p style="font-family: times new roman;" class="docText"&gt;The display pointer points to buffer being displayed. This  display pointer can be changed on most modern systems. When you are finished  drawing to the back buffer, the display pointer can be switched from the current  display buffer to the back buffer. When the display pointer is changed, the  display buffer instantly becomes the back buffer, and vice versa.&lt;/p&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style="font-weight: bold;"&gt;Monitor Refresh and Tearing&lt;/span&gt;&lt;br /&gt;Remember that your monitor has a refresh rate. This refresh rate is usually&lt;br /&gt;around 75Hz or so, which means the monitor is refreshed 75 times a second. But&lt;br /&gt;what happens when page flipping occurs or a buffer is copied in the middle of a&lt;br /&gt;monitor refresh? Yes, you guessed it: Part of the old buffer can display at the&lt;br /&gt;same time as part of the new buffer. This effect, similar to flickering, is&lt;br /&gt;called tearing. It happens so fast it might barely be&lt;br /&gt;noticeable, but when it is noticeable, it appears as tears somewhere in the&lt;br /&gt;screen. To get around this, it's possible to perform the page flip at just the right&lt;br /&gt;moment, right before the monitor is about to be refreshed. This might sound like&lt;br /&gt;a complicated task, but don't worry—the Java runtime does it all for you, using&lt;br /&gt;the BufferStrategy class.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The &lt;/span&gt;&lt;span style="font-weight: bold;" class="docEmphasis"&gt;BufferStrategy&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; Class&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p style="font-family: times new roman;" class="docText"&gt;Double buffering, page flipping, and waiting for the monitor  refresh all are handled by the BufferStrategy class.  BufferStrategy chooses the best buffering method based on the  capabilities of the system. First, it tries page flipping. If that's not  possible, it tries double buffering. Also, it waits on the monitor refresh to  finish before performing any page flip. In short, it does all the work for you,  without you having to think about it.&lt;br /&gt;&lt;/p&gt;&lt;p style="font-family: times new roman;" class="docText"&gt;One drawback to waiting for the monitor refresh is that the  game is limited in the number of frames per second it can display. If the  monitor is set at a 75Hz refresh rate, the game displays a maximum of 75 frames  per second. This means you can't use the game's frame rate as a "benchmark" for  how fast a system runs.&lt;/p&gt; &lt;p style="font-family: times new roman;" class="docText"&gt;Of course, it really doesn't matter whether your game runs at  200 frames per second—you'll still see only what your monitor is capable of. No  matter how fast your game runs, you'll still see 75 frames per second on a  monitor with a 75Hz refresh rate.&lt;/p&gt; &lt;p style="font-family: times new roman;" class="docText"&gt;Both the Canvas and Window objects can have a  BufferStrategy. Use the createBufferStrategy() method to  create a BufferStrategy based on the number of buffers you want. You'll  want at least two buffers for double buffering and page flipping to work. For  example:&lt;/p&gt;&lt;blockquote style="font-family: times new roman;"&gt;&lt;p class="docText"&gt;&lt;a name="idd1e8223"&gt;&lt;/a&gt;&lt;a name="idd1e8228"&gt;&lt;/a&gt;&lt;a name="idd1e8235"&gt;&lt;/a&gt;&lt;a name="idd1e8240"&gt;&lt;/a&gt;&lt;/p&gt;frame.createBufferStrategy(2); &lt;/blockquote&gt; &lt;p style="font-family: times new roman;" class="docText"&gt;After you've created the BufferStrategy, get a  reference to it by calling the getBufferStrategy() method and use the  getDrawGraphics() method to get the graphics context for the draw  buffer. After you finish drawing, call the show() method to show the  draw buffer, either by using a page flip or by copying the draw buffer to the  display buffer. Here's an example:&lt;/p&gt;&lt;blockquote style="font-family: times new roman;"&gt;&lt;p class="docText"&gt;&lt;a name="idd1e8267"&gt;&lt;/a&gt;&lt;a name="idd1e8270"&gt;&lt;/a&gt;&lt;a name="idd1e8275"&gt;&lt;/a&gt;&lt;a name="idd1e8278"&gt;&lt;/a&gt;&lt;a name="idd1e8283"&gt;&lt;/a&gt;&lt;a name="idd1e8286"&gt;&lt;/a&gt;&lt;a name="idd1e8291"&gt;&lt;/a&gt;&lt;a name="idd1e8294"&gt;&lt;/a&gt;&lt;a name="idd1e8299"&gt;&lt;/a&gt;&lt;/p&gt;BufferStrategy strategy = frame.getBufferStrategy();&lt;br /&gt;Graphics g = strategy.getDrawGraphics();&lt;br /&gt;draw(g);&lt;br /&gt;g.dispose();&lt;br /&gt;strategy.show(); &lt;/blockquote&gt;&lt;h4 style="font-family: times new roman;" class="docSection2Title"&gt;Creating a Screen Manager&lt;/h4&gt; &lt;p style="font-family: times new roman;" class="docText"&gt;Now let's update the SimpleScreenManager with these  new features. Here are some of the things you'll add:&lt;a name="idd1e8321"&gt;&lt;/a&gt;&lt;/p&gt; &lt;ul style="font-family: times new roman;"&gt;&lt;li&gt; &lt;p class="docList"&gt;Double buffering and page flipping by creating a  BufferStrategy&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p class="docList"&gt;getGraphics(), which gets the graphics context for the  display&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p class="docList"&gt;update(), which updates the display&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p class="docList"&gt;getCompatibleDisplayModes(), which gets a list of the  compatible display modes&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p class="docList"&gt;getCurrentDisplayMode(), which gets the current  display mode&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p class="docList"&gt;findFirstCompatibleMode(), which gets the first  compatible mode from a list of modes&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p style="font-family: times new roman;" class="docText"&gt;Also, now that you're doing active rendering, there's no need  for the JFrame used as the full-screen window to receive paint  events from the operating system, so you can turn them off:&lt;/p&gt;&lt;blockquote style="font-family: times new roman;"&gt;frame.ignoreRepaint(true); &lt;/blockquote&gt; &lt;p style="font-family: times new roman;" class="docText"&gt;This doesn't turn off normal repaint events, however.  Calling repaint() on the JFrame stills send a paint  event.&lt;/p&gt; &lt;p style="font-family: times new roman;" class="docText"&gt;The SimpleScreenManager is updated in the  ScreenManager class, shown here&lt;/p&gt;&lt;pre face="times new roman"&gt;&lt;span style="font-weight: bold;"&gt;Listing ScreenManager.java&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.awt.image.BufferStrategy;&lt;br /&gt;&lt;br /&gt;import java.awt.image.BufferedImage;&lt;br /&gt;&lt;br /&gt;import javax.swing.JFrame;&lt;/p&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;/**&lt;br /&gt;&lt;br /&gt;The ScreenManager class manages initializing and displaying&lt;br /&gt;&lt;br /&gt;full screen graphics modes.&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;public class ScreenManager {&lt;/p&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;    private GraphicsDevice device;&lt;/p&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;    /**&lt;br /&gt;&lt;br /&gt; Creates a new ScreenManager object.&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;public ScreenManager() {&lt;br /&gt;&lt;br /&gt; GraphicsEnvironment environment =&lt;br /&gt;&lt;br /&gt;     GraphicsEnvironment.getLocalGraphicsEnvironment();&lt;br /&gt;&lt;br /&gt; device = environment.getDefaultScreenDevice();&lt;br /&gt;&lt;br /&gt;}&lt;/p&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;&lt;br /&gt; Returns a list of compatible display modes for the&lt;br /&gt;&lt;br /&gt; default device on the system.&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;public DisplayMode[] getCompatibleDisplayModes() {&lt;br /&gt;&lt;br /&gt; return device.getDisplayModes();&lt;br /&gt;&lt;br /&gt;}&lt;/p&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;&lt;br /&gt; Returns the first compatible mode in a list of modes.&lt;br /&gt;&lt;br /&gt; Returns null if no modes are compatible.&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;public DisplayMode findFirstCompatibleMode(&lt;br /&gt;&lt;br /&gt; DisplayMode modes[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt; DisplayMode goodModes[] = device.getDisplayModes();&lt;br /&gt;&lt;br /&gt; for (int i = 0; i &amp;lt; modes.length; i++) {&lt;br /&gt;&lt;br /&gt;     for (int j = 0; j &amp;lt; goodModes.length; j++) {&lt;br /&gt;&lt;br /&gt;         if (displayModesMatch(modes[i], goodModes[j])) {&lt;br /&gt;&lt;br /&gt;             return modes[i];&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;     }&lt;/p&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;        }&lt;/p&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;        return null;&lt;br /&gt;&lt;br /&gt;}&lt;/p&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;&lt;br /&gt; Returns the current display mode.&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;public DisplayMode getCurrentDisplayMode() {&lt;br /&gt;&lt;br /&gt; return device.getDisplayMode();&lt;br /&gt;&lt;br /&gt;}&lt;/p&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;&lt;br /&gt; Determines if two display modes "match". Two display&lt;br /&gt;&lt;br /&gt; modes match if they have the same resolution, bit depth,&lt;br /&gt;&lt;br /&gt; and refresh rate. The bit depth is ignored if one of the&lt;br /&gt;&lt;br /&gt; modes has a bit depth of DisplayMode.BIT_DEPTH_MULTI.&lt;br /&gt;&lt;br /&gt; Likewise, the refresh rate is ignored if one of the&lt;br /&gt;&lt;br /&gt; modes has a refresh rate of&lt;br /&gt;&lt;br /&gt; DisplayMode.REFRESH_RATE_UNKNOWN.&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;public boolean displayModesMatch(DisplayMode mode1,&lt;br /&gt;&lt;br /&gt; DisplayMode mode2)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt; if (mode1.getWidth() != mode2.getWidth() ||&lt;br /&gt;&lt;br /&gt;     mode1.getHeight() != mode2.getHeight())&lt;br /&gt;&lt;br /&gt; {&lt;br /&gt;&lt;br /&gt;     return false;&lt;br /&gt;&lt;br /&gt; }&lt;/p&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;        if (mode1.getBitDepth() != DisplayMode.BIT_DEPTH_MULTI &amp;amp;&amp;amp;&lt;br /&gt;&lt;br /&gt;     mode2.getBitDepth() != DisplayMode.BIT_DEPTH_MULTI &amp;amp;&amp;amp;&lt;br /&gt;&lt;br /&gt;     mode1.getBitDepth() != mode2.getBitDepth())&lt;br /&gt;&lt;br /&gt; {&lt;br /&gt;&lt;br /&gt;     return false;&lt;br /&gt;&lt;br /&gt; }&lt;/p&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;        if (mode1.getRefreshRate() !=&lt;br /&gt;&lt;br /&gt;     DisplayMode.REFRESH_RATE_UNKNOWN &amp;amp;&amp;amp;&lt;br /&gt;&lt;br /&gt;     mode2.getRefreshRate() !=&lt;br /&gt;&lt;br /&gt;     DisplayMode.REFRESH_RATE_UNKNOWN &amp;amp;&amp;amp;&lt;br /&gt;&lt;br /&gt;     mode1.getRefreshRate() != mode2.getRefreshRate())&lt;br /&gt;&lt;br /&gt;  {&lt;br /&gt;&lt;br /&gt;      return false;&lt;br /&gt;&lt;br /&gt;  }&lt;/p&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;         return true;&lt;br /&gt;&lt;br /&gt;}&lt;/p&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;&lt;br /&gt; Enters full screen mode and changes the display mode.&lt;br /&gt;&lt;br /&gt; If the specified display mode is null or not compatible&lt;br /&gt;&lt;br /&gt; with this device, or if the display mode cannot be&lt;br /&gt;&lt;br /&gt; changed on this system, the current display mode is used.&lt;br /&gt;&lt;br /&gt; &amp;lt;p&amp;gt;&lt;br /&gt;&lt;br /&gt; The display uses a BufferStrategy with 2 buffers.&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;public void setFullScreen(DisplayMode displayMode) {&lt;br /&gt;&lt;br /&gt; JFrame frame = new JFrame();&lt;br /&gt;&lt;br /&gt; frame.setUndecorated(true);&lt;br /&gt;&lt;br /&gt; frame.setIgnoreRepaint(true);&lt;br /&gt;&lt;br /&gt; frame.setResizable(false);&lt;/p&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;        device.setFullScreenWindow(frame);&lt;br /&gt;&lt;br /&gt; if (displayMode != null &amp;amp;&amp;amp;&lt;br /&gt;&lt;br /&gt;     device.isDisplayChangeSupported())&lt;br /&gt;&lt;br /&gt; {&lt;br /&gt;&lt;br /&gt;     try {&lt;br /&gt;&lt;br /&gt;         device.setDisplayMode(displayMode);&lt;br /&gt;&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     catch (IllegalArgumentException ex) { }&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; frame.createBufferStrategy(2);&lt;br /&gt;&lt;br /&gt;}&lt;/p&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;&lt;br /&gt; Gets the graphics context for the display. The&lt;br /&gt;&lt;br /&gt; ScreenManager uses double buffering, so applications must&lt;br /&gt;&lt;br /&gt; call update() to show any graphics drawn.&lt;br /&gt;&lt;br /&gt; &amp;lt;p&amp;gt;&lt;br /&gt;&lt;br /&gt; The application must dispose of the graphics object.&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;public Graphics2D getGraphics() {&lt;br /&gt;&lt;br /&gt; Window window = device.getFullScreenWindow();&lt;br /&gt;&lt;br /&gt; if (window != null) {&lt;br /&gt;&lt;br /&gt;     BufferStrategy strategy = window.getBufferStrategy();&lt;br /&gt;&lt;br /&gt;     return (Graphics2D)strategy.getDrawGraphics();&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; else {&lt;br /&gt;&lt;br /&gt;     return null;&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;/p&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;&lt;br /&gt; Updates the display.&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;public void update() {&lt;br /&gt;&lt;br /&gt; Window window = device.getFullScreenWindow();&lt;br /&gt;&lt;br /&gt; if (window != null) {&lt;br /&gt;&lt;br /&gt;     BufferStrategy strategy = window.getBufferStrategy();&lt;br /&gt;&lt;br /&gt;     if (!strategy.contentsLost()) {&lt;br /&gt;&lt;br /&gt;         strategy.show();&lt;br /&gt;&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; // Sync the display on some systems.&lt;br /&gt;&lt;br /&gt; // (on Linux, this fixes event queue problems)&lt;br /&gt;&lt;br /&gt; Toolkit.getDefaultToolkit().sync();&lt;br /&gt;&lt;br /&gt;}&lt;/p&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;&lt;br /&gt; Returns the window currently used in full screen mode.&lt;br /&gt;&lt;br /&gt; Returns null if the device is not in full screen mode.&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;public Window getFullScreenWindow() {&lt;br /&gt;&lt;br /&gt; return device.getFullScreenWindow();&lt;br /&gt;&lt;br /&gt;}&lt;/p&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;&lt;br /&gt; Returns the width of the window currently used in full&lt;br /&gt;&lt;br /&gt; screen mode. Returns 0 if the device is not in full&lt;br /&gt;&lt;br /&gt; screen mode.&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;public int getWidth() {&lt;br /&gt;&lt;br /&gt; Window window = device.getFullScreenWindow();&lt;br /&gt;&lt;br /&gt; if (window != null) {&lt;br /&gt;&lt;br /&gt;     return window.getWidth();&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; else {&lt;br /&gt;&lt;br /&gt;     return 0;&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;/p&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;&lt;br /&gt; Returns the height of the window currently used in full&lt;br /&gt;&lt;br /&gt; screen mode. Returns 0 if the device is not in full&lt;br /&gt;&lt;br /&gt; screen mode.&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;public int getHeight() {&lt;br /&gt;&lt;br /&gt; Window window = device.getFullScreenWindow();&lt;br /&gt;&lt;br /&gt; if (window != null) {&lt;br /&gt;&lt;br /&gt;     return window.getHeight();&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; else {&lt;br /&gt;&lt;br /&gt;     return 0;&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;/p&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;&lt;br /&gt; Restores the screen's display mode.&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;public void restoreScreen() {&lt;br /&gt;&lt;br /&gt; Window window = device.getFullScreenWindow();&lt;br /&gt;&lt;br /&gt; if (window != null) {&lt;br /&gt;&lt;br /&gt;     window.dispose();&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; device.setFullScreenWindow(null);&lt;br /&gt;&lt;br /&gt;}&lt;/p&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 0, 0); font-family: courier new;"&gt;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;&lt;br /&gt; Creates an image compatible with the current display.&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;public BufferedImage createCompatibleImage(int w, int h,&lt;br /&gt;&lt;br /&gt; int transparency)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt; Window window = device.getFullScreenWindow();&lt;br /&gt;&lt;br /&gt; if (window != null) {&lt;br /&gt;&lt;br /&gt;     GraphicsConfiguration gc =&lt;br /&gt;&lt;br /&gt;         window.getGraphicsConfiguration();&lt;br /&gt;&lt;br /&gt;     return gc.createCompatibleImage(w, h, transparency);&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; return null;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p class="docText"&gt;In &lt;tt&gt;ScreenManager&lt;/tt&gt;, you'll notice the following line in  the &lt;tt&gt;update()&lt;/tt&gt; method:&lt;a name="idd1e8506"&gt;&lt;/a&gt;&lt;a name="idd1e8509"&gt;&lt;/a&gt;&lt;/p&gt;&lt;pre&gt;&lt;blockquote&gt;Toolkit.getDefaultToolkit().sync();&lt;/blockquote&gt;&lt;br /&gt;&lt;/pre&gt; &lt;p class="docText"&gt;This method makes sure the display is synchronized with the  window system. On many systems, this method does nothing, but on Linux, calling  this method fixes problems with the AWT event queue. Without calling this  method, some Linux systems might experience delayed mouse and keyboard input  events.&lt;/p&gt; &lt;p class="docText"&gt;Two new &lt;tt&gt;ScreenManager&lt;/tt&gt; methods to note are  &lt;tt&gt;displayModesMatch()&lt;/tt&gt; and&lt;span style="font-family:monospace;"&gt; &lt;/span&gt;&lt;tt&gt;createCompatibleImage()&lt;/tt&gt;.&lt;a name="idd1e8534"&gt;&lt;/a&gt;&lt;a name="idd1e8537"&gt;&lt;/a&gt;&lt;a name="idd1e8542"&gt;&lt;/a&gt;&lt;a name="idd1e8545"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="docText"&gt;The &lt;tt&gt;displayModesMatch()&lt;/tt&gt; method checks whether two  &lt;tt&gt;DisplayMode&lt;/tt&gt; objects "match." They match if the resolution, bit depth,  and refresh rate are equal. The bit depth and the refresh rate are ignored if  they aren't specified in one of the &lt;tt&gt;DisplayMode&lt;/tt&gt; objects.&lt;a name="idd1e8562"&gt;&lt;/a&gt;&lt;a name="idd1e8565"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="docText"&gt;&lt;tt&gt;createCompatibleImage()&lt;/tt&gt; creates an image that is  compatible with the display—that is, the image would have the same bit depth and  color model as the display. The image class created is a &lt;tt&gt;BufferedImage&lt;/tt&gt;,  which is a nonaccelerated image stored in system memory. This method is useful  for creating transparent or translucent images because the normal  &lt;tt&gt;createImage()&lt;/tt&gt; method creates only opaque images.&lt;a name="idd1e8581"&gt;&lt;/a&gt;&lt;a name="idd1e8584"&gt;&lt;/a&gt;&lt;a name="idd1e8589"&gt;&lt;/a&gt;&lt;a name="idd1e8592"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="docText"&gt;Now you'll update &lt;tt&gt;AnimationTest1&lt;/tt&gt; to use the new and  improved &lt;tt&gt;ScreenManager&lt;/tt&gt;, creating the &lt;tt&gt;AnimationTest2&lt;/tt&gt; class. &lt;span style="font-weight: bold;"&gt;Hooray&lt;/span&gt;, no more  flickering!&lt;a name="idd1e8613"&gt;&lt;/a&gt;&lt;a name="idd1e8616"&gt;&lt;/a&gt;&lt;a name="idd1e8621"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p style="font-weight: bold;"&gt;Listing AnimationTest2.java&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;import java.awt.*;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;import javax.swing.ImageIcon;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;public class AnimationTest2 {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;    public static void main(String args[]) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        AnimationTest2 test = new AnimationTest2();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        test.run();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;    private static final DisplayMode POSSIBLE_MODES[] = {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        new DisplayMode(800, 600, 32, 0),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        new DisplayMode(800, 600, 24, 0),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        new DisplayMode(800, 600, 16, 0),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        new DisplayMode(640, 480, 32, 0),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        new DisplayMode(640, 480, 24, 0),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        new DisplayMode(640, 480, 16, 0)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;    };&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;    private static final long DEMO_TIME = 10000;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;    private ScreenManager screen;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;    private Image bgImage;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;    private Animation anim;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;    public void loadImages() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        // load images&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        bgImage = loadImage("images/background.jpg");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        Image player1 = loadImage("images/player1.png");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        Image player2 = loadImage("images/player2.png");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        Image player3 = loadImage("images/player3.png");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        // create animation&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        anim = new Animation();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        anim.addFrame(player1, 250);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        anim.addFrame(player2, 150);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        anim.addFrame(player1, 150);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        anim.addFrame(player2, 150);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        anim.addFrame(player3, 200);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        anim.addFrame(player2, 150);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;    private Image loadImage(String fileName) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        return new ImageIcon(fileName).getImage();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;    public void run() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        screen = new ScreenManager();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        try {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;            DisplayMode displayMode =&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;                screen.findFirstCompatibleMode(POSSIBLE_MODES);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;            screen.setFullScreen(displayMode);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;            loadImages();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;            animationLoop();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        finally {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;             screen.restoreScreen();&lt;/span&gt;&lt;a style="color: rgb(0, 153, 0); font-family: courier new;" name="idd1e8643"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0); font-family: courier new;" name="idd1e8650"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0); font-family: courier new;" name="idd1e8653"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0); font-family: courier new;" name="idd1e8656"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0); font-family: courier new;" name="idd1e8661"&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;    public void animationLoop() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        long startTime = System.currentTimeMillis();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        long currTime = startTime;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        while (currTime - startTime &amp;lt; DEMO_TIME) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;            long elapsedTime =&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;                System.currentTimeMillis() - currTime;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;            currTime += elapsedTime;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;            // update animation&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;            anim.update(elapsedTime);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;            // draw and update screen&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;            Graphics2D g = screen.getGraphics();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;            draw(g);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;            g.dispose();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;            screen.update();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;            // take a nap&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;            try {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;                Thread.sleep(20);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;            catch (InterruptedException ex) { }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;    public void draw(Graphics g) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        // draw background&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        g.drawImage(bgImage, 0, 0, null);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        // draw image&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;        g.drawImage(anim.getImage(), 0, 0, null);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;}&lt;/span&gt;&lt;a style="color: rgb(0, 153, 0); font-family: courier new;" name="idd1e8667"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0); font-family: courier new;" name="idd1e8674"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0); font-family: courier new;" name="idd1e8677"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0); font-family: courier new;" name="idd1e8680"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 153, 0); font-family: courier new;" name="idd1e8685"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p class="docText"&gt;Not much has changed in the move from &lt;tt&gt;AnimationTest1&lt;/tt&gt;  to &lt;tt&gt;AnimationTest2&lt;/tt&gt;. One thing that has changed is how  &lt;tt&gt;AnimationTest2&lt;/tt&gt; selects a display mode. Instead of using a default  display mode or getting the display mode from the command line,  &lt;tt&gt;AnimationTest2&lt;/tt&gt; provides the &lt;tt&gt;ScreenManager&lt;/tt&gt; with a list of  possible modes to use, and the &lt;tt&gt;ScreenManager&lt;/tt&gt; selects the first  compatible mode in the list.&lt;/p&gt; &lt;p class="docText"&gt;Also, the &lt;tt&gt;ScreenManager&lt;/tt&gt; creates its own  &lt;tt&gt;JFrame&lt;/tt&gt; object, so &lt;tt&gt;AnimationTest2&lt;/tt&gt; doesn't have to deal with  creating the &lt;tt&gt;JFrame&lt;/tt&gt; used as the full-screen window.&lt;/p&gt;&lt;p class="docText"&gt;Try it Out and Leave a comment on what you think&lt;br /&gt;&lt;/p&gt;&lt;pre&gt;&lt;br /&gt;&lt;/pre&gt; &lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-4327421197075958643?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/4327421197075958643/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/05/getting-rid-of-flicker-and-tearing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/4327421197075958643'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/4327421197075958643'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/05/getting-rid-of-flicker-and-tearing.html' title='Game: Getting Rid of Flicker and Tearing'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-1847363998335155924</id><published>2009-05-13T09:36:00.000-07:00</published><updated>2009-06-30T07:51:21.903-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Game'/><category scheme='http://www.blogger.com/atom/ns#' term='Animation'/><category scheme='http://www.blogger.com/atom/ns#' term='2D graphics'/><category scheme='http://www.blogger.com/atom/ns#' term='JAVA'/><title type='text'>Game : 2D Graphics in Animation</title><content type='html'>Okay, enough about images and drawing! Let's  move on to something you can use in a game: animation.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Animation&lt;/span&gt;&lt;br /&gt;&lt;p class="docText"&gt;The first type of animation we'll go over is cartoon-style  animation. This type of animation is displayed as a sequence of images, one  after another. This is how animated cartoons work.&lt;a name="idd1e7141"&gt;&lt;/a&gt;&lt;/p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_lYg70zdQa3I/Sgr3SO_dOVI/AAAAAAAAACo/MGJHI4C6zUA/s1600-h/a.JPG"&gt;&lt;img style="cursor: pointer; width: 240px; height: 176px;" src="http://2.bp.blogspot.com/_lYg70zdQa3I/Sgr3SO_dOVI/AAAAAAAAACo/MGJHI4C6zUA/s320/a.JPG" alt="" id="BLOGGER_PHOTO_ID_5335348601207732562" border="0" /&gt;&lt;/a&gt;Frame 1&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/Sgr3Uz7xU3I/AAAAAAAAACw/uQFjGLJP-jU/s1600-h/b.JPG"&gt;&lt;img style="cursor: pointer; width: 239px; height: 176px;" src="http://1.bp.blogspot.com/_lYg70zdQa3I/Sgr3Uz7xU3I/AAAAAAAAACw/uQFjGLJP-jU/s320/b.JPG" alt="" id="BLOGGER_PHOTO_ID_5335348645484122994" border="0" /&gt;&lt;/a&gt;Frame 2&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/Sgr3XTZTzGI/AAAAAAAAAC4/d-EECfzqaec/s1600-h/c.JPG"&gt;&lt;img style="cursor: pointer; width: 241px; height: 176px;" src="http://1.bp.blogspot.com/_lYg70zdQa3I/Sgr3XTZTzGI/AAAAAAAAAC4/d-EECfzqaec/s320/c.JPG" alt="" id="BLOGGER_PHOTO_ID_5335348688289254498" border="0" /&gt;&lt;/a&gt;Frame 3&lt;br /&gt;&lt;br /&gt;The images in an animation can be referred to as frames. Each frame displays for  a certain amount of time, but frames don't all have to display for the same  amount of time. For example, the first frame might display for 200 milliseconds,  the second for 75 milliseconds, and so on...&lt;br /&gt;&lt;br /&gt;Take Note that : An animation is made of several images, and each image displays for a certain  amount of time. The same image can be used more than once.&lt;br /&gt;&lt;p class="docText"&gt;Now we'll take the concept of an animation and turn it into  code. We'll make it so our animations can use the same image more than once.  Also, the animations will loop indefinitely instead of just playing through  once.&lt;/p&gt;&lt;p class="docText"&gt;The &lt;tt&gt;Animation&lt;/tt&gt; class has three important methods:  &lt;tt&gt;addFrame()&lt;/tt&gt;, &lt;tt&gt;update()&lt;/tt&gt;, and &lt;tt&gt;getImage()&lt;/tt&gt;. The  &lt;tt&gt;addFrame()&lt;/tt&gt; method adds an image to the animation with a specified time  (in milliseconds) to display. The &lt;tt&gt;update()&lt;/tt&gt; method tells the animation  that a specified amount of time has passed. Finally, the &lt;tt&gt;getImage()&lt;/tt&gt;  method gets the image that should be displayed based on the amount of time that  has passed.&lt;a name="idd1e7244"&gt;&lt;/a&gt;&lt;a name="idd1e7247"&gt;&lt;/a&gt;&lt;a name="idd1e7252"&gt;&lt;/a&gt;&lt;a name="idd1e7259"&gt;&lt;/a&gt;&lt;a name="idd1e7264"&gt;&lt;/a&gt;&lt;a name="idd1e7267"&gt;&lt;/a&gt;&lt;a name="idd1e7272"&gt;&lt;/a&gt;&lt;a name="idd1e7275"&gt;&lt;/a&gt;&lt;a name="idd1e7280"&gt;&lt;/a&gt;&lt;a name="idd1e7283"&gt;&lt;/a&gt;&lt;/p&gt;&lt;h5 class="docExampleTitle"&gt;&lt;a name="ch02list05"&gt;&lt;/a&gt;Listing  Animation.java&lt;br /&gt;&lt;/h5&gt;&lt;pre&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;import java.awt.Image;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;import java.util.ArrayList;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;/**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    The Animation class manages a series of images (frames) and&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    the amount of time to display each frame.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;*/&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;public class Animation {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    private ArrayList frames;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    private int currFrameIndex;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    private long animTime;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    private long totalDuration;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        Creates a new, empty Animation.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    public Animation() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        frames = new ArrayList();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        totalDuration = 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        start();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        Adds an image to the animation with the specified&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        duration (time to display the image).&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    public synchronized void addFrame(Image image,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        long duration)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        totalDuration += duration;&lt;/span&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7349"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7352"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7357"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7364"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7369"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7372"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7377"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7380"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7385"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7388"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7393"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7396"&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        frames.add(new AnimFrame(image, totalDuration));&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        Starts this animation over from the beginning.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    public synchronized void start() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        animTime = 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        currFrameIndex = 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        Updates this animation's current image (frame), if&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        necessary.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    public synchronized void update(long elapsedTime) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        if (frames.size() &amp;gt; 1) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;            animTime += elapsedTime;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;            if (animTime &amp;gt;= totalDuration) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;                animTime = animTime % totalDuration;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;                currFrameIndex = 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;            while (animTime &amp;gt; getFrame(currFrameIndex).endTime) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;                currFrameIndex++;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        Gets this Animation's current image. Returns null if this&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        animation has no images.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    public synchronized Image getImage() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        if (frames.size() == 0) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;            return null;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        else {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;            return getFrame(currFrameIndex).image;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    private AnimFrame getFrame(int i) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        return (AnimFrame)frames.get(i);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    private class AnimFrame {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        Image image;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        long endTime;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        public AnimFrame(Image image, long endTime) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;            this.image = image;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;            this.endTime = endTime;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;}&lt;/span&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7404"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7407"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7413"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7420"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7425"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7428"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7433"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7436"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7441"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7444"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7449"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e7452"&gt;&lt;/a&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p class="docText"&gt;In the &lt;tt&gt;Animation&lt;/tt&gt; class, you might notice the odd  &lt;tt&gt;%&lt;/tt&gt; character in the following line:&lt;/p&gt;&lt;blockquote&gt;animTime = animTime % totalDuration; &lt;/blockquote&gt; &lt;p class="docText"&gt;In case you are unfamiliar with this, the &lt;tt&gt;%&lt;/tt&gt; character  is the remainder operator, returning the remainder from an integer division. For  example, (&lt;tt&gt;10 % 3&lt;/tt&gt;) equals 1—the integer result of 10 divided by 3 is 3,  with 1 left over. It's used here to make sure the animation time starts over  when the animation is done so that the animation loops.&lt;/p&gt; &lt;p class="docText"&gt;The &lt;tt&gt;Animation&lt;/tt&gt; code is fairly straightforward. The  inner class &lt;tt&gt;AnimFrame&lt;/tt&gt; contains an image and the amount of time to  display it. Most of the work is done in &lt;tt&gt;Animation&lt;/tt&gt;'s &lt;tt&gt;update()&lt;/tt&gt;  method, which selects the correct &lt;tt&gt;AnimFrame&lt;/tt&gt; to use based on how much  time has elapsed.&lt;a name="idd1e7501"&gt;&lt;/a&gt;&lt;a name="idd1e7504"&gt;&lt;/a&gt;&lt;a name="idd1e7509"&gt;&lt;/a&gt;&lt;a name="idd1e7512"&gt;&lt;/a&gt;&lt;a name="idd1e7517"&gt;&lt;/a&gt;&lt;a name="idd1e7524"&gt;&lt;/a&gt;&lt;a name="idd1e7529"&gt;&lt;/a&gt;&lt;a name="idd1e7532"&gt;&lt;/a&gt;&lt;a name="idd1e7537"&gt;&lt;/a&gt;&lt;a name="idd1e7540"&gt;&lt;/a&gt;&lt;a name="idd1e7545"&gt;&lt;/a&gt;&lt;a name="idd1e7548"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="docText"&gt;To implement animation, you need a way to continuously update  the screen in an efficient way. Before, you relied on the &lt;tt&gt;paint()&lt;/tt&gt;  method to do any rendering. You could call &lt;tt&gt;repaint()&lt;/tt&gt; to signal the AWT  event dispatch thread to repaint the screen, but this can cause delays because  the AWT thread might be busy doing other things.&lt;a name="idd1e7566"&gt;&lt;/a&gt;&lt;a name="idd1e7571"&gt;&lt;/a&gt;&lt;a name="idd1e7574"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="docText"&gt;Another option is to use active rendering. &lt;span class="docEmphasis"&gt;Active rendering&lt;/span&gt; is a term to describe drawing directly  to the screen in the main thread. This way, you have control over when the  screen actually gets drawn, and it simplifies the code a bit.&lt;/p&gt; &lt;p class="docText"&gt;To use the active rendering technique, use &lt;tt&gt;Component&lt;/tt&gt;'s  &lt;tt&gt;getGraphics()&lt;/tt&gt; method to get the graphics context for the screen:&lt;a name="idd1e7594"&gt;&lt;/a&gt;&lt;a name="idd1e7597"&gt;&lt;/a&gt;&lt;/p&gt;&lt;blockquote&gt;Graphics g = screen.getFullScreenWindow().getGraphics();&lt;br /&gt;draw(g);&lt;br /&gt;g.dispose(); &lt;/blockquote&gt; &lt;p class="docText"&gt;Pretty simple, isn't it? As in this example, don't forget to  dispose of the &lt;tt&gt;Graphics&lt;/tt&gt; object when you're done drawing. This cleans up  some resources that the garbage collector might not get around to for a while.&lt;/p&gt;&lt;p class="docText"&gt;Now you'll use active rendering to continuously draw in a loop.  This loop is known as the animation loop. An animation loop follows these  steps:&lt;a name="idd1e7633"&gt;&lt;/a&gt;&lt;a name="idd1e7638"&gt;&lt;/a&gt;&lt;a name="idd1e7643"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;span style="font-weight: bold;"&gt;&lt;ol class="docList"&gt;&lt;li&gt;Updates any animations&lt;span value="1" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Draws to the screen&lt;span value="2" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;    &lt;li&gt;Optionally sleeps for a short period&lt;span value="3" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Starts over with step 1&lt;span value="4" style="font-weight: normal;"&gt;&lt;br /&gt;   &lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/span&gt;&lt;p class="docText"&gt;In code, the animation loop might look something like this:&lt;br /&gt;&lt;/p&gt;&lt;pre&gt;&lt;blockquote&gt;while (true) {&lt;br /&gt;&lt;br /&gt;// update any animations&lt;br /&gt;updateAnimations();&lt;br /&gt;&lt;br /&gt;// draw to screen&lt;br /&gt;Graphics g = screen.getFullScreenWindow().getGraphics();&lt;br /&gt;draw(g);&lt;br /&gt;g.dispose();&lt;br /&gt;&lt;br /&gt;// take a nap&lt;br /&gt;try {&lt;br /&gt;   Thread.sleep(20);&lt;br /&gt;}&lt;br /&gt;catch (InterruptedException ex) { }&lt;br /&gt;}&lt;/blockquote&gt;&lt;/pre&gt;&lt;p class="docText"&gt;Obviously, in a real-world example, the animation loop  shouldn't loop forever. In our examples, we'll make the animation loop stop  after a few seconds.&lt;/p&gt;&lt;p class="docText"&gt;In &lt;tt&gt;AnimationTest1&lt;/tt&gt;, you will update the entire screen  every time you draw. Alternatively, you could update only the parts of the  screen that have changed since the last draw. This method works great for games  in which the background is static, such as the maze in Pac-Man. But most modern  games have a dynamic background or have several things happening at once. Also,  redrawing only what has changed since the last draw doesn't work when you're  using page flipping, which we discuss later. In short, you'll just go ahead and  update the entire screen in these examples.&lt;a name="idd1e7691"&gt;&lt;/a&gt;&lt;a name="idd1e7696"&gt;&lt;/a&gt;&lt;a name="idd1e7701"&gt;&lt;/a&gt;&lt;/p&gt;&lt;h5 class="docExampleTitle"&gt;&lt;a name="ch02list06"&gt;&lt;/a&gt;Listing   AnimationTest1.java&lt;br /&gt;&lt;/h5&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;import java.awt.*;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;import javax.swing.ImageIcon;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;import javax.swing.JFrame;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;public class AnimationTest1 {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;    public static void main(String args[]) {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        DisplayMode displayMode;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        if (args.length == 3) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;            displayMode = new DisplayMode(&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;                Integer.parseInt(args[0]),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;                Integer.parseInt(args[1]),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;                Integer.parseInt(args[2]),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;                DisplayMode.REFRESH_RATE_UNKNOWN);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        else {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;            displayMode = new DisplayMode(800, 600, 16,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;                DisplayMode.REFRESH_RATE_UNKNOWN);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        AnimationTest1 test = new AnimationTest1();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        test.run(displayMode);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;    private static final long DEMO_TIME = 5000;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;    private SimpleScreenManager screen;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;    private Image bgImage;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;    private Animation anim;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;    public void loadImages() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        // load images&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        bgImage = loadImage("images/background.jpg");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        Image player1 = loadImage("images/player1.png");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        Image player2 = loadImage("images/player2.png");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        Image player3 = loadImage("images/player3.png");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        // create animation&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        anim = new Animation();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        anim.addFrame(player1, 250);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        anim.addFrame(player2, 150);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        anim.addFrame(player1, 150);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        anim.addFrame(player2, 150);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        anim.addFrame(player3, 200);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        anim.addFrame(player2, 150);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;    private Image loadImage(String fileName) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        return new ImageIcon(fileName).getImage();&lt;/span&gt;&lt;a style="color: rgb(0, 102, 0);" name="idd1e7734"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 102, 0);" name="idd1e7739"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 102, 0);" name="idd1e7744"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 102, 0);" name="idd1e7747"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 102, 0);" name="idd1e7754"&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;    public void run(DisplayMode displayMode) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        screen = new SimpleScreenManager();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        try {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;            screen.setFullScreen(displayMode, new JFrame());&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;            loadImages();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;            animationLoop();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        finally {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;             screen.restoreScreen();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;    public void animationLoop() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        long startTime = System.currentTimeMillis();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        long currTime = startTime;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        while (currTime - startTime &amp;lt; DEMO_TIME) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;            long elapsedTime =&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;                System.currentTimeMillis() - currTime;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;            currTime += elapsedTime;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;            // update animation&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;            anim.update(elapsedTime);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;            // draw to screen&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;            Graphics g =&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;                screen.getFullScreenWindow().getGraphics();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;            draw(g);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;            g.dispose();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;            // take a nap&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;            try {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;                Thread.sleep(20);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;            catch (InterruptedException ex) { }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;    public void draw(Graphics g) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        // draw background&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        g.drawImage(bgImage, 0, 0, null);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        // draw image&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;        g.drawImage(anim.getImage(), 0, 0, null);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;}&lt;/span&gt;&lt;a style="color: rgb(0, 102, 0);" name="idd1e7758"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 102, 0);" name="idd1e7763"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 102, 0);" name="idd1e7768"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 102, 0);" name="idd1e7771"&gt;&lt;/a&gt;&lt;a style="color: rgb(0, 102, 0);" name="idd1e7778"&gt;&lt;/a&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-1847363998335155924?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/1847363998335155924/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/05/okay-enough-about-images-and-drawing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/1847363998335155924'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/1847363998335155924'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/05/okay-enough-about-images-and-drawing.html' title='Game : 2D Graphics in Animation'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_lYg70zdQa3I/Sgr3SO_dOVI/AAAAAAAAACo/MGJHI4C6zUA/s72-c/a.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-4237074815843709250</id><published>2009-05-10T21:01:00.000-07:00</published><updated>2009-06-30T07:51:11.145-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Game'/><category scheme='http://www.blogger.com/atom/ns#' term='2D graphics'/><category scheme='http://www.blogger.com/atom/ns#' term='JAVA'/><title type='text'>Game : Using Images in 2D Graphics and Animation</title><content type='html'>&lt;p style="font-family: arial;" class="docText"&gt;Drawing text on the screen is fun and all, but you probably  want to have some images in your game, right? Right. Before you draw images on  the screen, let's learn about some image fundamentals: transparency types and  file formats.&lt;/p&gt;&lt;ul  style="font-family:arial;"&gt;&lt;li&gt; &lt;p class="docText"&gt;&lt;span class="docEmphStrong"&gt;Opaque&lt;/span&gt;. Every pixel in the  image is visible.&lt;a name="idd1e6083"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p class="docText"&gt;&lt;span class="docEmphStrong"&gt;Transparent&lt;/span&gt;. Every pixel in  the image is either completely visible or completely see-through. In the image,  the white background could be transparent so that what's "underneath" the image  shows through when it is drawn.&lt;a name="idd1e6097"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p class="docText"&gt;&lt;span class="docEmphStrong"&gt;Translucent&lt;/span&gt;. Pixels can be  partially transparent, to create a ghostlike, partially see-through effect.  Also, translucency can be used just on the edges of an image, to create an  anti-aliased image.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;File Formats&lt;/span&gt;&lt;br /&gt;&lt;p style="font-family: arial;" class="docText"&gt;Two basic types of image formats exist: raster and vector. A  raster image format describes images just like your display does, in terms of  pixels with a specified bit depth. A vector image format describes an image  geometrically and can be resized without degrading the quality.&lt;a name="idd1e6134"&gt;&lt;/a&gt;&lt;a name="idd1e6139"&gt;&lt;/a&gt;&lt;a name="idd1e6142"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p style="font-family: arial;" class="docText"&gt;The Java API doesn't have any vector formats built in, so we  focus on raster images.&lt;a name="idd1e6154"&gt;&lt;/a&gt;&lt;a name="idd1e6157"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p style="font-family: arial;" class="docText"&gt;The Java runtime has three different raster formats built in,  and you can read them with hardly any effort. These three formats are GIF, PNG,  and JPEG:&lt;a name="idd1e6163"&gt;&lt;/a&gt;&lt;/p&gt; &lt;ul  style="font-family:arial;"&gt;&lt;li&gt; &lt;p class="docText"&gt;&lt;span class="docEmphStrong"&gt;GIF&lt;/span&gt;. GIF images can be either  opaque or transparent, and can have 8-bit color or less. Although GIF has high  compression for graphics images without a lot of color variation, PNG supercedes  GIF's functionality, so there's no reason to use GIF anymore.&lt;a name="idd1e6181"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p class="docText"&gt;&lt;span class="docEmphStrong"&gt;PNG&lt;/span&gt;. PNG images can have any  type of transparency: opaque, transparent, or translucent. Also, PNG images can  have any bit depth, all the way up to 24-bit color. The compression ratio for  8-bit PNG images is about the same as for GIF images.&lt;a name="idd1e6195"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p class="docText"&gt;&lt;span class="docEmphStrong"&gt;JPEG&lt;/span&gt;. JPEG images can be  opaque, 24-bit images only. JPEG has high compression for photographic images,  but it is a lossy compression, so the image isn't an exact replica of its  source.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family:arial;"&gt;To read Image into your program and display them you use the Toolkit's getImage() method.&lt;/span&gt; heres how:&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:courier new;"&gt;Toolkit toolkit = Toolkit.getDefaultToolkit(); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Image image = toolkit.getImage(fileName); &lt;/span&gt;&lt;/blockquote&gt;&lt;p style="font-family: arial;" class="docText"&gt;This code looks innocent enough, but it doesn't actually load  the image. The image begins loading in another thread. If you display the image  before it is finished loading, only part (or none) of the image actually gets  displayed.&lt;/p&gt; &lt;p style="font-family: arial;" class="docText"&gt;You can use a MediaTracker object to watch the image and wait  for it to finish loading, but there is an easier solution. The  ImageIcon class loads an image using MediaTracker for you. The  ImageIcon class in the javax.swing package loads an image using the  Toolkit and waits for it to finish loading before it returns. For example:&lt;a name="idd1e6310"&gt;&lt;/a&gt;&lt;a name="idd1e6313"&gt;&lt;/a&gt;&lt;a name="idd1e6318"&gt;&lt;/a&gt;&lt;a name="idd1e6321"&gt;&lt;/a&gt;&lt;/p&gt;&lt;pre  style="font-family:arial;"&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:courier new;"&gt;ImageIcon icon = new ImageIcon(fileName);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Image image = icon.getImage();&lt;/span&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;p style="font-family: arial;" class="docText"&gt;Okay, now that you can load images, you can try it. The  ImageTest class in the Listing  works similarly to the FullScreenTest class, also using  SimpleScreenManager. ImageTest draws one JPEG background image and four  PNG foreground images, waits 10 seconds, and then exits.&lt;/p&gt;&lt;p style="font-family: arial;" class="docText"&gt;Note: the image folder should be in the same directory as your source file. change the name of the files to reflect the names used in the code or vice-versa.&lt;br /&gt;&lt;/p&gt;&lt;p style="font-family: arial;" class="docText"&gt;&lt;a name="idd1e6349"&gt;&lt;/a&gt;&lt;a name="idd1e6352"&gt;&lt;/a&gt;&lt;/p&gt;&lt;h5 style="font-family: arial;" class="docExampleTitle"&gt;&lt;a name="ch02list03"&gt;&lt;/a&gt;&lt;/h5&gt;&lt;h5 class="docExampleTitle"&gt;&lt;a name="ch02list03"&gt;&lt;/a&gt;Listing ImageTest.java&lt;br /&gt;&lt;/h5&gt;&lt;pre&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;import java.awt.*;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;import javax.swing.ImageIcon;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;import javax.swing.JFrame;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;public class ImageTest extends JFrame {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    public static void main(String[] args) {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        DisplayMode displayMode;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        if (args.length == 3) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;            displayMode = new DisplayMode(&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;                Integer.parseInt(args[0]),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;                Integer.parseInt(args[1]),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;                Integer.parseInt(args[2]),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;                DisplayMode.REFRESH_RATE_UNKNOWN);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        else {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;            displayMode = new DisplayMode(800, 600, 16,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;                DisplayMode.REFRESH_RATE_UNKNOWN);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        ImageTest test = new ImageTest();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        test.run(displayMode);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    private static final int FONT_SIZE = 24;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    private static final long DEMO_TIME = 10000;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    private SimpleScreenManager screen;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    private Image bgImage;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    private Image opaqueImage;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    private Image transparentImage;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    private Image translucentImage;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    private Image antiAliasedImage;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    private boolean imagesLoaded;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    public void run(DisplayMode displayMode) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        setBackground(Color.blue);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        setForeground(Color.white);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        setFont(new Font("Dialog", Font.PLAIN, FONT_SIZE));&lt;/span&gt;&lt;a style="color: rgb(51, 204, 0);" name="idd1e6480"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 204, 0);" name="idd1e6485"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 204, 0);" name="idd1e6490"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 204, 0);" name="idd1e6497"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 204, 0);" name="idd1e6500"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 204, 0);" name="idd1e6505"&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        imagesLoaded = false;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        screen = new SimpleScreenManager();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        try {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;            screen.setFullScreen(displayMode, this);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;            loadImages();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;            try {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;                Thread.sleep(DEMO_TIME);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;            catch (InterruptedException ex) { }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        finally {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;             screen.restoreScreen();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    public void loadImages() {&lt;/span&gt;&lt;br /&gt;     //Place a folder called "images"&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        bgImage = loadImage("images/background.jpg");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        opaqueImage = loadImage("images/opaque.png");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        transparentImage = loadImage("images/transparent.png");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        translucentImage = loadImage("images/translucent.png");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        antiAliasedImage = loadImage("images/antialiased.png");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        imagesLoaded = true;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        // signal to AWT to repaint this window&lt;/span&gt;&lt;a style="color: rgb(51, 204, 0);" name="idd1e6511"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 204, 0);" name="idd1e6516"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 204, 0);" name="idd1e6521"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 204, 0);" name="idd1e6528"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 204, 0);" name="idd1e6531"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 204, 0);" name="idd1e6536"&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        repaint();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    private Image loadImage(String fileName) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        return new ImageIcon(fileName).getImage();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    public void paint(Graphics g) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        // set text anti-aliasing&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        if (g instanceof Graphics2D) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;            Graphics2D g2 = (Graphics2D)g;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;            g2.setRenderingHint(&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;                RenderingHints.KEY_TEXT_ANTIALIASING,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        // draw images&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        if (imagesLoaded) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;            g.drawImage(bgImage, 0, 0, null);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;            drawImage(g, opaqueImage, 0, 0, "Opaque");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;            drawImage(g, transparentImage, 320, 0, "Transparent");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;            drawImage(g, translucentImage, 0, 300, "Translucent");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;            drawImage(g, antiAliasedImage, 320, 300,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;                "Translucent (Anti-Aliased)");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        else {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;            g.drawString("Loading Images...", 5, FONT_SIZE);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    public void drawImage(Graphics g, Image image, int x, int y,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        String caption)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        g.drawImage(image, x, y, null);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        g.drawString(caption, x + 5, y + FONT_SIZE +&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;            image.getHeight(null));&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;}&lt;/span&gt;&lt;a style="color: rgb(51, 204, 0);" name="idd1e6542"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 204, 0);" name="idd1e6547"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 204, 0);" name="idd1e6552"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 204, 0);" name="idd1e6559"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 204, 0);" name="idd1e6562"&gt;&lt;/a&gt;&lt;a style="color: rgb(51, 204, 0);" name="idd1e6567"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p class="docText"&gt;Before the images are loaded, the &lt;tt&gt;ImageTest&lt;/tt&gt; class  shows a "Loading images" message. After the images are loaded,  &lt;tt&gt;repaint()&lt;/tt&gt; is called to signal the AWT to repaint the screen. At that  point, the background and four PNGs are drawn.&lt;a name="idd1e6582"&gt;&lt;/a&gt;&lt;a name="idd1e6585"&gt;&lt;/a&gt;&lt;a name="idd1e6590"&gt;&lt;/a&gt;&lt;a name="idd1e6595"&gt;&lt;/a&gt;&lt;/p&gt;&lt;pre&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-4237074815843709250?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/4237074815843709250/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/05/game-using-images-in-2d-graphics-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/4237074815843709250'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8090004115078610550/posts/default/4237074815843709250'/><link rel='alternate' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/05/game-using-images-in-2d-graphics-and.html' title='Game : Using Images in 2D Graphics and Animation'/><author><name>saharkiz</name><uri>http://www.blogger.com/profile/07959081897702084177</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_lYg70zdQa3I/SeFds2wQsxI/AAAAAAAAAAM/898O_WLymw4/S220/DSC00522.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8090004115078610550.post-2463300021661089709</id><published>2009-05-06T07:06:00.000-07:00</published><updated>2009-06-30T07:50:58.472-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='BLUEJ'/><category scheme='http://www.blogger.com/atom/ns#' term='Game'/><category scheme='http://www.blogger.com/atom/ns#' term='2D graphics'/><category scheme='http://www.blogger.com/atom/ns#' term='Simple Screen Manager'/><category scheme='http://www.blogger.com/atom/ns#' term='JAVA'/><title type='text'>Game: 2D Graphics and Animation</title><content type='html'>&lt;span style="font-family:arial;"&gt;First off, you can create three types of graphical games in Java: an applet game, a windowed game, and a full-screen game.&lt;/span&gt;&lt;br /&gt;&lt;ul style="font-family: arial; color: rgb(0, 0, 0);"&gt;&lt;li&gt;Applet games. Java applet games are applications that run in a web browser. The benefit here is that the user doesn't have to install anything. But players have to be online and running a web browser to play, and, unfortunately, applets have a few security restrictions to keep malicious code from causing harm. For example, applets can't save information such as preferences or saved games to the user's hard drive. Also, an applet can make a network connection only to the server that it came from.&lt;/li&gt;&lt;li&gt;Windowed games. Windowed Java games don't have the security restrictions that applets do. In fact, they look and behave like a normal application, with a title bar, a close button, and so on. However, these user interface elements can be distracting to the player, especially when you want players to become immersed in your game.&lt;/li&gt;&lt;li&gt;Full-screen games. Full-screen Java games give you total control over the visual presentation on your game, with no desktop user interface elements such as title bars, task bars, or docks. The player can become completely immersed in your game.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;For these reasons, full-screen games are the focus here.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3 style="font-family: arial; color: rgb(0, 0, 0);" id="162609-911" class="docSection1Title"&gt;Full-Screen Graphics&lt;/h3&gt;&lt;p style="font-family: arial; color: rgb(0, 0, 0);" class="docText"&gt;Let's take a quick look at how the hardware works before you  start programming it. There are two parts to display hardware: the video card  and the monitor.&lt;a name="idd1e4649"&gt;&lt;/a&gt;&lt;a name="idd1e4654"&gt;&lt;/a&gt;&lt;a name="idd1e4659"&gt;&lt;/a&gt;&lt;a name="idd1e4664"&gt;&lt;/a&gt;&lt;a name="idd1e4669"&gt;&lt;/a&gt;&lt;a name="idd1e4672"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p style="font-family: arial; color: rgb(0, 0, 0);" class="docText"&gt;The video card stores what's on the screen in its memory and  has several functions for modifying what's displayed. Also, the video card works  behind the scenes to push what's in its memory to the monitor.&lt;/p&gt; &lt;p style="font-family: arial; color: rgb(0, 0, 0);" class="docText"&gt;The monitor simply displays the information that the video card  tells it to.&lt;/p&gt;&lt;p style="font-weight: bold; font-family: arial; color: rgb(0, 0, 0);" class="docText"&gt;Screen Layout&lt;/p&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;The monitor's screen is divided into tiny little color pixels that are all the same size. A pixel, derived from the term picture element, is a single point of light displayed by the monitor. The number of horizontal and vertical pixels that make up a screen is called the screen's resolution.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;The screen's origin is in the upper-left corner of the screen. The pixels are stored in video memory like you read a book, starting from the upper-left corner and reading left to right, top to bottom. A location on the screen can be expressed as (x,y), where x is the number of horizontal pixels from the origin, and y is the number of vertical pixels from the origin.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a style="font-family: arial; color: rgb(0, 0, 0);" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_lYg70zdQa3I/SgGcRxBOyuI/AAAAAAAAACg/egdJ-245zGo/s1600-h/untitled.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 178px;" src="http://1.bp.blogspot.com/_lYg70zdQa3I/SgGcRxBOyuI/AAAAAAAAACg/egdJ-245zGo/s320/untitled.JPG" alt="" id="BLOGGER_PHOTO_ID_5332715262813588194" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;What resolutions you can pick depends on the capabilities of the video card and monitor. Typical resolutions are 640x480, 800x600, 1024x768, and 1280x1024.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;Typical monitors and televisions have a display size ratio of 4:3. That means the height of the display is three quarters of the size of the width. Some newer monitors have a wider screen with a display size ratio of 3:2 or 16:10. To compare, wide-screen movies typically have a display size ratio of 16:9.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:arial;" &gt;Big old CRT (cathode ray tube) monitors are capable of showing all sorts of resolutions cleanly because CRTs draw pixels with an electron beam. Leaner LCD (liquid crystal display) monitors found on laptops and newer computer systems are a different story, however. Because each pixel on a LCD is lit with a physical transistor, LCDs have one native resolution, which is the resolution that the LCD was designed to display. Non-native resolutions might appear blocky or fuzzy on LCDs. Because of this, it's a good idea to make sure your game can run in two or three different resolutions so players can pick the one that looks best on their system.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);font-family:arial;" &gt;&lt;br /&gt;Pixel Color and Bit Depth&lt;/span&gt;&lt;br /&gt;&lt;p class="docText" face="arial"&gt;As a child, you were probably taught the three primary colors  of red, yellow, and blue. You also probably heard the phrase, "yellow plus blue  is green." The idea is that when you are painting or using another physical  medium, you can combine these three colors to create any color you want. This is  known as a subtractive color model, in which the absence of all color is white.  (Actually, it's not an exact color model—modern printers use a more  sophisticated color model using cyan, magenta, yellow, and black instead.)&lt;a name="idd1e4902"&gt;&lt;/a&gt;&lt;a name="idd1e4909"&gt;&lt;/a&gt;&lt;a name="idd1e4912"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="docText" style="font-family: arial;"&gt;This is similar to how computer monitors and televisions work.  Monitors combine red, blue, and green to create any color. Instead of a physical  medium such as paint or inks, monitors emit light, so the RGB color model is an  additive color model, in which adding all the colors together creates white.&lt;a name="idd1e4920"&gt;&lt;/a&gt;&lt;a name="idd1e4927"&gt;&lt;/a&gt;&lt;a name="idd1e4930"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="docText" style="font-family: arial;"&gt;The number of colors a monitor can display depends on the bit  depth of the display mode. Common bit depths are 8, 15, 16, 24, and 32 bits.&lt;a name="idd1e4938"&gt;&lt;/a&gt;&lt;a name="idd1e4945"&gt;&lt;/a&gt;&lt;a name="idd1e4950"&gt;&lt;/a&gt;&lt;a name="idd1e4955"&gt;&lt;/a&gt;&lt;a name="idd1e4958"&gt;&lt;/a&gt;&lt;/p&gt; &lt;ul face="arial"&gt;&lt;li&gt; &lt;p class="docList"&gt;8-bit color has 2&lt;sup&gt;8&lt;/sup&gt; = 256 colors. Only 256 colors can  be displayed at a time, based on a palette of colors. Unfortunately, there is  currently no way in Java to change the palette, and the specification doesn't  say what those colors are. The Java runtime can use a web-safe palette, which  has 216 possible colors: 6 possible values each for red, green, and blue  (6x6x6=216).&lt;a name="idd1e4972"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p class="docList"&gt;15-bit color has 5 bits for red, green, and blue, for a total  of 2&lt;sup&gt;15&lt;/sup&gt; = 32,768 colors.&lt;a name="idd1e4982"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p class="docList"&gt;16-bit color has 5 bits for red and blue, and 6 bits for green,  for a total of 2&lt;sup&gt;16&lt;/sup&gt; = 65,536 colors.&lt;a name="idd1e4992"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p class="docList"&gt;24-bit color has 8 bits for red, green, and blue, or  2&lt;sup&gt;24&lt;/sup&gt; = 16,777,216 colors.&lt;a name="idd1e5002"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p class="docList"&gt;32-bit color is the same as 24-bit color, but with an extra 8  bits of padding to keep pixel data aligned on 32-bit boundaries.&lt;a name="idd1e5009"&gt;&lt;/a&gt;&lt;a name="idd1e5012"&gt;&lt;/a&gt;&lt;a name="idd1e5019"&gt;&lt;/a&gt;&lt;a name="idd1e5024"&gt;&lt;/a&gt;&lt;a name="idd1e5029"&gt;&lt;/a&gt;&lt;a name="idd1e5032"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p class="docText" style="font-family: arial;"&gt;Most modern video cards support 8-, 16-, and 32-bit modes.  Because the human eye can see about 10 million colors, 24-bit color is ideal.  16-bit color is a little faster than 24-bit color because there is less data to  transfer, but the color quality isn't as accurate.&lt;a name="idd1e5040"&gt;&lt;/a&gt;&lt;a name="idd1e5045"&gt;&lt;/a&gt;&lt;a name="idd1e5048"&gt;&lt;/a&gt;&lt;a name="idd1e5051"&gt;&lt;/a&gt;&lt;a name="idd1e5054"&gt;&lt;/a&gt;&lt;a name="idd1e5059"&gt;&lt;/a&gt;&lt;a name="idd1e5064"&gt;&lt;/a&gt;&lt;a name="idd1e5067"&gt;&lt;/a&gt;&lt;/p&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;Refresh Rate&lt;br /&gt;&lt;/span&gt;&lt;p class="docText" style="font-family: arial;"&gt;Even though your monitor looks like it's displaying a solid  image, each pixel actually fades away after a few milliseconds. To make up for  this, the monitor continuously refreshes the display to keep it from fading. How  fast it refreshes the display is known as the &lt;span class="docEmphasis"&gt;refresh  rate&lt;/span&gt;. The refresh rate is measured in Hertz (Hz), which means cycles per  second. A refresh rate between 75Hz and 85Hz is usually suitable for the human  eye.&lt;a name="idd1e5082"&gt;&lt;/a&gt;&lt;a name="idd1e5089"&gt;&lt;/a&gt;&lt;a name="idd1e5094"&gt;&lt;/a&gt;&lt;a name="idd1e5099"&gt;&lt;/a&gt;&lt;a name="idd1e5102"&gt;&lt;/a&gt;&lt;a name="idd1e5105"&gt;&lt;/a&gt;&lt;/p&gt;&lt;a style="font-family: arial;" name="ch02lev2sec4"&gt;&lt;/a&gt; &lt;h4 style="font-family: arial;" class="docSection2Title"&gt;Switching the Display to Full-Screen Mode&lt;/h4&gt; &lt;p style="font-family: arial;" class="docText"&gt;Now that you know all about resolutions, bit depths, and  refresh rates, let's write some code. You'll need a few objects to switch the  display to full-screen mode:&lt;a name="idd1e5117"&gt;&lt;/a&gt;&lt;a name="idd1e5122"&gt;&lt;/a&gt;&lt;/p&gt; &lt;ul style="font-family: arial;"&gt;&lt;li&gt; &lt;p class="docText"&gt;&lt;span class="docEmphStrong"&gt;A Window object&lt;/span&gt;. The  Window object is an abstraction of what is displayed on the  screen—think of it as a canvas to draw on. The examples here actually use a  JFrame, which is a subclass of the Window class and can also  be used for making windowed applications.&lt;a name="idd1e5154"&gt;&lt;/a&gt;&lt;a name="idd1e5157"&gt;&lt;/a&gt;&lt;a name="idd1e5162"&gt;&lt;/a&gt;&lt;a name="idd1e5165"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p class="docText"&gt;&lt;span class="docEmphStrong"&gt;A DisplayMode object&lt;/span&gt;.  The DisplayMode object specifies the resolution, bit depth, and refresh  rate to switch the display to.&lt;a name="idd1e5187"&gt;&lt;/a&gt;&lt;a name="idd1e5190"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p class="docText"&gt;&lt;span class="docEmphStrong"&gt;A GraphicsDevice  object&lt;/span&gt;. The GraphicsDevice object enables you to change the  display mode and inspect display properties. Think of it as an interface to your  video card. The GraphicsDevice object is acquired from the  GraphicsEnvironment object.&lt;a name="idd1e5218"&gt;&lt;/a&gt;&lt;a name="idd1e5221"&gt;&lt;/a&gt;&lt;a name="idd1e5226"&gt;&lt;/a&gt;&lt;a name="idd1e5229"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p style="font-family: arial;" class="docText"&gt;Here's an example of how to switch the display to full-screen  mode:&lt;/p&gt;&lt;pre style="font-family: arial;"&gt;&lt;blockquote&gt;JFrame window = new JFrame();&lt;br /&gt;DisplayMode displayMode = new DisplayMode(800, 600, 16, 75);&lt;br /&gt;&lt;br /&gt;// get the GraphicsDevice&lt;br /&gt;GraphicsEnvironment environment =&lt;br /&gt;GraphicsEnvironment.getLocalGraphicsEnvironment();&lt;br /&gt;GraphicsDevice device = environment.getDefaultScreenDevice();&lt;br /&gt;&lt;br /&gt;// use the JFrame as the full screen window&lt;br /&gt;device.setFullScreenWindow(window);&lt;br /&gt;&lt;br /&gt;// change the display mode&lt;br /&gt;device.setDisplayMode(displayMode);&lt;/blockquote&gt;&lt;br /&gt;&lt;/pre&gt; &lt;p style="font-family: arial;" class="docText"&gt;Afterward, to switch back to the previous display mode, set the  full-screen Window to null:&lt;/p&gt;&lt;pre style="font-family: arial;"&gt;&lt;blockquote&gt;device.setFullScreenWindow(null);&lt;/blockquote&gt;&lt;br /&gt;&lt;/pre&gt; &lt;p style="font-family: arial;" class="docText"&gt;Note that this code isn't complete. Some systems won't allow  you to change the display mode, and setDisplayMode() throws an  IllegalArgumentException on those systems.&lt;a name="idd1e5265"&gt;&lt;/a&gt;&lt;a name="idd1e5268"&gt;&lt;/a&gt;&lt;a name="idd1e5273"&gt;&lt;/a&gt;&lt;a name="idd1e5276"&gt;&lt;/a&gt;&lt;a name="idd1e5281"&gt;&lt;/a&gt;&lt;a name="idd1e5286"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p style="font-family: arial;" class="docText"&gt;Also, by default, JFrames still show their borders and  title bars, even in full-screen mode. We'll deal with these issues and simplify  the functions by creating a wrapper class called SimpleScreenManager.&lt;a name="idd1e5302"&gt;&lt;/a&gt;&lt;a name="idd1e5305"&gt;&lt;/a&gt;&lt;a name="idd1e5310"&gt;&lt;/a&gt;&lt;a name="idd1e5313"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p style="font-family: arial;" class="docText"&gt;The SimpleScreenManager class is a simple interface to change  the display to full-screen mode. Behind the scenes, SimpleScreenManager  catches Exceptions and removes the JFrame's border and title bar with a  call to setUndecorated(true). Also, the JFrame is disposed  when the screen is restored.&lt;/p&gt;&lt;p style="font-family: arial;" class="docText"&gt;&lt;a name="idd1e5340"&gt;&lt;/a&gt;&lt;a name="idd1e5343"&gt;&lt;/a&gt;&lt;a name="idd1e5348"&gt;&lt;/a&gt;&lt;a name="idd1e5351"&gt;&lt;/a&gt;&lt;/p&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;Listing  SimpleScreenManager.java&lt;br /&gt;&lt;/span&gt;&lt;pre  style="font-family:arial;"&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;import java.awt.*;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;import javax.swing.JFrame;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;/**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    The SimpleScreenManager class manages initializing and&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    displaying full screen graphics modes.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;*/&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;public class SimpleScreenManager {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    private GraphicsDevice device;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        Creates a new SimpleScreenManager object.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    public SimpleScreenManager() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        GraphicsEnvironment environment =&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;            GraphicsEnvironment.getLocalGraphicsEnvironment();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        device = environment.getDefaultScreenDevice();&lt;/span&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e5373"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e5378"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e5385"&gt;&lt;/a&gt;&lt;a style="color: rgb(204, 0, 0);" name="idd1e5388"&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        Enters full screen mode and changes the display mode.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    public void setFullScreen(DisplayMode displayMode,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        JFrame window)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        window.setUndecorated(true);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        window.setResizable(false);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        device.setFullScreenWindow(window);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        if (displayMode != null &amp;amp;&amp;amp;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;            device.isDisplayChangeSupported())&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;            try {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;                device.setDisplayMode(displayMode);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;            catch (IllegalArgumentException ex) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;                // ignore - illegal mode for this device&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        Returns the window currently used in full screen mode.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    public Window getFullScreenWindow() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        return device.getFullScreenWindow();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    /**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        Restores the screen's display mode.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    public void restoreScreen() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        Window window = device.getFullScreenWindow();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        if (window != null) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;            window.dispose();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;        device.setFullScreenWindow(null);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;}&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="idd1e5396"&gt;&lt;/a&gt;&lt;a name="idd1e5401"&gt;&lt;/a&gt;&lt;a name="idd1e5408"&gt;&lt;/a&gt;&lt;a name="idd1e5411"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p style="font-family: arial;" class="docText"&gt;Now let's put the SimpleScreenManager to use. The  FullScreenTest class tests the methods of the SimpleScreenManager class. It changes  the display to full-screen mode, displays a "Hello World!" message, waits five  seconds, and exits.&lt;a name="idd1e5435"&gt;&lt;/a&gt;&lt;a name="idd1e5438"&gt;&lt;/a&gt;&lt;a name="idd1e5443"&gt;&lt;/a&gt;&lt;a name="idd1e5446"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p style="font-family: arial;" class="docText"&gt;FullScreenTest runs in a resolution of 800x600 and a  bit depth of 16. If you want to run at a different resolution, just specify the  different display mode at the command line. The program treats the first,  second, and third arguments passed to it as the width, height, and bit depth of  the display mode. For example, entering this at the console runs the program at  resolution of 1024x768 and a bit depth of 32:&lt;a name="idd1e5456"&gt;&lt;/a&gt;&lt;a name="idd1e5463"&gt;&lt;/a&gt;&lt;a name="idd1e5468"&gt;&lt;/a&gt;&lt;a name="idd1e5473"&gt;&lt;/a&gt;&lt;a name="idd1e5476"&gt;&lt;/a&gt;&lt;a name="idd1e5481"&gt;&lt;/a&gt;&lt;a name="idd1e5484"&gt;&lt;/a&gt;&lt;a name="idd1e5487"&gt;&lt;/a&gt;&lt;/p&gt;&lt;blockquote style="font-family: arial;"&gt;java FullScreenTest 1024 768 32 &lt;/blockquote&gt; &lt;p style="font-family: arial;" class="docText"&gt;Note that the code doesn't allow you to set an "illegal" mode  that will do something crazy like set the monitor on fire. If the display mode  you request isn't available or the system doesn't have full-screen support, an  IllegalArgumentException is thrown and the demo mimics full-screen mode  using the current display mode.&lt;/p&gt;&lt;p face="arial" style="font-weight: bold; font-family: arial;" class="docText"&gt;Listing  FullScreenTest.java&lt;/p&gt;&lt;p style="font-family: arial;" class="docText"&gt;&lt;a name="idd1e5501"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style="font-family: arial;" class="docText"&gt;&lt;a name="idd1e5501"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style="font-family: arial;" class="docText"&gt;&lt;a name="idd1e5501"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style="font-family: arial;" class="docText"&gt;&lt;a name="idd1e5501"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style="font-family: arial;" class="docText"&gt;&lt;a name="idd1e5501"&gt;&lt;/a&gt;&lt;a name="idd1e5506"&gt;&lt;/a&gt;&lt;a name="idd1e5513"&gt;&lt;/a&gt;&lt;a name="idd1e5516"&gt;&lt;/a&gt;&lt;/p&gt;&lt;pre style="font-family: arial;"&gt;&lt;br /&gt;&lt;blockquote style="color: rgb(51, 51, 255);"&gt;import java.awt.*;&lt;br /&gt;import javax.swing.JFrame;&lt;br /&gt;&lt;br /&gt;public class FullScreenTest extends JFrame {&lt;br /&gt;&lt;br /&gt;public static void main(String[] args) {&lt;br /&gt;&lt;br /&gt;DisplayMode displayMode;&lt;br /&gt;&lt;br /&gt;if (args.length == 3) {&lt;br /&gt; displayMode = new DisplayMode(&lt;br /&gt;     Integer.parseInt(args[0]),&lt;br /&gt;     Integer.parseInt(args[1]),&lt;br /&gt;     Integer.parseInt(args[2]),&lt;br /&gt;     DisplayMode.REFRESH_RATE_UNKNOWN);&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt; displayMode = new DisplayMode(800, 600, 16,&lt;br /&gt;     DisplayMode.REFRESH_RATE_UNKNOWN);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;FullScreenTest test = new FullScreenTest();&lt;br /&gt;test.run(displayMode);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private static final long DEMO_TIME = 5000;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public void run(DisplayMode displayMode) {&lt;br /&gt;setBackground(Color.blue);&lt;br /&gt;setForeground(Color.white);&lt;br /&gt;setFont(new Font("Dialog", Font.PLAIN, 24));&lt;br /&gt;&lt;br /&gt;SimpleScreenManager screen = new SimpleScreenManager();&lt;br /&gt;try {&lt;br /&gt; screen.setFullScreen(displayMode, this);&lt;a name="idd1e5538"&gt;&lt;/a&gt;&lt;a name="idd1e5543"&gt;&lt;/a&gt;&lt;a name="idd1e5550"&gt;&lt;/a&gt;&lt;a name="idd1e5557"&gt;&lt;/a&gt;&lt;br /&gt; try {&lt;br /&gt;     Thread.sleep(DEMO_TIME);&lt;br /&gt; }&lt;br /&gt; catch (InterruptedException ex) { }&lt;br /&gt;}&lt;br /&gt;finally {&lt;br /&gt;  screen.restoreScreen();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public void paint(Graphics g) {&lt;br /&gt;g.drawString("Hello World!", 20, 50);&lt;br /&gt;}&lt;br /&gt;}&lt;a name="idd1e5561"&gt;&lt;/a&gt;&lt;a name="idd1e5566"&gt;&lt;/a&gt;&lt;a name="idd1e5573"&gt;&lt;/a&gt;&lt;a name="idd1e5580"&gt;&lt;/a&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p style="font-family: arial;" class="docText"&gt;One thing to note in FullScreenTest is the use of the  try/finally block in the run() method. Restoring the  screen in the finally block guarantees that the screen will always be  restored, even if an Exception is thrown in the try block.&lt;a name="idd1e5608"&gt;&lt;/a&gt;&lt;a name="idd1e5611"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p style="font-family: arial;" class="docText"&gt;Besides that, the first thing you might notice in  FullScreenTest is the Graphics object used in the  paint() method. The Graphics object provides all sorts of  functions for drawing text, lines, rectangles, ovals, polygons, images, and so  on. Most of the methods are self-explanatory, so check out the Java API  specification for all the juicy details.&lt;a name="idd1e5631"&gt;&lt;/a&gt;&lt;a name="idd1e5634"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p style="font-family: arial;" class="docText"&gt;If you're asking yourself, "Hey, how does that paint()  method get called, anyway?" the answer is, well, magic. Actually, you'll notice  that FullScreenTest is a JFrame. When a JFrame (or  any other component, for that matter) is displayed, Java's Abstract Window  Toolkit, or AWT, calls the component's paint() method.&lt;a name="idd1e5657"&gt;&lt;/a&gt;&lt;a name="idd1e5660"&gt;&lt;/a&gt;&lt;a name="idd1e5665"&gt;&lt;/a&gt;&lt;a name="idd1e5668"&gt;&lt;/a&gt;&lt;a name="idd1e5673"&gt;&lt;/a&gt;&lt;a name="idd1e5678"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p style="font-family: arial;" class="docText"&gt;If you want to force the AWT to call the paint()  method, call repaint(). This signals to the AWT to call the  paint() method when it gets around to it. The AWT send paint  events in a separate thread, so if you want to send a repaint event and  then wait for the painting to complete, use something like this:&lt;a name="idd1e5699"&gt;&lt;/a&gt;&lt;a name="idd1e5702"&gt;&lt;/a&gt;&lt;a name="idd1e5707"&gt;&lt;/a&gt;&lt;a name="idd1e5710"&gt;&lt;/a&gt;&lt;a name="idd1e5715"&gt;&lt;/a&gt;&lt;a name="idd1e5720"&gt;&lt;/a&gt;&lt;/p&gt;&lt;pre style="font-family: arial;"&gt;&lt;blockquote style="color: rgb(0, 153, 0);"&gt;public class MyComponent extends SomeComponent {&lt;br /&gt;...&lt;br /&gt;public synchronized void repaintAndWait() {&lt;br /&gt;repaint();&lt;br /&gt;try {&lt;br /&gt; wait();&lt;br /&gt;}&lt;br /&gt;catch (InterruptedException ex) { }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public synchronized void paint(Graphics g) {&lt;br /&gt;// do painting here&lt;br /&gt;...&lt;br /&gt;// notify that we're done painting&lt;br /&gt;notifyAll();&lt;br /&gt;}&lt;br /&gt;}&lt;a name="idd1e5732"&gt;&lt;/a&gt;&lt;a name="idd1e5737"&gt;&lt;/a&gt;&lt;/blockquote&gt;&lt;span style="font-weight: bold;"&gt;Anti-Aliasing&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You might notice that the "Hello World" text from &lt;tt&gt;FullScreenTest&lt;/tt&gt; looks&lt;br /&gt;a little jagged around the edges. This is because the text isn't anti-aliased.&lt;br /&gt;It might sound strange, but anti-aliasing makes the text look sharper by&lt;br /&gt;blurring the edges so that the text's color blends with the background color,&lt;br /&gt;making the staircase of pixels appear to be smoother.&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p class="docText"&gt;To make text anti-aliased, set the appropriate rendering hint  before drawing any text. The rendering hint functionality is present only in the  &lt;tt&gt;Graphics2D&lt;/tt&gt; class, which is a subclass of &lt;tt&gt;Graphics&lt;/tt&gt;.&lt;a name="idd1e5853"&gt;&lt;/a&gt;&lt;a name="idd1e5856"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="docText"&gt;For backward compatibility, the &lt;tt&gt;paint()&lt;/tt&gt; method takes a  &lt;tt&gt;Graphics&lt;/tt&gt; object as a parameter. However, starting with Java SDK 1.2,  it's actually a &lt;tt&gt;Graphics2D&lt;/tt&gt; object that is passed to the method. Here's  the code for a &lt;tt&gt;paint()&lt;/tt&gt; method with text anti-aliasing:&lt;a name="idd1e5876"&gt;&lt;/a&gt;&lt;a name="idd1e5879"&gt;&lt;/a&gt;&lt;a name="idd1e5884"&gt;&lt;/a&gt;&lt;/p&gt;&lt;blockquote style="color: rgb(153, 153, 0);"&gt;public void paint(Graphics g) {&lt;br /&gt;&lt;br /&gt;if (g instanceof Graphics2D) {&lt;br /&gt;   Graphics2D g2 = (Graphics2D)g;&lt;br /&gt;   g2.setRenderingHint(&lt;br /&gt;       RenderingHints.KEY_TEXT_ANTIALIASING,&lt;br /&gt;       RenderingHints.VALUE_TEXT_ANTIALIAS_ON);&lt;br /&gt;}&lt;br /&gt;g.drawString("Hello World!", 20, 50);&lt;br /&gt;}&lt;/blockquote&gt;&lt;p class="docText"&gt;Other rendering hints exist, including making all geometric  lines and shapes anti-aliased, setting rendering quality, and so on. See the  documentation for the &lt;tt&gt;RenderingHints&lt;/tt&gt; class for details.&lt;a name="idd1e5900"&gt;&lt;/a&gt;&lt;a name="idd1e5903"&gt;&lt;/a&gt;&lt;a name="idd1e5908"&gt;&lt;/a&gt;&lt;a name="idd1e5915"&gt;&lt;/a&gt;&lt;a name="idd1e5922"&gt;&lt;/a&gt;&lt;a name="idd1e5927"&gt;&lt;/a&gt;&lt;/p&gt;&lt;h4 class="docSection2Title"&gt;Which Display Mode to Use&lt;/h4&gt;&lt;p class="docText"&gt;A lot of display modes are available, but which one should your  game run at?&lt;a name="idd1e5937"&gt;&lt;/a&gt;&lt;a name="idd1e5942"&gt;&lt;/a&gt;&lt;a name="idd1e5947"&gt;&lt;/a&gt;&lt;a name="idd1e5954"&gt;&lt;/a&gt;&lt;a name="idd1e5961"&gt;&lt;/a&gt;&lt;a name="idd1e5966"&gt;&lt;/a&gt;&lt;a name="idd1e5973"&gt;&lt;/a&gt;&lt;a name="idd1e5976"&gt;&lt;/a&gt;&lt;a name="idd1e5979"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="docText"&gt;Well, make sure your game runs in at least two resolutions. The  general rule is to allow players to change display modes so they can pick the  one they like best on their display.&lt;/p&gt; &lt;p class="docText"&gt;If possible, initially run your game at the same resolution as  the current resolution. On LCDs, the current resolution is most likely the LCD's  native resolution, so the game will look nicer if you use the current one.&lt;/p&gt; &lt;p class="docText"&gt;As for bit depth, using 16-, 24-, or 32-bit color is a good  idea for modern games. 16-bit color is usually a little faster, but use a higher  bit depth if you need more accurate color representation.&lt;/p&gt; &lt;p class="docText"&gt;Also, a refresh rate between 75Hz and 85Hz is suitable for the  human eye.&lt;a name="idd1e5994"&gt;&lt;/a&gt;&lt;a name="idd1e5999"&gt;&lt;/a&gt;&lt;a name="idd1e6004"&gt;&lt;/a&gt;&lt;a name="idd1e6007"&gt;&lt;/a&gt;&lt;a name="idd1e6010"&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8090004115078610550-2463300021661089709?l=areshsaharkhiz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://areshsaharkhiz.blogspot.com/feeds/2463300021661089709/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://areshsaharkhiz.blogspot.com/2009/05/2d-graphics-and-animation.html#comment-form' title='0 Comments'/><link rel='edit' type='appli
