Slide me into the gist

Hello people,i'm trying to get arduino to work in conjunction with processing but i'm not getting the wright results.I just wont to read a digital output from arduino into processing and color up my high or low input.The code i'm using is:
arduino code
void setup() {
// initialize serial:
Serial.begin(9600);
pinMode(2, INPUT);
}
void loop() {
int a = digitalRead(2);
Serial.println(a); //send value to serial
}

processing code
import processing.serial.*;

Serial myPort; // Create object from Serial class
int val; // Data received from the serial port

void setup()
{
size(200, 200);
// Open whatever port is the one you're using.
String portName = Serial.list()[1]; My arduino is working on com4 and is listed 2nd in line after com3
myPort = new Serial(this, portName, 9600);
}

void draw()
{
if ( myPort.available() > 0) { // If data is available,
val = myPort.read(); // read it and store it in val
}
background(255); // Set background to white
if (val == 0) { // If the serial value is 0,
fill(0); // set fill to black
}
else { // If the serial value is not 0,
fill(204); // set fill to light gray
}
rect(50, 50, 100, 100);
}

All i get is either a grey box or a black one but no change appears when i change the value of my input.First i load arduino and upload the scetch.Then i run the processing code

 int a = digitalRead(2);
Serial.println(a); //send value to serial

Sends the HIGH or LOW value as a string.

  if ( myPort.available() > 0) {  // If data is available,
    val = myPort.read();         // read it and store it in val
  }
  background(255);             // Set background to white
  if (val == 0) {              // If the serial value is 0,
    fill(0);                   // set fill to black
  }
  else {                       // If the serial value is not 0,
    fill(204);                 // set fill to light gray
  }

Expects a binary input, which was NOT what was received. Try

if(val == '0')

Thanks alot Pauls it works with the ' '.I also had to make 2 changes in the arduino code: the program only worked fine after changing the serial.println(a) to serial.print(a) and adding a delay(1000) at the end.Could someone explain why?

Seril.println sends a value and a carriage return, Serial.print sends just a value.

The delay gives some time between characters sent - allows some time for the program in Processing to do something with what was sent. otherwise the serial port is being sent a value just as fast as the arduino can send them

To be precise, Serial.println() sends a carriage return AND a line feed after the value.