Kindav a noobish question, but im having some troubles in several different programs with this. Im trying to use a variable that I defined in one method and use it in another method. To be a little specific, Im working on this (#1-pyramid), and Im trying to create one method that can find the center of the graphics window, and the next method that calls on one of the call on one of the variables when placing a block. If I wasn't making too much sense here, well heres what I got in the 5 minutes I worked on this before I got stuck:
import acm.graphics.*; import acm.program.*; import java.awt.*; public class Pyramid extends GraphicsProgram { /** Width of each brick in pixels */ private static final int BRICK_WIDTH = 30; /** Width of each brick in pixels */ private static final int BRICK_HEIGHT = 12; /** Number of bricks in the base of the pyramid */ private static final int BRICKS_IN_BASE = 14; public void run() { findCenter(); startBase(); } //This will find the center of the graphics window. public void findCenter() { int x = getWidth(); int y = getHeight(); int center = x/2; int bottom = y; } private void startBase() { } }
I havent messed with graphics programs to much, so this is going to take some work for me to learn tomorrow. Thats also why I dont have anything else filled in after the startBase() method.
Sry if some of this may not make sense. I should have dragged myself off to bed a while ago. But I guess if some of this did make sense, im looking forward to some answers!