It might be that the Processing program starts transmitting too soon and so the bootloader on the Mega 2560 never times out (and starts the Dimmer sketch). Try adding a delay() to the end of the setup() function in the Processing program. Or check, in the Processing program, that millis() > 5000 (or so) in order to send data over the serial port.