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

📄 tictactoegridbox.java

📁 jxta官方例程
💻 JAVA
字号:
/* * GridBox.java * * Created on February 8, 2005, 2:22 AM */package net.jxta.myjxta.plugins.tictactoe;import java.awt.Color;import java.awt.Dimension;import java.awt.EventQueue;import java.awt.Graphics;import java.awt.Image;import java.awt.Insets;import javax.swing.ImageIcon;import javax.swing.JPanel;import javax.swing.border.EmptyBorder;import javax.swing.border.LineBorder;import org.apache.log4j.Level;import org.apache.log4j.Logger;/** * * @author Jeff Moore */public class TicTacToeGridBox extends JPanel {        static final Logger LOG = Logger.getLogger (TicTacToeGridBox.class);        private EmptyBorder emptyBorder = null;        private LineBorder lineBorder = null;        private LineBorder normalBorder = null;        private Dimension maxDimension = new Dimension (68,68);    /** either LOCAL_PLAYER or REMOTE_PLAYER*/    private int player = 0;        private String id = null;        private boolean available = true;        private TicTacToeDialogPanel view = null;        private Image image;        private Insets insets = null;        boolean blinking = false;        public TicTacToeGridBox (String id, TicTacToeDialogPanel view) {                super();                LOG.setLevel(Level.INFO);                this.id = id;                this.view = view;                insets = new Insets(0,0,0,0);                this.emptyBorder = new EmptyBorder (2,2,2,2);                this.lineBorder = new LineBorder (Color.RED, 2);                this.normalBorder = new LineBorder(Color.BLUE,1);                setOpaque (false);                setBorder (normalBorder);                setPlayerIcon (view.getIconBlank ());                setVisible (true);                                    }        public Insets getInsets() {        return insets;    }    public Insets getInsets(Insets insets) {        return getInsets();    }        public boolean isAvailable () {                return available;            }        public void setAvailable (boolean available) {                this.available = available;            }        public String getId () {                return this.id;            }        public void reset () {        setPlayerIcon (view.getIconBlank ());        setAvailable(true);    }        public int getPlay () {                return this.player;            }                public Dimension getMaximunSize () {                return maxDimension;            }             public Dimension getMinimumSize () {                return maxDimension;            }        public void paintComponent(Graphics g) {        super.paintComponent(g);                g.drawImage(this.image, 0,0, this);                    }        public Dimension  getPreferredSize() {                return maxDimension;            }           private void setPlayerIcon (final ImageIcon icon) {        this.image = icon.getImage().getScaledInstance (68, 68, Image.SCALE_SMOOTH);        repaint();        /*        EventQueue.invokeLater (new Runnable () {            public void run () {                                setIcon (icon);                            }        });         **/    }                protected void setBlink () {                if(blinking) {                        blink(blinking = false);        }else{            blink(blinking=true);        }    }        protected void blink(final boolean blink) {                                EventQueue.invokeLater (new Runnable () {            public void run () {                                if(blink) {                    setBorder (lineBorder);                }else{                    setBorder (normalBorder);                }                                            }        });                    }        public void makeMove (int player) {        if ( isAvailable () ) {                        this.player = player;                        ImageIcon icon = null;                        if(player == TicTacToeGameControl.LOCAL_PLAYER) {                                icon = view.getLocalPlayerIcon ();                            }else if(player == TicTacToeGameControl.REMOTE_PLAYER) {                if (LOG.isEnabledFor (Level.INFO)) {            LOG.info ("remotePlayerIcon is "+view.getRemotePlayerIcon ());        }                icon = view.getRemotePlayerIcon ();                            }else {                                icon = view.getIconBlank ();                            }                        setPlayerIcon (icon);        }    }            }

⌨️ 快捷键说明

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