Results 1 to 4 of 4
  1. #1
    lalu is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default chess code in applet

    /* <Applet code="MyApplet8" width="480" height="480">
    </Applet>
    */
    Java Code:
    import java.applet.*;
    import java.awt.*;
    
    public class MyApplet8 extends Applet
    {
    	
    	public void paint(Graphics g)
    	{
    		int w=getWidth();
    		int h=getHeight();
    		int y=0;
    		for(int j=1;j<=4;j++)
    		{
    			
    
    		for(int i=0;i<=w;i=i+w/8)
    		{
    			
    			
    			
    			g.setColor(Color.BLACK);
    			g.fillRect(i,y,w/8,h/8);
    			i=i+w/8;
    			g.setColor(Color.WHITE);
    			g.fillRect(i,y,w/8,h/8);
    			
    		}
    			y=y+h/8;
    		for( int i=0;i<=w;i=i+w/8)
    		{
    			g.setColor(Color.WHITE);
    			g.fillRect(i,y,w/8,h/8);
    			i=i+w/8;
    			g.setColor(Color.BLACK);
    			g.fillRect(i,y,w/8,h/8);
    		}
    			y=y+h/8;
    	}
    		
         }
    }
    Last edited by Norm; 04-21-2012 at 01:39 PM. Reason: added code tags // Moved to applet area

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: chess code in applet

    Please explain what the problem is. Does it compile and excute without errors? What happens when you load it into appletviewer or a browser?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    lalu is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: chess code in applet

    this code will create chess layout of 8x8 in applet u can also use this to create same layout in frame by importing frame there is no error in this code, it is for our friends who wants to create chess layout.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: chess code in applet

    This is a forum, not a blog. As such, this thread is off topic and will be closed now and removed later.

    For those who read it before it vanishes, that badly indented code is poor on several accounts, not the least of which is that it extends the outdated AWT Applet and not the Swing JApplet which has been around for more than 10 years. The code also neglects the truncating effect of integer division, and uses two loops where one nested loop would suffice.

    db

    THREAD CLOSED
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. chess game! plz help!
    By mofaghih in forum AWT / Swing
    Replies: 2
    Last Post: 07-11-2011, 08:46 AM
  2. Help with Chess GUI
    By Lord Voldemort in forum AWT / Swing
    Replies: 9
    Last Post: 01-24-2011, 06:38 PM
  3. Seeing Code in applet
    By ravul1 in forum Java Applets
    Replies: 1
    Last Post: 12-22-2010, 02:39 PM
  4. chess game
    By michail in forum New To Java
    Replies: 13
    Last Post: 01-12-2010, 08:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •