Java message sender brakes the rest of program
<p>Ok, so as the title said i got this small tool that helps me and i wanted to add "sort of message spammer" but when it starts i can't stop it.</p>

<p>Here's the code:</p>

<pre><code>SpamScriptToggleButton.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent ev) {
            if (ev.getStateChange()==ItemEvent.SELECTED) {
                i = 3;
            } else if(ev.getStateChange()==ItemEvent.DESELECTED){
                i = 1;
            }
        while(i &gt; 2) {
            robot.delay(40);
            type("Message "+i+" !");
            i++;
            }
        }
    });
</code></pre>

<p>My question is how i can make it stop, clicking the ToggleButton doesn't help, and please keep in mind that i need to count those messages.</p>

<p>Thanks,
Christian</p>