The WaveIn device should be always "recording". Every buffer, you examine to decide if it contains sound or not. You'll need to write this algorithm yourself. Usually you are looking for samples that go above a certain threshold.
If there is sound, open a WaveFileWriter and start writing into it, until you decide a buffer is silent and you should stop.
If there is sound, open a WaveFileWriter and start writing into it, until you decide a buffer is silent and you should stop.