• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

applet problems

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;

}
}
}
}
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic