okay so ive finished this code but now i have to modify it so that it uses the following lines of code to make the program "easier" to understand

private static void writeText(BillboardInterface billboard, int x, int y, String text)
private static void writeLetter(BillboardInterface billboard, int x, int y, char c)
private static void write_s(BillboardInterface billboard, int x, int y)
private static void write_p(BillboardInterface billboard, int x, int y)
private static void write_a(BillboardInterface billboard, int x, int y)
private static void write_r(BillboardInterface billboard, int x, int y)
private static void write_e(BillboardInterface billboard, int x, int y)

ive implemented the lines into my program and it compiles however when i try inserting code or each write_# i get a error saying Cannot find symbol - variable START_X.

here is the code so far

import java.util.Scanner;
import billboard.BillboardInterface;
import billboard.DigitalBillboardFrame;
import javax.swing.JOptionPane;

/**
 * Partial solution for Stage 2 of the digital billboard
 *
 * @author phi
 * @version 2011 2
 */
public class testClass
{
    public static void main(String[] args)
    {
        // initial size of the display in pixels
        final int WINDOW_WIDTH = 300;
        final int WINDOW_HEIGHT = 120;
        // size of the grid for the digital billboard
        final int BB_WIDTH = 50;
        final int BB_HEIGHT = 30;

        // create a billboard
        BillboardInterface billboard = new DigitalBillboardFrame(
                "SCSS",
                WINDOW_WIDTH, WINDOW_HEIGHT,
                BB_WIDTH, BB_HEIGHT);

        // we will make letters 5 cells wide and 12 high
        final int LETTER_WIDTH = 5;
        final int LETTER_HEIGHT = 12;
        // and leave a 1 cell gap between letters
        final int GAP = 1;

        // the top left of the first letter in the word will be 2 cells from the left and 1 down
        final int START_X = 10;
        final int START_Y = 8;
        
        

        final boolean isJOptionPaneUsed = true; //for Scanner (0) or JOptionPane (1);

        String inputString;  // input string recved

        // Create a Scanner object for keyboard input.
        Scanner keyboard = new Scanner(System.in);

        // first make sure the display is blank
        billboard.allOff();

        // forever
        for(;;)
        {
            if (isJOptionPaneUsed)
            {

                //get a message from the user
                // Get user input  
                inputString = JOptionPane.showInputDialog("Enter a 5 letter word made up of the letters ‘s’, ‘p’, ‘a’, ‘r’ and ‘e’ ");

            }
            else
            {
                keyboard = new Scanner(System.in);
                System.out.println("\nEnter a 5 letter word made up of the letters ‘s’, ‘p’, ‘a’, ‘r’ and ‘e’ ");
                String input = keyboard.nextLine();

            } 
            
            // first make sure the display is blank
            billboard.allOff();

            //for each letter in the message
            int x = START_X; // keep track of where each letter should go
            int y = START_Y;
            for(int i = 0; i < 5; i++)
            {
                // display the i_th letter              
                switch((inputString).charAt(i))
                {
                    case 's':
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+2);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+2);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+2);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+2);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+3);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+4);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+5);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+5);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+5);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+6);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+7);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+8);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+8);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+8);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+8);
                    break;
                    
                    case 'p':
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP),START_Y+2);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+2);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+2);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+2);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+3);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+4);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+5);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+6);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+7);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+8);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+9);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+10);     
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+11);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+12);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+3);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+4);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+5);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+6);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+7);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+8);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+8);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+8);
                    break;
                    
                    case 'a':
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+2);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+2);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+2);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+3);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+4);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+5);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+6);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+7);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+3);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+4);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+5);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+6);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+7);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+8);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+8);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+8);
            
                    break;

                    case 'r':
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP),START_Y+2);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+2);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+2);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+3);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+4);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+5);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+6);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+7);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+8);
                    billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+3);
                    
                    break;

                    case'e':
                    write_e(billboard, x, y);
                    break;

                    break;


                    default:
                }
                x += LETTER_WIDTH + GAP;
                // display the letter

            }
            // OK - ready to update the display
            billboard.redisplay(0);
        }
        
    }
     
    private static void writeText(BillboardInterface billboard, int x, int y, String text)
    {
    }
    private static void writeLetter(BillboardInterface billboard, int x, int y, char c)
    {
    }
    private static void write_s(BillboardInterface billboard, int x, int y)
    {
    }
    private static void write_p(BillboardInterface billboard, int x, int y)
    {
    }
    private static void write_a(BillboardInterface billboard, int x, int y)
    {
    }
    private static void write_r(BillboardInterface billboard, int x, int y)
    {
    }
    private static void write_e(BillboardInterface billboard , int x, int y)
    {
        
        billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+2);
        billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+2);
        billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+3);
        billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+4);
        billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+5);
        billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+6);
        billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+7);
        billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+5);
        billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+5);
        billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+5);
        billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+4);
        billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+3);
        billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+7);
        billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+8);
        billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+8);
        billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+8); 
    }
}

im figuring there maybe something wrong with line 195 but cant seem to get it.

thank you

Edited 5 Years Ago by Bob1000: n/a

The problem with ur code is that START_X is a local variable to main() method. Hence cannot be access outside main function. Since its final it would be ok to declare it outside main as private variable...

im sorry im quite new to this. but how would i do that? is private variible the var thing ?

okay ive managed to fix that problem. thankyou stevan. however now i have a new problem xD

import java.util.Scanner;
import billboard.BillboardInterface;
import billboard.DigitalBillboardFrame;
import javax.swing.JOptionPane;

/**
 * Partial solution for Stage 2 of the digital billboard
 *
 * @author phi
 * @version 2011 2
 */
public class Methodbilboard
{
    public static void main(String[] args)
    {
        // initial size of the display in pixels
        final int WINDOW_WIDTH = 300;
        final int WINDOW_HEIGHT = 120;
        // size of the grid for the digital billboard
        final int BB_WIDTH = 50;
        final int BB_HEIGHT = 30;

        // create a billboard
        BillboardInterface billboard = new DigitalBillboardFrame(
                "SCSS",
                WINDOW_WIDTH, WINDOW_HEIGHT,
                BB_WIDTH, BB_HEIGHT);

        // we will make letters 5 cells wide and 12 high
        final int LETTER_WIDTH = 5;
        final int LETTER_HEIGHT = 12;
        // and leave a 1 cell gap between letters
        final int GAP = 1;

        // the top left of the first letter in the word will be 2 cells from the left and 1 down
        final int START_X = 10;
        final int START_Y = 8;
      

        final boolean isJOptionPaneUsed = true; //for Scanner (0) or JOptionPane (1);

        String inputString;  // input string recved

        // Create a Scanner object for keyboard input.
        Scanner keyboard = new Scanner(System.in);

        // first make sure the display is blank
        billboard.allOff();

        // forever
        for(;;)
        {
            if (isJOptionPaneUsed)
            {

                //get a message from the user
                // Get user input  
                inputString = JOptionPane.showInputDialog("Enter a 5 letter word made up of the letters ‘s’, ‘p’, ‘a’, ‘r’ and ‘e’ ");

            }
            else
            {
                keyboard = new Scanner(System.in);
                System.out.println("\nEnter a 5 letter word made up of the letters ‘s’, ‘p’, ‘a’, ‘r’ and ‘e’ ");
                String input = keyboard.nextLine();

            } 
            
            // first make sure the display is blank
            billboard.allOff();

            //for each letter in the message
            int x = START_X; // keep track of where each letter should go
            int y = START_Y;
            for(int i = 0; i < 5; i++)
            {
                // display the i_th letter   
                
                writeLetter();
                
                x += LETTER_WIDTH + GAP;
                // display the letter

            }
            // OK - ready to update the display
            billboard.redisplay(0);
        }
        
    }
    private static void writeText(BillboardInterface billboard, int x, int y, String text)
    {
    }
    private static void writeLetter(BillboardInterface billboard, int x, int y, char c)
    {
                switch((inputString).charAt(i))
                {
                    case 's':
                    write_s(billboard, START_X, i, LETTER_WIDTH, GAP, START_Y);
                    break;
                    
                    case 'p':
                    write_p(billboard, START_X, i, LETTER_WIDTH, GAP, START_Y); 
                    break;
                    
                    case 'a':
                    write_a(billboard, START_X, i, LETTER_WIDTH, GAP, START_Y);
                    break;

                    case 'r':
                    write_r(billboard, START_X, i, LETTER_WIDTH, GAP, START_Y);
                    break;

                    case 'e':
                    write_e(billboard, START_X, i, LETTER_WIDTH, GAP, START_Y);
                    break;


                    default:
                }
    }
    private static void write_s(BillboardInterface billboard, int START_X, int i, int LETTER_WIDTH, int GAP, int START_Y)
    {
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+3);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+4);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+6);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+7);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+8);
    }
    private static void write_p(BillboardInterface billboard, int START_X, int i, int LETTER_WIDTH, int GAP, int START_Y)
    {
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP),START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+3);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+4);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+6);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+7);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+9);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+10);     
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+11);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+12);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+3);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+4);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+6);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+7);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+8);
    }
    private static void write_a(BillboardInterface billboard, int START_X, int i, int LETTER_WIDTH, int GAP, int START_Y)
    {
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+3);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+4);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+6);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+7);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+3);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+4);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+6);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+7);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+8);
        
    }
    private static void write_r(BillboardInterface billboard, int START_X, int i, int LETTER_WIDTH, int GAP, int START_Y)
    {
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP),START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+3);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+4);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+6);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+7);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+3);
    }
    private static void write_e(BillboardInterface billboard, int START_X, int i, int LETTER_WIDTH, int GAP, int START_Y)
    {
           
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1,START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+3);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+4);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+6);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+7);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+4);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+3);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+7);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+8);   
            
            
        
    }
}

am i putting the call in the wrong position (line 79) or are my variables wrong again ?

Edited 5 Years Ago by Bob1000: n/a

Dude first of all u haven't fixed the START_X variable problem.
I meant, instead of declaring the

final int START_X = 10;
final int START_Y = 8;

inside main method, declare it outside the main Method

class className
{
  final int START_X = 10;
  final int START_Y = 8;
  
  public static void main(String a[])
  {
  }
  .
  .
  .
}

Second of all are you calling the writeLetter with proper arguments?

BTW, can u provide the entire project code. looks interesting... would love to see it..!

Edited 5 Years Ago by stevanity: n/a

ill try attaching the project since not sure how i can post the whole thing. let me know if it works =]

i tried putting the variable outside the main method. but then i get antoher error. saying non static variable START_X cannot be found.

Edited 5 Years Ago by Bob1000: n/a

okay i made most my variables static and also attempted the writeLetter and writeText part. but now i have a new problem. the program compiles however when i try spell a word i get a error saying java.lang.NullPointerException:null. im guessing there is something wrong with my

private static void writeLetter(BillboardInterface billboard, int x, int y)

but cant seem to put my finger on it. please help xD

btw did you run the program Stevan?

almost forgot the code xD

import java.util.Scanner;
import billboard.BillboardInterface;
import billboard.DigitalBillboardFrame;
import javax.swing.JOptionPane;

/**
 * Partial solution for Stage 2 of the digital billboard
 *
 * @author phi
 * @version 2011 2
 */
public class Methodbilboard
{
        private static final int LETTER_WIDTH = 5;
        private static  final int LETTER_HEIGHT = 12;
        private static  final int GAP = 1;
        private static int isJOptionPaneUsed;
        static Scanner keyboard = new Scanner(System.in);
        private static final int START_X = 10;
        private static final int START_Y = 8;
        private static String inputString;     
    public static void main(String[] args)
    {
        // initial size of the display in pixels
        final int WINDOW_WIDTH = 300;
        final int WINDOW_HEIGHT = 120;
        // size of the grid for the digital billboard
        final int BB_WIDTH = 50;
        final int BB_HEIGHT = 30;

        // create a billboard
        BillboardInterface billboard = new DigitalBillboardFrame(
                "SCSS",
                WINDOW_WIDTH, WINDOW_HEIGHT,
                BB_WIDTH, BB_HEIGHT);

      
        final boolean isJOptionPaneUsed = true; //for Scanner (0) or JOptionPane (1);
        
        billboard.allOff();
        
        writeText(billboard, inputString, isJOptionPaneUsed);

        // forever
        
        
    }
    private static void writeText(BillboardInterface billboard, String inputString, boolean isJOptionPaneUsed)
    {
        for(;;)
        {
            if (isJOptionPaneUsed)
            {

                //get a message from the user
                // Get user input  
                inputString = JOptionPane.showInputDialog("Enter a 5 letter word made up of the letters ‘s’, ‘p’, ‘a’, ‘r’ and ‘e’ ");

            }
            else
            {
                keyboard = new Scanner(System.in);
                System.out.println("\nEnter a 5 letter word made up of the letters ‘s’, ‘p’, ‘a’, ‘r’ and ‘e’ ");
                String input = keyboard.nextLine();

            } 
            
            // first make sure the display is blank
            billboard.allOff();

            //for each letter in the message
            int x = START_X; // keep track of where each letter should go
            int y = START_Y;
            
            writeLetter(billboard, x, y);
            // OK - ready to update the display
            billboard.redisplay(0);
        }
        
    }
    private static void writeLetter(BillboardInterface billboard, int x, int y)
    {
       for(int i = 0; i < 5; i++)
       {
                // display the i_th letter   
            switch((inputString).charAt(i))
            {
                case 's':
                write_s(billboard, START_X, i, LETTER_WIDTH, GAP, START_Y);
                break;
                
                case 'p':
                write_p(billboard, START_X, i, LETTER_WIDTH, GAP, START_Y); 
                break;
                
                case 'a':
                write_a(billboard, START_X, i, LETTER_WIDTH, GAP, START_Y);
                break;
    
                case 'r':
                write_r(billboard, START_X, i, LETTER_WIDTH, GAP, START_Y);
                break;
    
                case 'e':
                write_e(billboard, START_X, i, LETTER_WIDTH, GAP, START_Y);
                break;
    
    
                default:
            }         
            writeLetter(billboard, x, y);
            
            x += LETTER_WIDTH + GAP;
            // display the letter

       } 
    }
    private static void write_s(BillboardInterface billboard, int START_X, int i, int LETTER_WIDTH, int GAP, int START_Y)
    {
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+3);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+4);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+6);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+7);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+8);
    }
    private static void write_p(BillboardInterface billboard, int START_X, int i, int LETTER_WIDTH, int GAP, int START_Y)
    {
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP),START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+3);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+4);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+6);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+7);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+9);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+10);     
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+11);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+12);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+3);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+4);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+6);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+7);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+8);
    }
    private static void write_a(BillboardInterface billboard, int START_X, int i, int LETTER_WIDTH, int GAP, int START_Y)
    {
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+3);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+4);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+6);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+7);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+3);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+4);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+6);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+7);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+8);
        
    }
    private static void write_r(BillboardInterface billboard, int START_X, int i, int LETTER_WIDTH, int GAP, int START_Y)
    {
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP),START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+3);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+4);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+6);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+7);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+3);
    }
    private static void write_e(BillboardInterface billboard, int START_X, int i, int LETTER_WIDTH, int GAP, int START_Y)
    {
           
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1,START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+2);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+3);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+4);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+6);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP), START_Y+7);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+5);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+4);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+3);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+4, START_Y+7);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+3, START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+2, START_Y+8);
            billboard.turnOn(START_X+i*(LETTER_WIDTH+GAP)+1, START_Y+8);   
            
            
        
    }
}

The reason for the NullPointerException is simple. You are not accessing the actual "static" inputString Variable inside writeText. Hence the static inputString remains with a null reference even if you assign a value to a inputString value which is not that object. You have already declared inputString outside all functions. So dont call writeTest with the inputString variable. Omit that argument and that problem will be resolved.

change call to

writeText(billboard,isJOptionPaneUsed);

And header of writeText to

private static void writeText(BillboardInterface billboard,  boolean isJOptionPaneUsed)

I ran ur code. But there is some another problem with ur code. Do more testing....

This question has already been answered. Start a new discussion instead.