This (not my photo; thanks, Flickr!) is what appeared on the TV screen several seconds before the earthquake arrived in Noshiro this morning. Note that the blue overlay is not part of the newscast, but pops up over whatever show is currently on. This particular warning is from an aftershock about half an hour after the main quake, so at this point everybody was already watching the news.
Seismic sensors are placed all over the country, and immediately upon the occurrence of the first shock, the epicenter is calculated and warnings go up on TV stations immediately. Since the shock waves take time to spread from the epicenter through the ground, the warning will hit the TV before the quake arrives in most places. Impressive stuff.