Модераторы: javastic, AntonSaburov
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Прокрутка меню, С использованием List 
:(
    Опции темы
Zamuta
Дата 21.3.2006, 23:59 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 389
Регистрация: 18.1.2006

Репутация: нет
Всего: 6



Код

package hello;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;



public class Kernel extends MIDlet {
    protected Display display;
    private Image splashLogo;
    private boolean isSplash = true;
    private MainMenuScreen mainMenuScreen;
    private SettingsScreen settingsScreen;
    private HighScoreScreen highScoreScreen;
    private HelpScreen helpScreen;
    private AboutScreen aboutScreen;    
    public Kernel() {
   
        }
    public void startApp() {
        display = Display.getDisplay(this);
        mainMenuScreen = new MainMenuScreen(this);
        settingsScreen = new SettingsScreen(this);
        highScoreScreen = new HighScoreScreen(this);
        helpScreen = new HelpScreen(this);
        aboutScreen = new AboutScreen(this);
        if(isSplash) {
            isSplash = false;
            try {
                splashLogo = Image.createImage("/splash.png");
                new SplashScreen(display, mainMenuScreen, splashLogo,3000);
                } catch(Exception ex) {
                    mainMenuScreenShow();
                    }
            } else {
            mainMenuScreenShow();
            }
        }
    public Display getDisplay() {
        return display;
        }
    public void pauseApp() {
        }
    public void destroyApp(boolean unconditional) {
        System.gc();
        notifyDestroyed();
        }
    private Image createImage(String filename) {
        Image image = null;
        try {
            image = Image.createImage(filename);
            } catch (Exception e) {
                }return image;
                }
    public void mainMenuScreenShow() {
        display.setCurrent(mainMenuScreen);
        }
    public void settingsScreenShow() {
        display.setCurrent(settingsScreen);
        }
    public void highScoreScreenShow() {
        display.setCurrent(highScoreScreen);
        }
    public void helpScreenShow() {
        display.setCurrent(helpScreen);
        }
    public void aboutScreenShow() {
        display.setCurrent(aboutScreen);
        }
    public void mainMenuScreenQuit() {
        destroyApp(true);
        }
    }




Код

package hello;


import javax.microedition.lcdui.*;



public class MainMenuScreen extends List implements CommandListener {
  
    private Kernel midlet;
    private Command selectCommand = new Command("Select", Command.ITEM,1);
    private Command exitCommand = new Command("Exit", Command.EXIT,1);
    private Alert alert;
    public MainMenuScreen(Kernel midlet) {
       
        super("Name List",Choice.IMPLICIT);
        this.midlet = midlet;


      

    
        append(Locale.get( "menu.StartGame"),null);
        
        append(Locale.get( "menu.LoadGame"),null);
      
        append(Locale.get( "menu.Highscore"), null);
   
        append(Locale.get( "menu.Quit"),null);
       
        append(Locale.get( "menu.Help"),null);
        addCommand(exitCommand);
        addCommand(selectCommand);
        setCommandListener(this);
        }
    public void commandAction(Command c, Displayable d) {
        if (c == exitCommand) {
            midlet.mainMenuScreenQuit();
            } else if (c == selectCommand) {
            processMenu();
            } else {
            processMenu();
            }
        }
    
    private void processMenu() {
        try {
               List down = (List)midlet.display.getCurrent();
            switch (down.getSelectedIndex()) {
                case 0: scnNewGame(); break;
                case 1: scnSettings(); break;
                case 2: scnHighScore(); break;
                case 3: scnHelp(); break;
                case 4: scnAbout(); break;
                };
                } catch (Exception ex) {
                    // Proper Error Handling should be done here
                    System.out.println("processMenu::"+ex);
                    }
        }
    private void scnNewGame() {
        midlet.mainMenuScreenShow();
        }
    private void scnSettings() {
        midlet.settingsScreenShow();
        }
    private void scnHighScore() {
        midlet.highScoreScreenShow();
        }
    private void scnHelp() {
        midlet.helpScreenShow();
        }
    private void scnAbout() {
        midlet.aboutScreenShow();
        }
    }




Во вемя работы на телефоне (проверял на SE K700), создаётся впечатление что строчка перепрыгивает на следующий пункт меню автоматически, при однократном движении джойстика, т. е. нужна небольшая задержка. Кто знает как сделать?


--------------------
Thank you opensource.
PM MAIL ICQ   Вверх
javastic
Дата 22.3.2006, 11:33 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Эксперт
***


Профиль
Группа: Комодератор
Сообщений: 1214
Регистрация: 18.3.2005
Где: St.Petersburg

Репутация: 19
Всего: 27



Никак. List работает с той задержкой которая в нём определена.


--------------------
01101010 01100001 01110110 01100001 01110011 01110100 01101001 01100011
scjp, mcp 
PM MAIL WWW ICQ   Вверх
DEMOVERSION
Дата 22.3.2006, 12:47 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


Профиль
Группа: Участник
Сообщений: 105
Регистрация: 18.10.2005

Репутация: нет
Всего: 1



а Thread.sleep() попробовать?
PM MAIL   Вверх
Zamuta
Дата 26.3.2006, 05:30 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 389
Регистрация: 18.1.2006

Репутация: нет
Всего: 6



Не буду создавать новую тему, спрошу здесь...


public static Image createImage(String name) - что такое здесь name.
throws IOException

В доках пишут:

Creates an immutable image from decoded image data obtained from the named resource. The name parameter is a resource name as defined by Class.getResourceAsStream(name). The rules for resolving resource names are defined in the Application Resource Files section of the java.lang package documentation.

Что такое имя ресурсов?


--------------------
Thank you opensource.
PM MAIL ICQ   Вверх
batigoal
Дата 26.3.2006, 10:25 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Нелетучий Мыш
****


Профиль
Группа: Участник Клуба
Сообщений: 6423
Регистрация: 28.12.2004
Где: Санктъ-Петербургъ

Репутация: 1
Всего: 151



Может, это просто путь к файлу так хитро обозвали?


--------------------
"Чтобы правильно задать вопрос, нужно знать большую часть ответа" (Р. Шекли)
ЖоржЖЖ
PM WWW   Вверх
redrick
Дата 26.3.2006, 13:43 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 547
Регистрация: 7.1.2004
Где: Москва

Репутация: 1
Всего: 5



The rules for resolving resource names are defined in the Application Resource Files section of the java.lang package documentation.

читаем:
Application Resource Files

Application resource files are accessed using getResourceAsStream(String name) in java.lang.Class . In the MIDP specification, getResourceAsStream is used to allow resource files to be retrieved from the MIDlet Suite's JAR file.

Resource names refer to the contents of the MIDlet Suite JAR file. Absolute pathnames, beginning with "/" are fully qualified file names within the jar file.

Relative pathnames, not beginning with "/" are relative to the class upon which getResourceAsStream is called. Relative names are converted to absolute by prepending a "/" followed by the fully qualified package with "." characters converted to "/" and a separator of "/". The resulting string is reduced to canonical form by applying as many times as possible the following:

* All occurences of "/./" are replaced with "/".
* All occurences of "/segment/../" are replaced with "/" where segment does not contain "/".

The canonical resource name is the absolute pathname of the resource within the JAR.

In no case can the path extend outside the JAR file, and resources outside the JAR file MUST NOT be accessible. For example, using "../../" does NOT point outside the JAR file. If there are any remaining "." or ".." characters they are treated literally in locating the resource. No resource can exist with that name so null is returned from Class.getResourceAsStream. Also, devices MUST NOT allow classfiles to be read from the JAR file as resources, but all other files MUST be accessible.



Lamer George, ну вощем да =) нро все ж написано =)


--------------------
Имею Мнение Хрен Оспоришь   
PM MAIL ICQ   Вверх
  
Ответ в темуСоздание новой темы Создание опроса

  • Прежде чем задать вопрос прочтите это!
  • Литература по Java находится здесь.
  • Литературу по Java обсуждаем здесь.
  • Используйте теги [code=java][/code] для подсветки кода. Используйтe чекбокс "транслит" (возле кнопок кодов) если у Вас нет русских шрифтов.
  • Действия модераторов можно обсудить здесь
  • С просьбами о написании курсовой, реферата и т.п. обращаться сюда

  • FAQ раздела лежит здесь!
 
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | Java ME (J2ME) | Следующая тема »


 




[ Время генерации скрипта: 0.0466 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.