Новичок
Профиль
Группа: Участник
Сообщений: 14
Регистрация: 20.4.2007
Где: г.Хабаровкс
Репутация: 1 Всего: 1
|
Код программы: | Код | /* * CrMo.java * * Created on 17 Апрель 2007 г., 22:43 */ import javax.microedition.lcdui.*; import javax.microedition.midlet.*; import javax.microedition.io.*; import javax.microedition.media.*; import java.io.*; import java.util.*; import com.nokia.mid.ui.FullCanvas;
/** * An example MIDlet with simple "Hello" text and an Exit command. * Refer to the startApp, pauseApp, and destroyApp * methods so see how each handles the requested transition. * * @author (C@8: * @version */ public class CrMo extends MIDlet { private Command exitCommand; // The exit command private Display display; // The display for this MIDlet public static String error;
mendraw m = new mendraw(); //Создание подкласса mendraw zastavka z = new zastavka(); //создание заставки
Thread thread; Thread thread_1;// Переменная типа процес Image image,image1; // Переменная типа картинка int index = 0,h,w; public void startApp() { display = Display.getDisplay(this); display.setCurrent(z); // Сразу после загрузки мидлета переходит на класс mendraw } //////////////////////////////////////////////////////////////////////////////// // Заставка ==================================================================== class zastavka extends FullCanvas implements Runnable { int i1=255,i2=0,i3=0,index_color=1; public void paint(Graphics g) { if (index==0) { Start_run(); setImage(g,"/start.png",0,0); index=1; } if (error != null) { g.setColor(0x00FFFF); //любой цвет g.drawString(error, 40, 95, Graphics.HCENTER | Graphics.TOP);} g.setColor(i1, i2, i3); g.drawString("Please press a key",88,190,Graphics.HCENTER | Graphics.TOP); } public void Start_run() { thread=null; thread = new Thread(this); so thread_1 = new so(); thread.setPriority(Thread.MIN_PRIORITY); thread_1.start(); thread.start(); repaint(); } public void run() { while (index!=4){ if (index_color==1) { if (i2!=255){ i2++;} else {index_color=2;} } if (index_color==2) { if (i1!=0){ i1--;} else {index_color=3;} } if (index_color==3) { if (i3!=255){ i3++;} else {index_color=4;} } if (index_color==4) { if (i2!=0){ i2--;} else {index_color=5;} } if (index_color==5) { if (i1!=255){ i1++;} else {index_color=6;} } if (index_color==6) { if (i3!=0){ i3--;} else {index_color=1;} } repaint(); try{ thread.sleep(0);} catch (InterruptedException e){error = e.toString();} } } public void keyPressed(int KeyCode) { index=1; thread=null; thread_1=null; display.setCurrent(m); } } //////////////////////////////////////////////////////////////////////////////// // Меню ======================================================================== class mendraw extends FullCanvas implements PlayerListener { public void paint(Graphics g) { h = getHeight(); w = getWidth(); setImage(g,"/menu.png",0,0); //setImage(g,"/menu_rus.png",55+5,35+5); g.setColor(0, 0, 0); //Задаем цвет прямоугольников меню g.drawRoundRect(40, 70 ,96,15,10,10); g.drawRoundRect(40,70+25,96,15,10,10); g.drawRoundRect(40,70+50,96,15,10,10); g.drawRoundRect(40,70+75,96,15,10,10); g.drawRoundRect(40,70+100,96,15,10,10); g.setColor(128, 64, 0); g.drawString("Игра", 88, 71, g.TOP | g.HCENTER); // Рисуем первую строку меню g.drawString("Настроики", 88, 71+25, g.TOP | g.HCENTER); // Рисуем второю строку меню g.drawString("Справка", 88, 71+50, g.TOP | g.HCENTER); // Рисуем четвертую строку меню g.drawString("О программе", 88+1, 71+75, g.TOP | g.HCENTER); // Рисуем пятую строку меню g.drawString("Выход", 88, 71+100, g.TOP | g.HCENTER); // Рисуем шестую строку меню if (index == 1) { // Если индекс равен 1 g.setColor(128, 64, 0); g.fillRoundRect(40,70,96,15,10,10); //Заливаем прямоугольник №1 g.setColor(255, 255, 0); g.drawString("Игра", 88, 71, g.TOP | g.HCENTER); // Рисуем первую строку меню } if (index == 2) { // Если индекс равен 2 g.setColor(128, 64, 0); g.fillRoundRect(40,70+25,96,15,10,10); //Заливаем прямоугольник№2 g.setColor(255, 255, 0); g.drawString("Настроики", 88, 71+25, g.TOP | g.HCENTER); // Рисуем второю строку меню } if (index == 3) { // Если индекс равен 3 g.setColor(128, 64, 0); g.fillRoundRect(40,70+50,96,15,10,10); //Заливаем прямоугольник №4 g.setColor(255, 255, 0); g.drawString("Справка", 88, 71+50, g.TOP | g.HCENTER); // Рисуем четвертую строку меню } if (index == 4) { // Если индекс равен 4 g.setColor(128, 64, 0); g.fillRoundRect(40,70+75,96,15,10,10); //Заливаем прямоугольник №5 g.setColor(255, 255, 0); g.drawString("О программе", 88+1, 71+75, g.TOP | g.HCENTER); // Рисуем пятую строку меню } if (index == 5) { // Если индекс равен 5 g.setColor(128, 64, 0); g.fillRoundRect(40,70+100,96,15,10,10); //Заливаем прямоугольник №6 g.setColor(255, 255, 0); g.drawString("Выход", 88, 71+100, g.TOP | g.HCENTER); // Рисуем шестую строку меню } } public void keyPressed(int KeyCode) { int press = KeyCode; //Заносим в переменную код нажатой кнопки if (press == -5) { //Усли нажата кнопка OK if (index == 1){ index=0; display.setCurrent(g); } if (index == 2){ } if (index == 3){ // display.setCurrent(h); } if (index == 4){ // display.setCurrent(a); } if (index == 5){ destroyApp(true); notifyDestroyed(); } } if (press == -2) { //Усли нажата кнопка DOWN if (index > 4) { index = 1; } else { index++; // Перемещаем прямоугольники вниз } repaint(); //Прорисовываем изменения } if (press == -1) { //Усли нажата кнопка UP if (index < 2) { index = 5; } else { index--; // Перемещаем прямоугольники вверх } repaint(); //Прорисовываем изменения } } public void playerUpdate(javax.microedition.media.Player player, String str, Object obj) { } } ////////////////////////////////////////////////////////////////////////////////
public void pauseApp() {} public void destroyApp(boolean unconditional) {} public void commandAction(Command c, Displayable s) { if (c == exitCommand) { destroyApp(false); notifyDestroyed(); } } //////////////////////////////////////////////////////////////////////////////// private class so extends Thread { public void run(){ error="поток Запущен"; ru(); } public void ru(){ try { InputStream is = getClass().getResourceAsStream("intro.wav"); Player p = Manager.createPlayer(is, "audio/x-wav"); error="Плэир создан"; p.prefetch(); error="p.prefetch(); создан"; p.setLoopCount(10); error="p.setLoopCount(10); создан"; p.start(); error="p.start; создан"; try { thread.sleep(100);} catch (InterruptedException e){error = e.toString();} }catch (IOException ex) {error = ex.toString();} catch (MediaException ex) {error = ex.toString();} }} //////////////////////////////////////////////////////////////////////////////// // Вставка картинки=============================================================
public void setImage(Graphics g,String path,int x1,int y1){ try{ image = Image.createImage(path); } catch (IOException ioe) {System.out.println("bed :( "+ioe.getMessage()); } g.drawImage(image,x1,y1,Graphics.LEFT | Graphics.TOP); } ////////////////////////////////////////////////////////////////////////////////
}
|
Не могу понять на эмуляторе правильно работает а на телефоне тупит  . Когда пытался отловить ошибку он вроде бы правильно работает потоки запускаются, а музыка не играет.
|