Serial Communication PC - Arduino "Examples > > Dimmer"

This simple tutorial from the Arduino Webside “Examples > Communication > Dimmer” doesn’t work.
There is a connection between PC and Arduino but there is no change in the brightness if I move the mouse.

const int ledPin = 9;
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
byte brightness;

if (Serial.available()) {
brightness = Serial.read();
analogWrite(ledPin, brightness);
}
}

Processing code for this example

// Dimmer - sends bytes over a serial port
// by David A. Mellis

import processing.serial.*;
Serial port;

void setup() {
size(256, 150);

println(“Available serial ports:”);
println(Serial.list());

port = new Serial(this, Serial.list()[0], 9600);
}
void draw() {
for (int i = 0; i < 256; i++) {
stroke(i);
line(i, 0, i, 150);
}
port.write(mouseX);
}

What can I do?

With a “delay” it work, but of course with a delay. Has anybody an idea?

void draw() {
// draw a gradient from black to white
for (int i = 0; i < 256; i++) {
stroke(i);
line(i, 0, i, 150);
}
port.write(mouseX);
delay(800);
}