import javax.microedition.lcdui.*; import javax.microedition.media.*; import java.io.*; public class MyCanvas extends Canvas{ private Player sample[]; //массив плееров с семплами(в каждом плеере один семпл) private Image imageSampler; //картинка семплера private InputStream inputStream; //поток для загрузки семплов из jar-архива public MyCanvas(){ super(); setFullScreenMode(true); try{ imageSampler=Image.createImage("/1.png"); sample=new Player[9]; //создание плееров с семплами inputStream=getClass().getResourceAsStream("/1.amr"); sample[0]=Manager.createPlayer(inputStream,"audio/amr"); sample[0].realize(); sample[0].prefetch(); inputStream.close(); inputStream=getClass().getResourceAsStream("/2.amr"); sample[1]=Manager.createPlayer(inputStream,"audio/amr"); sample[1].realize(); sample[1].prefetch(); inputStream.close(); inputStream=getClass().getResourceAsStream("/3.amr"); sample[2]=Manager.createPlayer(inputStream,"audio/amr"); sample[2].realize(); sample[2].prefetch(); inputStream.close(); inputStream=getClass().getResourceAsStream("/4.amr"); sample[3]=Manager.createPlayer(inputStream,"audio/amr"); sample[3].realize(); sample[3].prefetch(); inputStream.close(); inputStream=getClass().getResourceAsStream("/5.amr"); sample[4]=Manager.createPlayer(inputStream,"audio/amr"); sample[4].realize(); sample[4].prefetch(); inputStream.close(); inputStream=getClass().getResourceAsStream("/6.amr"); sample[5]=Manager.createPlayer(inputStream,"audio/amr"); sample[5].realize(); sample[5].prefetch(); inputStream.close(); inputStream=getClass().getResourceAsStream("/7.amr"); sample[6]=Manager.createPlayer(inputStream,"audio/amr"); sample[6].realize(); sample[6].prefetch(); inputStream.close(); inputStream=getClass().getResourceAsStream("/8.amr"); sample[7]=Manager.createPlayer(inputStream,"audio/amr"); sample[7].realize(); sample[7].prefetch(); inputStream.close(); inputStream=getClass().getResourceAsStream("/9.amr"); sample[8]=Manager.createPlayer(inputStream,"audio/amr"); sample[8].realize(); sample[8].prefetch(); inputStream.close(); }catch(Exception e){} } public void paint(Graphics g){ g.drawImage(imageSampler,0,0,20); repaint(); } public void keyPressed(int keyCode){ try{ if (keyCode==KEY_NUM1) sample[0].start(); else if (keyCode==KEY_NUM2) sample[1].start(); else if (keyCode==KEY_NUM3) sample[2].start(); else if (keyCode==KEY_NUM4) sample[3].start(); else if (keyCode==KEY_NUM5) sample[4].start(); else if (keyCode==KEY_NUM6) sample[5].start(); else if (keyCode==KEY_NUM7) sample[6].start(); else if (keyCode==KEY_NUM8) sample[7].start(); else if (keyCode==KEY_NUM9) sample[8].start(); }catch(Exception e){} } }