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

📄 tictactoedialogpanel.java

📁 jxta官方例程
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                                remotePlayerNameLabel.setText (remotePlayerName);                            }                                            });            }                    public void setLocalPlayerName (String name) {                this.remotePlayerName = name;    }                        private void updateGameStateView (final String stateString) {                EventQueue.invokeLater (new Runnable () {            public void run () {                gameStateLabel.setText (stateString);            }        });    }        protected void updatePlayersTurnView (final String stateString) {                EventQueue.invokeLater (new Runnable () {            public void run () {                playersTurnLabel.setText (stateString);            }        });    }        public void sessionStateChanged (int sessionState) {                if(sessionState == TicTacToeGameControl.SESSION_DISCONNECTED) {                        updateGameStateView (TicTacToeDialogPanel.DISPLAY_SESSION_TTT_DISCONNECTED);                    }else if(sessionState == TicTacToeGameControl.SESSION_DISCONNECTING) {                        updateGameStateView (TicTacToeDialogPanel.DISPLAY_SESSION_TTT_DISCONNECTING);                    }else if(sessionState == TicTacToeGameControl.SESSION_ENDED) {                        updateGameStateView (TicTacToeDialogPanel.DISPLAY_SESSION_TTT_ENDED);                    }else if(sessionState == TicTacToeGameControl.SESSION_ENDING) {                        updateGameStateView (TicTacToeDialogPanel.DISPLAY_SESSION_TTT_ENDING);                    }else if(sessionState == TicTacToeGameControl.SESSION_STARTED) {                        updateGameStateView (TicTacToeDialogPanel.DISPLAY_SESSION_TTT_STARTED);                    }else if(sessionState == TicTacToeGameControl.SESSION_STARTING) {                        updateGameStateView (TicTacToeDialogPanel.DISPLAY_SESSION_TTT_STARTING);                    }else if(sessionState == TicTacToeGameControl.SESSION_CONNECTED) {                        updateGameStateView (TicTacToeDialogPanel.DISPLAY_SESSION_TTT_CONNECTED);                    }else if(sessionState == TicTacToeGameControl.SESSION_CONNECTING) {                        updateGameStateView (TicTacToeDialogPanel.DISPLAY_SESSION_TTT_CONNECTING);                    }            }            public void updateRemotePlayerTotalWins (final int wins) {        EventQueue.invokeLater (new Runnable () {            public void run () {                                remotePlayerWinsLabel.setText (String.valueOf (wins));                            }        });            }        public void updateLocalPlayerTotalWins (final int wins) {        EventQueue.invokeLater (new Runnable () {            public void run () {                                localPlayerWinsLabel.setText (String.valueOf (wins));                            }        });            }        public ImageIcon getIconBlank () {                return iconBlank;            }        public ImageIcon getIconX () {                return iconX;            }    public ImageIcon getIconO () {                return iconO;            }        public void setGameStatus (final String status) {        EventQueue.invokeLater (new Runnable () {            public void run () {                                //gameStateLabel.setText (status);                            }        });    }                        protected static void displayIncomingGameRequest (String remotePlayerName) {                JOptionPane.showInternalConfirmDialog (null,                "Accept game request from "+remotePlayerName,                "TicTacToe",                JOptionPane.YES_NO_OPTION,                JOptionPane.QUESTION_MESSAGE);            }                public void setGameDraw () {        setGameStatus (TicTacToeDialogPanel.GAME_DRAW);        Runnable r = new Runnable () {            public void run () {                                                int i = 0;                while(i++ < blinkVector) {                    for(int r =0; r < gridRows; r++) {                        for (int c = 0; c < gridColumns; c++) {                            if (LOG.isEnabledFor (Level.INFO)) {                                LOG.info ("grid ["+r+"] ["+c+"]");                            }                            grid[r][c].setBlink ();                                                                                }                    }                    try{                        Thread.sleep (blinkRate);                    }catch(InterruptedException x) {                        //bleh                    }                }                readyForNextGame ();            };        };        blinkGameBoard (r);                                    }    /**     * the winning set is the remote players winning set     */    public void setLocalPlayerLost (final String[] winningSet) {                if (LOG.isEnabledFor (Level.INFO)) {            LOG.info ("LocalPlayerLost");                    }        setGameStatus (TicTacToeDialogPanel.GAME_LOST);                updateRemotePlayerTotalWins (this.getGameControl ().getRemotePlayerTotalWins ());                Runnable r = new Runnable () {            public void run () {                                                int i = 0;                while(i++ < blinkVector) {                                        for(int j = 0 ; j < winningSet.length; j++) {                        int row = 0;                        int column = 0;                                                String r = String.valueOf (winningSet[j].charAt (0));                        if(r.equals ("A")) { row = 0; }                        if(r.equals ("B")) { row = 1; }                        if(r.equals ("C")) { row = 2; }                                                String c = String.valueOf (winningSet[j].charAt (1));                        column = Integer.valueOf (c).intValue ();                                                grid[row][column].setBlink ();                                            }                    try{                        Thread.sleep (blinkRate);                    }catch(InterruptedException x) {                        //bleh                    }                }                                readyForNextGame ();                            };        };        blinkGameBoard (r);                                    }                public void setLocalPlayerWon (final String[] winningSet) {                                updateLocalPlayerTotalWins (this.getGameControl ().getLocalPlayerTotalWins ());                setGameStatus (TicTacToeDialogPanel.GAME_WON);                Runnable r = new Runnable () {            public void run () {                                                int i = 0;                while(i++ < blinkVector) {                                        for(int j = 0 ; j < winningSet.length; j++) {                        int row = 0;                        int column = 0;                                                String r = String.valueOf (winningSet[j].charAt (0));                        if(r.equals ("A")) { row = 0; }                        if(r.equals ("B")) { row = 1; }                        if(r.equals ("C")) { row = 2; }                                                String c = String.valueOf (winningSet[j].charAt (1));                        column = Integer.valueOf (c).intValue ();                                                grid[row][column].setBlink ();                                            }                    try{                        Thread.sleep (blinkRate);                    }catch(InterruptedException x) {                        //bleh                    }                }                                readyForNextGame ();            };        };        blinkGameBoard (r);                                    }            /**     * Threads need to be collected and stopped somehow     */    private void blinkGameBoard (Runnable r) {                Thread t = new Thread (r);        t.start ();            }        protected void readyForNextGame () {        if(isLocallyInitiated ()) {            EventQueue.invokeLater (new Runnable () {                public void run () {                    playAgainButton.setEnabled (true);                    playAgainButton.setVisible (true);                }            });        }    }                public String getLocalPlayerIconType () {                return this.localPlayerIconType;            }        public String getRemotePlayerIconType () {                return this.remotePlayerIconType;            }        public void setRemotePlayerIconType (String remotePlayerIconType) {                this.remotePlayerIconType = remotePlayerIconType;            }        public void setLocalPlayerIconType (String localPlayerIconType) {                this.localPlayerIconType = localPlayerIconType;            }                public void setRemotePlayerIcon ( ImageIcon icon) {                remotePlayerIcon = new ImageIcon (icon.getImage ().getScaledInstance (68, 68, Image.SCALE_SMOOTH));;                EventQueue.invokeLater (new Runnable () {            public void run () {                remotePlayerIconLabel.setIcon (remotePlayerIcon);            }        });                    }        public void setRemotePlayerIcon ( Image image) {                remotePlayerIcon = new ImageIcon (image);                EventQueue.invokeLater (new Runnable () {            public void run () {                remotePlayerIconLabel.setIcon (remotePlayerIcon);            }        });                    }        public void setTempStatus (final String status) {                                int i = 0;        while(i++ < blinkVector) {            EventQueue.invokeLater (new Runnable () {                public void run () {                    //gameStateLabel.setText (status);                }            });                                    try{                Thread.sleep (blinkRate);            }catch(InterruptedException x) {                //bleh            }                                }                            }        public void setLocalPlayerIcon ( ImageIcon icon) {                localPlayerIcon = icon;                EventQueue.invokeLater (new Runnable () {            public void run () {                localPlayerIconLabel.setIcon (localPlayerIcon);            }        });                    }        public void addMoveListener (MoveListener l) {        synchronized(this.moveListeners) {                        moveListeners.add (l);                    }    }        private void notifyMoveListeners (TicTacToeGridBox box) {                Iterator<MoveListener> itr = moveListeners.iterator ();                while(itr.hasNext ()) {                        itr.next ().localMoveMade (box.getId ());        }            }                public ImageIcon getRemotePlayerIcon () {                return remotePlayerIcon;            }                public ImageIcon getLocalPlayerIcon () {                return localPlayerIcon;            }        public void setLocalPlayerIconFileName (String localPlayerIconFileName) {                this.localPlayerIconFileName = localPlayerIconFileName;            }        public String getLocalPlayerIconFileName () {                return localPlayerIconFileName;            }        private void resetGrid () {        EventQueue.invokeLater (new Runnable () {            public void run () {                for(int r = 0; r < gridRows; r++) {                    for(int c = 0; c < gridColumns ; c++) {                        grid[r][c].reset ();                    }                }            }        });            }            public void remoteMoveMade (String moveId) {                if (moveId != null) {                                    int row = 0;            int column = 0;                        String r = String.valueOf (moveId.charAt (0));            if(r.equals ("A")) { row = 0; }            if(r.equals ("B")) { row = 1; }            if(r.equals ("C")) { row = 2; }                        String c = String.valueOf (moveId.charAt (1));            column = Integer.valueOf (c).intValue ();                        grid[row][column].makeMove (TicTacToeGameControl.REMOTE_PLAYER);            grid[row][column].setAvailable (false);                    }    }    public boolean isLocallyInitiated() {	return  m_isLocallyInitiated;    }                                        }

⌨️ 快捷键说明

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