Hey guys basically I'm studying programming using the 'BlueJ' Java program on windows. I'm trying to create a 'Dynamic Billboard' program that asks a user to enter a 5 letter word than the characters are displayed on a billboard, the program uses a text file imported for the charcters).
Ive almost completed it but im having 1 diffuculty with calling on a method here is my codding
i need to insert this writeLetter(billboard, x, y, code); somewhere and im 100% certain that code wont work if i put it somewhere any advice?
where should i put writeLetter(billboard, x, y, code); and what should i change the variable "code" too?
import java.util.Scanner; //needed for Scanner
import billboard.BillboardInterface;
import billboard.DigitalBillboardFrame;
import java.io.File;
import java.io.FileNotFoundException;
public class FilesBillboard
{
// initial size of the display in pixels
static final int WINDOW_WIDTH = 300;
static final int WINDOW_HEIGHT = 120;
// size of the grid for the digital billboard
static final int BB_WIDTH = 50;
static final int BB_HEIGHT = 30;
// we will make letters 5 cells wide and 12 high
static final int LETTER_WIDTH = 8;
static final int LETTER_HEIGHT = 12;
// and leave a 1 cell gap between letters
static final int GAP = 0;
//number of characters in file
static final int NUM_LETTERS = 95;
//name for the textfile
static final String LETTER_PATH = "letters.txt";
// the top left of the first letter in the word will be 2 cells from the left and 1 down
static final int START_X = 2;
static final int START_Y = 1;
private static final int[][] _s =
{
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 1, 1, 1, 1},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 0},
{0, 1, 1, 1, 0},
{0, 0, 0, 0, 1},
{0, 0, 0, 0, 1},
{1, 1, 1, 1, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0}
};
private static final int[][] _p =
{
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{1, 1, 1, 1, 0},
{1, 0, 0, 0, 1},
{1, 0, 0, 0, 1},
{1, 0, 0, 0, 1},
{1, 0, 0, 0, 1},
{1, 0, 0, 0, 1},
{1, 1, 1, 1, 0},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 0}
};
private static final int[][] _a =
{
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 1, 1, 1, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
{0, 1, 1, 0, 1},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0}
};
private static final int[][] _r =
{
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{1, 0, 1, 1, 0},
{0, 1, 0, 0, 1},
{0, 1, 0, 0, 0},
{0, 1, 0, 0, 0},
{0, 1, 0, 0, 0},
{0, 1, 0, 0, 0},
{0, 1, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0}
};
private static final int[][] _e =
{
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 1, 1, 1, 0},
{1, 0, 0, 0, 1},
{1, 0, 0, 0, 1},
{1, 1, 1, 1, 0},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 1},
{0, 1, 1, 1, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0}
};
public static void main(String[] args)
{
//Call on readletters
try
{
readLetters(); //method that throws exception
}
catch (FileNotFoundException fnfe)
{
//print error message
return; //leave
}
// create a billboard
BillboardInterface billboard = new DigitalBillboardFrame(
"SCSS",
WINDOW_WIDTH, WINDOW_HEIGHT,
BB_WIDTH, BB_HEIGHT);
// first make sure the display is blank
billboard.allOff();
//forever
for(;;)
{
//get a message from the user
String word;
Scanner userInput = new Scanner (System.in); //Create Scanner Object
System.out.print("Enter a 5 letter word using the letters s, p, a, r, e! \n>>> ");
word = userInput.nextLine();
billboard.allOff();
//for each letter in the message
//for each letter in the message
int x = START_X; //keep track of where each letter should go
int y = START_Y;
//display the letter
writeText(billboard, x, y, word);
}
}
private static void writeLetter(BillboardInterface billboard, int x, int y, char c) // Displaying appropriate letters
{
int code =(int)(c - ' ');
writeLetter(billboard, x, y, code); //THIS PART
}
private static void writeText(BillboardInterface billboard, int x, int y, String text) // Getting word from user
{
int length = text.length(); // Defining length
for(int i = 0; i < 5 && i < length; i++)
{
//display the i_th letter
char charAt = text.charAt(i);
x += LETTER_WIDTH + GAP;
writeLetter(billboard, x, y, charAt); //calling on writeletter
billboard.redisplay(0);
}
}
private static void writeArray(BillboardInterface billboard, int x, int y, int[][] pixels) //method for array
{
for(int row = 0; row < pixels.length; row++)
{
for(int col = 0; col < pixels[row].length; col ++)
{
if (pixels[row][col] == 1) //checking if the pixel is a 1
{
billboard.turnOn(x+col, y+row); //using a turnOn to turn on the grid at a specific pixel
}
}
}
}
//declare a static field for the 3 dimensional array
private static int [][][] letters;
//read from file and display in array
private static void readLetters() throws FileNotFoundException
{
//created the letters array
letters = new int [NUM_LETTERS][LETTER_HEIGHT][LETTER_WIDTH];
//Using scanner object to open file
File letterFile = new File(LETTER_PATH);
Scanner input = new Scanner(letterFile);
//Nested Loops to read data from file
for (int i = 0; i < NUM_LETTERS; ++i){
for (int j = 0; j < LETTER_HEIGHT; ++j){
for (int k = 0; k < LETTER_WIDTH; ++k) {
letters[i][j][k] = input.nextInt();
}
}
}
}
}