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

📄 community.java

📁 j2me编写的一个在线游戏
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    }    /**     * Removes a particular named View from the View stack.     * @param name Name of View to remove.     */    public void removeView(String name) {        synchronized (viewList) {            View view = findView(name);            if (view != null) viewList.removeElement(view);        }    }    /**     * Causes currently visible canvas to repaint itself.     *     */    public void repaint()    {        getCanvas().repaint();    }    /**     * Returns currently visible canvas.     */    public Canvas getCanvas() {        return canvas;    }    /*     * =======================================================================     *  Dialog convenience methods     * =======================================================================     */    /**     * Shows an error dialog w/ a string message and one "OK"     * softkey in the left corner of the screen.  "OK" just     * goes back to the previous screen.     *     * @param msg text of error message to display     */    public void showError(String msg) {        showError( msg, null, Dialog.ALERT);    }    /**     * Shows error message passed in, in full-screen Dialog.     *     * @param msg The error message to be displayed     * @param target If not <code>null</code>, error dialog will     *   go to this View upon exiting.  Otherwise, will typically     *   go "BACK"     * @param type type of dialog.  See <code>Dialog<code> class.     */    public void showError(String msg, String target, int type)    {        //System.out.println("Community.showError(), msg = " + msg);    	String name = "Error";    	switch (type) {    	case Dialog.ALERT:    		name = "Alert";    		break;    	case Dialog.ALERT_FATAL:    	case Dialog.ALERT_LOGOUT:    		name = "Logout Error";            msg += " -- You must log back in from the main menu.";    		break;    	}        showDialog( name, msg, null, target, type);    }    /**     * Shows message passed in, in a full-screen Dialog.     *     * @param title     * @param contents Must be either a String or a Component     * @param arg Argument passed to listener when activated via SELECT     * @param targetView If not null, View to go to upon exiting     * @param type Type of dialog (see Dialog class for types).     */    public void showDialog(String title, Object contents, Object arg, String targetView, int type) {        String rightSoft = null;        String leftSoft = null;        // Contents to be displayed - must be either a String or a Component        Component comp = null;        // If contents is a Component (usually a text input component)        // then display it directly.        if (contents instanceof Component) {        	comp = (Component)contents;        // If contents is a String, then put the String in a TextBox and        // display that.        } else {	        TextBox box = new TextBox();	        if (contents instanceof String) {	        	box.setText( (String)contents);	        } else {	        	box.setText(	        			"Error! Unrecognized contents: " +	        			contents.toString()	        			);	        }	        box.setBackground(0x00ffffff);	        box.setForeground(0x00c0c0c0);	        box.setFocusable(false);	        box.setDimension( canvas.getWidth() - 10, 12 * box.getFont().getHeight() + TextBox.WIDTH_OFFSET);	        comp = box;        }        // Set left/right softkeys based on type        switch (type) {        case Dialog.YES_NO:        	leftSoft = Community.YES;            rightSoft = Community.NO;            break;        case Dialog.DATA_ENTRY:        case Dialog.OK_CANCEL:        	leftSoft = Community.OK;        	rightSoft = Community.CANCEL;        	break;        // All other alerts have only "OK" on left softkey        default:        	leftSoft = Community.OK;            break;        }        Dialog dialog = new Dialog(            this,            title,            this,            leftSoft,            rightSoft,            comp,            arg,            type,            targetView        );        switchToView(dialog, true);    }    /*    public void showDebug(String msg) {        TextView view = new TextView(                this,                "Debug",                null,                this,                Community.BACK,                Community.OK,                null,                msg,                true        );        switchToView( view, true );    }    *//*     * =======================================================================     *  Event handling - managing input from various Views     * =======================================================================     */    /**     * Callback for button list views     *     * @param view Name of View     * @param button Name of Button     */    public void buttonPressed(String view, String button) {    	// Welcome screen (offline main menu) buttons        if (view.equals(Community.WELCOME)) {            if (button.equals( Community.SINGLE_USER)) {                startGame(true);            }            else if (button.equals( Community.GO_ONLINE)) {                switchToView(LOGIN);            }            else if (button.equals( Community.ABOUT)) {            	switchToView( ABOUT);            }            else if (button.equals( Community.HELP)) {            	switchToView( HELP);            }        }        // Login screen buttons        else if (view.equals(LOGIN)) {        	 if (button.equals(Community.LOGIN)) {        		 switchToView(LOGIN);        	 }        	 else if (button.equals(Community.CREATE_ACCOUNT)) {        		 switchToView(CREATE_ACCOUNT);        	 }        }        // Rankings screen buttons (stats vs. my rankings)        else if (view.equals(RANKING)) {            if (button.equals( Community.STATS)) {                switchToView(STATS);            }            else if (button.equals( Community.MY_RANKINGS)) {                switchToView(MY_RANKINGS);            }        }        // Play screen buttons (challenge vs. quick match)        else if (view.equals(PLAY)) {            if (button.equals("quick match")) {            	handleQuickMatch();                View next = getView(PENDING_GAMESTART);                next.setWaiting(true);                switchToView(next, true);            }            else if (button.equals("challenge")) {                switchToView(FRIENDS);            }        }        // Help screen buttons        else if (view.equals(HELP)) {            if (button.equals("snap mobile")) {                switchToView(SM_HELP);            }            else if (button.equals("game")) {                switchToView(GAME_HELP);            }            else if (button.equals("operator")) {                switchToView(OPERATOR_HELP);            }        }        // Stats buttons        else if (view.equals(STATS)) {            RankingView next = (RankingView)getView(TOP_10);            next.setName(button);            switchToView(next, true);        }        // Online main menu buttons        else if (view.equals(HOME)) {            if (button.equals("play")) {                switchToView(PLAY);            }            else if (button.equals("rankings")) {                switchToView(RANKING);            }            else if (button.equals("friends")) {                switchToView(FRIENDS);            }            else if (button.equals("help")) {                switchToView(HELP);            }        }    }    /*     * Event handler implemented from samples.ui.EventListener interface.     *     * @param e The event     */    public boolean handleEvent(Event e) {        //System.out.println("Community.handleEvent(), source = " + e.getSource() + ", value = " + e.getValue());        View view = (View)e.getSource();        String action = (String)e.getValue();        ItemList il;        if (e.getSource() instanceof LoginView) {        	switchToView(HOME);            return true;        }        // Splash screen        else if (e.getSource() instanceof SplashView) {            switchToView(Community.WELCOME);            return true;        }        // Pending game start screen        else if (e.getSource() instanceof TextView) {            if (view.getName().equals(PENDING_GAMESTART)) {                if (action.equals(Community.CANCEL)) {                    il = new ItemList();                    il.setItem("cmd", "gameStartCancel");                    il.setItem("listener", this);                    executeCmd(il);                    switchToView(Community.BACK);                    return true;                }            }        }        // Dialogs        else if (e.getSource() instanceof Dialog) {            Dialog dialog = (Dialog)e.getSource();            String name = dialog.getName();            il = new ItemList();            if (dialog.getType()==Dialog.ALERT_FATAL) {                setLoginInfo(null, null, null, null);                if (mazeRacer.isPlaying()) mazeRacer.gameOver(false);                switchToView(Community.WELCOME);                return true;            }            else if (dialog.getType()==Dialog.ALERT_LOGOUT) {                if (mazeRacer.isPlaying()) mazeRacer.gameOver(false);                logout();                return true;            }            else if (name.equals("Alert") || name.equals("Error") || name.equals("Note")) {                //System.out.println("got dialog event, switching to back");                switchToView(Community.BACK);                return true;            }            else if (name.equals("Friend Request")) {                String from = (String)dialog.getArg();                if (action.equals(Community.YES)) {                    buddyList.add(new Buddy(from, Buddy.ONLINE_AVAILABLE));                    //System.out.println("approved buddy request. from = " + from);                    //System.out.println("buddyList.get(from) = " + buddyList.get(from));                }                il.setItem("cmd", action.equals(Community.YES)                    ? "acceptBuddyRequest"                    : "declineBuddyRequest");                il.setItem("name", from);                il.setItem("listener", this);                executeCmd(il);                switchToView(Community.BACK);                return true;            }            else if (name.equals("Add Friend")) {                if (action.equals(Community.OK)) {                	addFriend( ((TextField)dialog.getComponent()).getText());                    return true;                }            }            else if (name.equals("Remove Friend")) {                if (action.equals(Community.YES)) {                    String buddy = (String)dialog.getArg();                    il.setItem("cmd", "removeBuddy");                    il.setItem("name", buddy);                    il.setItem("listener", this);                    executeCmd(il);                    buddyList.remove(buddy);                    switchToView( Community.BACK);                    return true;                }            }            // user wants to accept challenge            else if (name.equals("Challenge")) {                if (action.equals(Community.YES)) {                	switchToView( Community.BACK);                    handleChallenge(null, (String)dialog.getArg(), 0);                    return true;                }            }

⌨️ 快捷键说明

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