快速搜索
主页 > 软件开发 > JAVA开发 >

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

时间:2014-11-14 11:08来源:网络整理 作者:网络 点击:
分享到:
这篇文章主要介绍了Java基于swing实现的弹球游戏代码,包含了窗体界面设计与游戏的逻辑功能处理,具有不错的参考借鉴价值,需要的朋友可以参考下

本文实例讲述了Java基于swing实现的弹球游戏代码。分享给大家供大家参考。

主要功能代码如下:

复制代码 代码如下:

package Game;

import java.awt.Graphics;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Random;

import javax.swing.ButtonGroup;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JRadioButtonMenuItem;

/**
?* 游戏界面类
?*
?* @author Administrator
?*
?*/
public class Game extends javax.swing.JFrame {
??????? private static final long serialVersionUID = 1L;
??????? private static Game UI;
??????? private Graphics g;
??????? private Listener ml;
??????? public javax.swing.JLabel text_field;
??????? public javax.swing.JProgressBar pBar;
??????? private String command;
??????? public ArrayList list = new ArrayList();
??????? private javax.swing.JToggleButton button;

??????? public static void main(String args[]) {
??????????????? UI = new Game();
??????????????? UI.initUI();
??????? }

??????? /**
???????? * 初始化窗体的方法
???????? */
??????? public void initUI() {
??????????????? // 设置标题
??????????????? this.setTitle("是高手就坚持10s");
??????????????? // 设置大小
??????????????? this.setSize(610, 635);
??????????????? // 设置关闭是退出程序
??????????????? this.setDefaultCloseOperation(3);
??????????????? // 设置打开窗体时在屏幕中间显示
??????????????? this.setLocationRelativeTo(null);
??????????????? // 设置窗体的流式布局管理器
??????????????? this.setLayout(new java.awt.FlowLayout());
??????????????? // 设置窗体背景颜色
??????????????? this.getContentPane().setBackground(java.awt.Color.black);
??????????????? // 创建文本标签对象
??????????????? text_field = new javax.swing.JLabel();
??????????????? javax.swing.JLabel lable = new javax.swing.JLabel("时? 间? :");
??????????????? // 设置文本标签前景颜色
??????????????? lable.setForeground(java.awt.Color.red);
??????????????? text_field.setForeground(java.awt.Color.red);

??????????????? // 创建进度条对象
??????????????? pBar = new javax.swing.JProgressBar(0, 330);
??????????????? // 创建按钮对象
??????????????? button = new javax.swing.JToggleButton();
??????????????? button.setMargin(new Insets(0, 0, 0, 0));
??????????????? button.setIcon(new javax.swing.ImageIcon("images/Pause.gif"));
??????????????? button.setActionCommand("暂停");
??????????????? // 通过匿名内部类来创建动作监听器
??????????????? java.awt.event.ActionListener button_listener = new java.awt.event.ActionListener() {

精彩图集

赞助商链接