Current location: Hot Scripts Forums » Programming Languages » Everything Java » I need help.


I need help.

Reply
  #1 (permalink)  
Old 11-10-03, 07:55 PM
silver90 silver90 is offline
New Member
 
Join Date: Oct 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
I need help.

I am trying to do an applet that will print a big Rectangle if the summ of i and j is odd and a small one if the summ is even.
This is my code. Do you have any idea why it is printing only big or small rectangle?

Thank you

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;

public class Sah extends Applet
{


public void paint(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;

int i=0;
int j=0;
int width = 320;

for(j =0; j< (width - 1); j += 40)
{

for(i =0; i< (width - 1); i += 40)
{
if ((i+j)%2 ==0)
{
Rectangle myBig = new Rectangle( i, j, 40, 40);
g2.draw(myBig);

}
else
{

Rectangle mySmall = new Rectangle( i, j, 4, 4);
g2.draw(mySmall);
}

}


}




}

}
Reply With Quote
  #2 (permalink)  
Old 11-11-03, 11:18 AM
esh esh is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Roswell, GA
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
not really following what exactly you are trying to do here...


you aren't taking any user input, all your values are hard coded, so the shapes will never change.

Code:
 
 
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
 
public class Sah extends Applet
{
 public void paint(Graphics g)
 {
  Graphics2D g2 = (Graphics2D)g;
  int i=0;
  int j=0;
  int width = 320;
 
  for(j =0; j< (width - 1); j += 40)
  {
	  for(i =0; i< (width - 1); i += 40)
	  {
		 if ((i+j)%2 ==0)
		 {
			 Rectangle myBig = new Rectangle( i, j, 40, 40);
			 g2.draw(myBig);
		 }
		 else
		 {
			 Rectangle mySmall = new Rectangle( i, j, 4, 4); 
			 g2.draw(mySmall);
		 }
	  }
   }
}
}
__________________
noemics.net

Last edited by esh; 11-11-03 at 11:29 AM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 05:38 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.