龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > JAVA开发 >

Java基于Swing实现的打猎射击游戏代码(9)

时间:2014-11-14 11:09来源:网络整理 作者:网络 点击:
分享到:
/** * 生成猪角色的线程 * */ class PigThread extends Thread { @Override public void run() { while (true) { // 创建代表野猪的标签控件 PigLabel pig = new PigLabel(); pig.setSize(120, 8

        /**
         * 生成猪角色的线程
         *
         */
        class PigThread extends Thread {
                @Override
                public void run() {
                        while (true) {
                                // 创建代表野猪的标签控件
                                PigLabel pig = new PigLabel();
                                pig.setSize(120, 80);// 设置控件初始大小
                                backgroundPanel.add(pig);// 添加控件到背景面板
                                try {
                                        // 线程随机休眠一段时间
                                        sleep((long) (random() * 3000) + 500);
                                } catch (InterruptedException e) {
                                        e.printStackTrace();
                                }
                        }
                }
        }

        /**
         * 生成鸟角色的线程
         *
         */
        class BirdThread extends Thread {
                @Override
                public void run() {
                        while (true) {
                                // 创建代表小鸟的标签控件
                                BirdLabel bird = new BirdLabel();
                                bird.setSize(50, 50);// 设置控件初始大小
                                backgroundPanel.add(bird);// 添加控件到背景面板
                                try {
                                        // 线程随机休眠一段时间
                                        sleep((long) (Math.random() * 3000) + 500);
                                } catch (InterruptedException e) {
                                        e.printStackTrace();
                                }
                        }
                }
        }
}

希望本文所述对大家的Java程序设计有所帮助。

精彩图集

赞助商链接