⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 optionsscreen.java

📁 In the last three articles, I’ve been walking you through the creation of an end-to-end BlackBerry a
💻 JAVA
字号:
package KnowledgeBase;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;

class OptionsScreen  extends MainScreen{
    
    private EditField appServerUrlField;
    private EditField maxCachedArticlesField;
    
    private MenuItem saveMenu = new MenuItem("Save",100,10) {
       public void run() {
           saveOptions();
       } 
    };
    
    OptionsScreen() {    
        
        this.setTitle("Options");
        
        appServerUrlField = new EditField("App. Server Url:","",256,EditField.EDITABLE | EditField.FILTER_URL);
        maxCachedArticlesField = new EditField("Max. Cached Results:","",2,EditField.EDITABLE | EditField.FILTER_INTEGER);
        
        this.add(appServerUrlField);
        this.add(maxCachedArticlesField);
    
    }
    
    protected void makeMenu(Menu menu, int instance) {
        menu.add(saveMenu);
        menu.add(MenuItem.separator(saveMenu.getOrdinal() + 1));
        super.makeMenu(menu,instance);
    }
    
    public void displayOptions() {
        
        String serverUrl = DataStore.getAppServerUrl();
        int maxCachedArticles = DataStore.getMaxCachedArticles();
        
        appServerUrlField.setText(serverUrl);
        maxCachedArticlesField.setText(String.valueOf(maxCachedArticles));
        
    }
    
    private void saveOptions() {
        
        String serverUrl = appServerUrlField.getText().trim();
        String maxCachedArticlesString = maxCachedArticlesField.getText().trim();
        
        if (null == serverUrl || serverUrl.length() == 0 ||
            null == maxCachedArticlesString || 
                maxCachedArticlesString.length() == 0) {
              
              Dialog.alert("Please correct the invalid options");
              return;  
        }
        
        DataStore.setAppServerUrl(serverUrl);
        DataStore.setMaxCachedArticles(Integer.parseInt(maxCachedArticlesString));
        this.setDirty(false);
        this.close();
        
    }
    
    protected boolean onSavePrompt() {
        
        if (Dialog.YES == Dialog.ask(Dialog.D_YES_NO, "Close without saving?")) {
            this.setDirty(false);
            return true;
        }  else {
            return false;
        }     
    }
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -