JAVA在运行调试时占用内存太大,怎么解决?
就是按一些键来播放不同的声音,但是按几个键之后就会卡。publicvoidkeyPressed(KeyEvente){intnKeycode=e.getKeyCode()...
就是按一些键来播放不同的声音,但是按几个键之后就会卡。
public void keyPressed(KeyEvent e) {
int nKeycode=e.getKeyCode( );
if ( nKeycode==KeyEvent.VK_1)
{
try {
AudioClip p = Applet.newAudioClip(new URL("file:sound/1.wav"));
p.play();
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
}
if ( nKeycode==KeyEvent.VK_2)
{
try {
AudioClip p = Applet.newAudioClip(new URL("file:sound/2.wav"));
p.play();
} catch (MalformedURLException e2) {
e2.printStackTrace();
}
}
if ( nKeycode==KeyEvent.VK_3)
{
try {
AudioClip p = Applet.newAudioClip(new URL("file:sound/3.wav"));
p.play();
} catch (MalformedURLException e3) {
e3.printStackTrace();
}
}
if ( nKeycode==KeyEvent.VK_4)
{
try {
AudioClip p = Applet.newAudioClip(new URL("file:sound/4.wav"));
p.play();
} catch (MalformedURLException e4) {
e4.printStackTrace();
}
}
repaint( );
}
public void keyReleased(KeyEvent e) { }
public void keyTyped(KeyEvent e) { }
} //end of KeyHandleExamples1 class
public class dddd {
public static void main(String[] args){
new KeyHandleExamples1();
}
} 展开
public void keyPressed(KeyEvent e) {
int nKeycode=e.getKeyCode( );
if ( nKeycode==KeyEvent.VK_1)
{
try {
AudioClip p = Applet.newAudioClip(new URL("file:sound/1.wav"));
p.play();
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
}
if ( nKeycode==KeyEvent.VK_2)
{
try {
AudioClip p = Applet.newAudioClip(new URL("file:sound/2.wav"));
p.play();
} catch (MalformedURLException e2) {
e2.printStackTrace();
}
}
if ( nKeycode==KeyEvent.VK_3)
{
try {
AudioClip p = Applet.newAudioClip(new URL("file:sound/3.wav"));
p.play();
} catch (MalformedURLException e3) {
e3.printStackTrace();
}
}
if ( nKeycode==KeyEvent.VK_4)
{
try {
AudioClip p = Applet.newAudioClip(new URL("file:sound/4.wav"));
p.play();
} catch (MalformedURLException e4) {
e4.printStackTrace();
}
}
repaint( );
}
public void keyReleased(KeyEvent e) { }
public void keyTyped(KeyEvent e) { }
} //end of KeyHandleExamples1 class
public class dddd {
public static void main(String[] args){
new KeyHandleExamples1();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询