permaculture playing cards*
The moose likes Applets and the fly likes applet problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "applet problems" Watch "applet problems" New topic
Author

applet problems

Kelly Frasure
Greenhorn

Joined: Mar 03, 2001
Posts: 15
I am trying to do an applet that displays rows of bricks. The rows alternate where they begin. I can get the program to compile, but the applet only displays one row of bricks. Can
someone please help?
import java.applet.Applet;
import java.awt.*;
public class Brick2 extends Applet
{

private final int MAX_X = 280;
private final int HEIGHT = 20;
private final int NUM_BRICKS = 50;
private final int THICKNESS = 40;
public void paint (Graphics page)
{
int x, y;
int width;

setBackground(Color.red);

page.setColor(Color.white);
page.fillRect(20,20,280,200);
page.setColor(Color.black);
page.drawRect(20,20,280,200);


y = 20;
width = 50;
x = 20;
for (int count = 0; count < NUM_BRICKS; count++)
{


if (x < MAX_X)
if (width > THICKNESS)
{

page.setColor (Color.red);
page.fillRect (x,y,width,HEIGHT);
page.setColor (Color.black);
page.drawRect (x,y,width,HEIGHT);

x = x + 40;


}
else

{
width = THICKNESS;
x = 0;
y = y + 20;
page.setColor (Color.red);
page.fillRect (x,y,width,HEIGHT);
page.setColor (Color.black);
page.drawRect (x,y,width,HEIGHT);
width = 50;

}
}
}
}
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Kelly,
I don't know what you are trying to do. But your current problem is that you are not ever changing the width variable inside your first if statement. You are initializing width = 50 which will always go thru your first if statement block. Since width never changes, your x variable never gets reset which leads to nothing happening for brick work ...
Good Luck,
Manfred.
 
Consider Paul's rocket mass heater.
 
subject: applet problems
 
Similar Threads
Why does it not show the new coordinates?!!??!!
Help with drawing objects on panel
Multithreading: bouncing balls problem
Applet Background Color
Newbie help with "while" statements.