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

📄 mainwindow.java

📁 java网络围棋,用java做的小游戏
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    {        this.textField1.setBackground(Color.white);        this.textField1.setEnabled(true);        this.choice1.setEnabled(true);        this.button1.setEnabled(true);    }    //判断类型    boolean isSingle()    {        return this.checkbox1.getState();    }    void single()    {    }    void multiple()    {    }    //加小黄点    void showMousePoint(Point mousePoint)    {        Graphics g=this.panelGo.getGraphics();        g.setColor(Color.yellow);        g.fillOval(mousePoint.x*20-6,mousePoint.y*20-6,this.panelGo.INTERVAL-8,this.panelGo.INTERVAL-8);        this.yellowPoint.x=mousePoint.x;//定位黄点        this.yellowPoint.y=mousePoint.y;        Graphics myG=this.myImage.getGraphics();        this.createMyImage(myG,this.yellowPoint,0);    }    //消除前一个黄点    void removeLastMousePoint(Point thatPoint,Point thisPoint)    {        if(thatPoint.x!=thisPoint.x||thatPoint.y!=thisPoint.y)        {            Graphics g=this.panelGo.getGraphics();            if(this.yellowPoint!=null&&this.myImage!=null)                g.drawImage(this.myImage,this.yellowPoint.x*20-8,this.yellowPoint.y*20-8,16,16,null);            this.yellowPoint.x=1000;//不在范围内,就一边去            this.yellowPoint.y=1000;        }    }    //构成所需要的Image    void createMyImage(Graphics g,Point thisPoint,int color)    {        int px=thisPoint.x;        int py=thisPoint.y;        Color myColor=this.panelGo.getBackground();        if(px==1&&py==1&&color==0)//四个角        {            g.setColor(myColor);            g.fillRect(0,0,16,16);            g.setColor(Color.black);            g.drawLine(8,8,8,16);            g.drawLine(5,5,5,16);            g.drawLine(8,8,16,8);            g.drawLine(5,5,16,5);        }        else if(px==1&&py==19&&color==0)        {            g.setColor(myColor);            g.fillRect(0,0,16,16);            g.setColor(Color.black);            g.drawLine(8,8,8,0);            g.drawLine(8,8,16,8);            g.drawLine(5,11,16,11);            g.drawLine(5,11,5,0);        }        else if(px==19&&py==1&&color==0)        {            g.setColor(myColor);            g.fillRect(0,0,16,16);            g.setColor(Color.black);            g.drawLine(8,8,8,16);            g.drawLine(8,8,0,8);            g.drawLine(11,5,11,16);            g.drawLine(11,5,0,5);        }        else if(px==19&&py==19&&color==0)        {            g.setColor(myColor);            g.fillRect(0,0,16,16);            g.setColor(Color.black);            g.drawLine(8,8,8,0);            g.drawLine(8,8,0,8);            g.drawLine(11,11,11,0);            g.drawLine(11,11,0,11);        }        else if(px==1&&color==0)//四个边        {            g.setColor(myColor);            g.fillRect(0,0,16,16);            g.setColor(Color.black);            g.drawLine(8,8,16,8);            g.drawLine(8,0,8,16);            g.drawLine(5,0,5,16);        }        else if(px==19&&color==0)        {            g.setColor(myColor);            g.fillRect(0,0,16,16);            g.setColor(Color.black);            g.drawLine(8,8,0,8);            g.drawLine(8,0,8,16);            g.drawLine(11,0,11,16);        }        else if(py==1&&color==0)        {            g.setColor(myColor);            g.fillRect(0,0,16,16);            g.setColor(Color.black);            g.drawLine(8,8,8,16);            g.drawLine(0,8,16,8);            g.drawLine(0,5,16,5);        }        else if(py==19&&color==0)        {            g.setColor(myColor);            g.fillRect(0,0,16,16);            g.setColor(Color.black);            g.drawLine(8,8,8,0);            g.drawLine(0,8,16,8);            g.drawLine(0,11,16,11);        }        //八个小黑点        else if(color==0&&((px==4&&py==4)||(px==4&&py==10)||(px==4&&py==16)||(px==10&&py==4)||(px==10&&py==10)||(px==10&&py==16)||(px==16&&py==4)||(px==16&&py==10)||(px==16&&py==16)))        {            g.setColor(myColor);            g.fillRect(0,0,16,16);            g.setColor(Color.black);            g.drawLine(0,8,16,8);            g.drawLine(8,0,8,16);            g.fillOval(5,5,6,6);        }        else if(color==0)        {            g.setColor(myColor);            g.fillRect(0,0,16,16);            g.setColor(Color.black);            g.drawLine(0,8,16,8);            g.drawLine(8,0,8,16);        }    }    //单机版走步    void doSingle()    {        if(this.stepColor)            this.panelGo.doStep(this.yellowPoint,1);        else            this.panelGo.doStep(this.yellowPoint,2);        if(!this.panelGo.errorFlag)//如果不违例,则换颜色        {            this.stepColor=!this.stepColor;            this.paintThisColor(this.stepColor);        }        else            this.panelGo.errorFlag=false;        this.yellowPoint.x=1000;//刚走的子不至于删掉        this.yellowPoint.y=1000;    }    //联机版走步    void doMultiple()    {        int color;        if(this.choice1.getSelectedItem().equals("黑"))            color=1;        else            color=2;        this.panelGo.doStep(this.yellowPoint,color);        //如果走法不对,返回        if(this.panelGo.errorFlag)        {            this.panelGo.errorFlag=false;            return;        }        this.panelGo.setEnabled(false);        String message=this.getMessage(color,this.yellowPoint.x,this.yellowPoint.y);        this.writer.println(message);        this.yellowPoint.x=99;//刚走的子不至于删掉,还要可以解析        this.yellowPoint.y=99;    }    //处理发送字符串    String getMessage(int color,int x,int y)    {        String strColor=String.valueOf(color);        String strX;        String strY;        //如果单数的话,就加一位        if(x<10)            strX="0"+String.valueOf(x);        else            strX=String.valueOf(x);        if(y<10)            strY="0"+String.valueOf(y);        else            strY=String.valueOf(y);        return strColor+strX+strY;    }    void this_windowClosing(WindowEvent e)    {        this.dispose();        System.exit(0);    }    void checkbox2_mouseClicked(MouseEvent e)    {        this.enableLink();    }    void checkbox1_mouseClicked(MouseEvent e)    {        this.disableLink();    }    void button1_actionPerformed(ActionEvent e)    {        this.goToLink(this.textField1.getText().trim(),this.PORT);    }    //主动连接serverSocket    void goToLink(String hostName,int port)    {        try        {            this.stopFlag=true;            this.sendSocket=new Socket(hostName,port);            this.panelGo.showError("连接成功!!");            this.choice1.setEnabled(true);            this.button1.setEnabled(false);            this.checkbox1.setEnabled(false);            this.checkbox2.setEnabled(false);            this.textField1.setEnabled(false);            this.writer=new PrintWriter(this.sendSocket.getOutputStream(),true);            new Listen(sendSocket,this).start();        }catch(IOException ioe){this.panelGo.showError("意外中断");}    }    //开始时根据颜色画己方颜色    void paintMyColor()    {        Graphics g=this.label2.getGraphics();        if(this.choice1.getSelectedItem().equals("黑"))            g.fillOval(20,10,30,30);        else        {            g.setColor(Color.white);            g.fillOval(20,10,30,30);            g.setColor(Color.black);            g.drawOval(20,10,30,30);        }    }    //单机版画每步颜色    void paintThisColor(boolean whatColor)    {        Graphics g=this.label2.getGraphics();        if(whatColor)            g.fillOval(20,10,30,30);        else        {            g.setColor(Color.white);            g.fillOval(20,10,30,30);            g.setColor(Color.black);            g.drawOval(20,10,30,30);        }    }}

⌨️ 快捷键说明

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