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

📄 tframe.java~35~

📁 简单的俄罗斯方块游戏 源码 可 延伸成 网络版
💻 JAVA~35~
字号:
package tetrics;import java.awt.*;import java.awt.event.*;//import dialog.*;import javax.swing.*;//import client.*;import java.util.*;import com.borland.jbcl.layout.*;public class TFrame extends JFrame implements NetRead{    public Tetrics m_tetrics;//    public JPanel m_pStatus;    //public StatusBar m_pStatus;//    public JLabel m_lStatus;    //用于网络 //   public MyServer m_server; //   public MyClient m_client;    //定义表征现在网络状态的常量。    //NOCONNECT表示单机运行。    //SERVE表示这个游戏用作服务器。    //CLIENT表示这个游戏用作客户端    public static final int NOCONNECT=0,SERVER=1,CLIENT=2;    public int m_nNetStatus=NOCONNECT;  JPanel jPanel1 = new JPanel();  XYLayout xYLayout1 = new XYLayout();  JScrollPane jScrollPane1 = new JScrollPane();  JTextArea jTextArea1 = new JTextArea();  XYLayout xYLayout2 = new XYLayout();  JLabel jLabel1 = new JLabel();  JTextField jTextField1 = new JTextField();  JButton jButton1 = new JButton();  JMenuBar jMenuBar1 = new JMenuBar();  JMenu jMenu1 = new JMenu();  JMenuItem jMenuItem1 = new JMenuItem();  JMenuItem jMenuItem2 = new JMenuItem();  JMenuItem jMenuItem3 = new JMenuItem();  JMenu jMenu2 = new JMenu();  JMenuItem jMenuItem4 = new JMenuItem();  JMenuItem jMenuItem5 = new JMenuItem();  JMenu jMenu3 = new JMenu();  JMenuItem jMenuItem6 = new JMenuItem();  JMenuItem jMenuItem7 = new JMenuItem();  JPanel jPanel2 = new JPanel();  XYLayout xYLayout3 = new XYLayout();  JTextArea jTextArea2 = new JTextArea();  JTextArea jTextArea3 = new JTextArea();    public void ShowMessage(String str)    {    }    public TFrame()    {        super();        try        {            jbInit();            myInit();        }        catch(Exception e)        {            e.printStackTrace();        }    }    public static void main(String[] args)    {        TFrame mframe=new TFrame();        mframe.show();    }    private void jbInit() throws Exception    {        this.addWindowListener(new java.awt.event.WindowAdapter() {            public void windowClosing(WindowEvent e) {                this_windowClosing(e);            }        });        this.addWindowListener(new java.awt.event.WindowAdapter()        {            public void windowClosing(WindowEvent e)            {                this_windowClosing(e);            }        });    this.getContentPane().setLayout(xYLayout1);    jTextArea1.setText("jTextArea1");    jPanel1.setLayout(xYLayout2);    jLabel1.setText("jLabel1");    jTextField1.setText("jTextField1");    jButton1.setText("jButton1");    this.setJMenuBar(jMenuBar1);    jMenu1.setText("游戏");    jMenuItem1.setText("开始");    jMenuItem2.setText("暂停");    jMenuItem3.setText("退出");    jMenu2.setText("设置");    jMenuItem4.setText("难度");    jMenuItem5.setText("速度");    jMenu3.setText("帮助");    jMenuItem6.setText("关于");    jMenuItem7.setText("操作");    jPanel2.setLayout(xYLayout3);    xYLayout1.setWidth(535);    xYLayout1.setHeight(526);    jTextArea3.setText("");    jPanel1.add(jScrollPane1,     new XYConstraints(0, 5, 530, 53));    jPanel1.add(jLabel1, new XYConstraints(15, 73, 75, 26));    jPanel1.add(jTextField1, new XYConstraints(110, 74, 321, 17));    jPanel1.add(jButton1, new XYConstraints(452, 71, 62, 20));    jScrollPane1.getViewport().add(jTextArea1, null);    jMenuBar1.add(jMenu1);    jMenuBar1.add(jMenu2);    jMenuBar1.add(jMenu3);    jMenu1.add(jMenuItem1);    jMenu1.add(jMenuItem2);    jMenu1.add(jMenuItem3);    jMenu2.add(jMenuItem4);    jMenu2.add(jMenuItem5);    jMenu3.add(jMenuItem6);    jMenu3.add(jMenuItem7);    this.getContentPane().add(jPanel2,  new XYConstraints(1, 0, 534, 398));    jPanel2.add(jTextArea3,                 new XYConstraints(187, 7, 274, 400));    jPanel2.add(jTextArea2,  new XYConstraints(43, 22, 78, 74));    this.getContentPane().add(jPanel1, new XYConstraints(0, 410, 535, 103));    }    private void myInit()    {        setSize(750,580);        setLocation(500,400);        //setLayout(null);        JPanel gameP=new JPanel();        gameP.setLayout(null);        m_tetrics=new Tetrics(this);      //  m_tetrics.setBounds(0,0,Tetrics.WIDTH,Tetrics.HEIGHT);/*        m_pStatus=new JPanel();        m_pStatus.setBackground(Color.lightGray);        m_lStatus=new JLabel("游戏装载完毕");        m_lStatus.setBackground(Color.lightGray);        m_pStatus.add(m_lStatus);*/      //  m_pStatus=new StatusBar(this);     //   m_pStatus.setBounds(0,Tetrics.HEIGHT,Tetrics.WIDTH,Tetrics.HEIGHT+130);      //  gameP.add(m_tetrics);     //   gameP.add(m_pStatus);//        add(m_tetrics);//        add(m_pStatus);        getContentPane().add(gameP);    }    void this_windowClosing(WindowEvent e)    {       // if(m_nNetStatus==SERVER)m_server.close();     //   if(m_nNetStatus==CLIENT)m_client.close();        System.exit(0);    }    public void insertScoreReport(int nScore)    {        Score score=new Score();        if(score.isScoreTop(nScore))        {            InsertURScoreP ius=new InsertURScoreP(this,"恭喜进入前十名",true);            ius.show();        }    }    /**     * 从对方读来字串时,调用这个方法     * @param str 读来的字串     */    public void readStr(String str)    {        //如果读来的数据是对方的状态信息        if(str.startsWith("Status:"))        {            int[] nRivalField=new int[Tetrics.m_nCols*(Tetrics.m_nRows+4)];            str=str.substring(7,str.length());            StringTokenizer st=new StringTokenizer(str,"|");            int i=0;            try            {                while(st.hasMoreTokens())                {                      nRivalField[i]=Integer.parseInt(st.nextToken());                      i++;                }            }catch(Exception e){}            i=0;            for(int col=0;col<Tetrics.m_nCols;col++)                for(int row=0;row<Tetrics.m_nRows;row++)                {                    m_tetrics.m_nRivalField[col][row]=nRivalField[i];                    i++;                }        }        //如果读来的数据是对方消去一行的消息。        else if(str.equals("RemoveLine"))        {            m_tetrics.addRandomLine();        }        //如果读来的数据是对方开始游戏的信息        else if(str.equals("StartGame"))        {            m_tetrics.start();        }        //如果读来的数据是对方暂停游戏的信息        else if(str.equals("PauseGame"))        {            m_tetrics.pause();        }        //如果读来的数据是对方中止游戏的信息        else if(str.equals("StopGame"))        {            m_tetrics.stop();        }        //如果读来的数据是对方要求改变游戏级别的信息        else if(str.startsWith("Level:"))        {            str=str.substring(6,str.length());            try{                m_tetrics.setPlayLevel(Integer.parseInt(str));            }            catch(Exception e){}        }        //如果读来的数据是对方对你谈话的内容        else if(str.startsWith("Talk:"))        {            str=str.substring(5,str.length());            jTextArea1.append("对手:"+str+"\n");        }        //如果读来的数据是对方的游戏已经结束的信息        else if(str.startsWith("GameOver:"))        {            str=str.substring(9,str.length());            if(m_tetrics.m_bGameInPlay)            {                m_tetrics.m_bGameInPlay=false;                m_tetrics.stop();                //sendStr("GameOver:"+m_tetrics.m_nTheScore);            }            try{                int nRivalScore=Integer.parseInt(str);                //new GameOverD(this,m_tetrics.m_nTheScore,nRivalScore);            }catch(Exception e){e.printStackTrace();}        }    }    /**     * 用来在StatusBar里显示现在的联网状况     */    public void showMessage(String str)    {     //   m_pStatus.appendStr(str+"\n");    }    /**     * 将信息发给对方     *//*   public void sendStr(String str)    {        switch(m_nNetStatus)        {            case SERVER:                if(m_server!=null)                    m_server.writeStr(str+"\n");                break;            case CLIENT:                if(m_client!=null)                    m_client.writeStr(str+"\n");                break;        }    }*/}

⌨️ 快捷键说明

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