Java: prevent beep sound on key press -
i have java program launched browser, running various java.awt.button buttons. when clicked, it's fine. when key pressed corresponds button, windows makes "default beep" sound.
the buttons created this:
import java.awt.gridlayout; import java.awt.borderlayout; import java.io.*; import java.awt.panel; import java.awt.button; import java.awt.font; import java.awt.event.*; import java.lang.integer; public class buttonpne extends panel implements actionlistener, constants { private pclient parent = null; private labelpne buttonlabel[] = new labelpne[8]; private panel buttonpanel[] = new panel[8]; public button thebuttons[] = new button[8]; private boolean buttonstatus[] = new boolean[8]; public buttonpne(pclient c) { parent = c; this.setlayout(new gridlayout(1, 8, 1, 0)); (int = 0; < 8; i++) { buttonlabel[i] = new labelpne(parent); buttonlabel[i].setsize(9, 9); thebuttons[i] = new button(); thebuttons[i].setfont(buttonfont); thebuttons[i].setactioncommand(integer.tostring(i)); thebuttons[i].addactionlistener(this); thebuttons[i].addkeylistener(parent); buttonpanel[i] = new panel(); buttonpanel[i].setbackground(backgroundcolor); buttonpanel[i].setlayout(new borderlayout()); buttonpanel[i].add("north", thebuttons[i]); buttonpanel[i].add("south", buttonlabel[i]); this.add(buttonpanel[i]); } deactivate(); }
the key presses handled this:
import java.awt.event.keyevent;
...
public class pclient extends applet implements keylistener, constants {
...
f.addkeylistener(this);
...
public void keypressed(keyevent evt) { int thekey; thekey = evt.getkeycode(); switch(thekey) { case keyevent.vk_1: case keyevent.vk_f1: buttons.dobutton(0); break;
...
public void dobutton(int thenumber) { if (buttonstatus[thenumber]) { if (parent.pollsendflag(buttons)) { parent.chat.takefocus(); parent.compass.deactivate(); deactivate(); } } return; }
how can stop default beep happening on key presses?
use swing components instead of awt components.
Comments
Post a Comment