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 Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "applet problems" Watch "applet problems" New topic

applet problems

Kelly Frasure

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;



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

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

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

x = x + 40;


width = THICKNESS;
x = 0;
y = y + 20;
page.setColor (;
page.fillRect (x,y,width,HEIGHT);
page.setColor (;
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,
subject: applet problems
It's not a secret anymore!