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

Java基于swing实现的弹球游戏代码(3)

时间:2014-11-14 11:08来源:网络整理 作者:网络 点击:
分享到:
}; button.addActionListener(button_listener); this.add(button); this.add(lable); this.add(pBar); this.add(text_field); // 的到菜单条 JMenuBar bar = creatMenuBar(); // 为窗体设置菜单条 thi

                };
                button.addActionListener(button_listener);

                this.add(button);
                this.add(lable);
                this.add(pBar);
                this.add(text_field);
                // 的到菜单条
                JMenuBar bar = creatMenuBar();
                // 为窗体设置菜单条
                this.setJMenuBar(bar);
                // 设置窗体的可见性
                this.setVisible(true);
        }

        /**
         * 创建菜单条的方法
         *
         * @return
         */
        public JMenuBar creatMenuBar() {
                // 创建菜单条对象
                JMenuBar bar = new JMenuBar();
                // 创建菜单对象
                JMenu menu_menu = new JMenu("菜单");
                JMenu difficulty_menu = new JMenu("难度");
                JMenu help_menu = new JMenu("帮助");
                // 创建菜单选项对象
                JMenuItem star_item = new JMenuItem("开始");
                JMenuItem exit_item = new JMenuItem("退出");
                JMenuItem help_item = new JMenuItem("游戏说明");
                JMenuItem about_item = new JMenuItem("关于");
                // 创建单选选项
                JRadioButtonMenuItem easy_item = new JRadioButtonMenuItem(
                                "简单");
                JRadioButtonMenuItem middle_item = new JRadioButtonMenuItem(
                                "中等");
                JRadioButtonMenuItem hard_item = new JRadioButtonMenuItem(
                                "困难");
                // 创建一个按钮组
                ButtonGroup group = new ButtonGroup();
                // 将单选按钮添加到按钮组中
                group.add(easy_item);
                group.add(middle_item);
                group.add(hard_item);
                // 将单选按钮添加到菜单中
                difficulty_menu.add(easy_item);
                difficulty_menu.add(middle_item);
                difficulty_menu.add(hard_item);
                // 通过匿名内部类来创建动作监听器
                ActionListener listener = new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                command = e.getActionCommand();
                                // 如果选择开始,则创建线程对象
                                if (command.equals("开始") && list.size() == 0) {
                                        creatBall(20, 1);

精彩图集

赞助商链接