Home > Java > javaTutorial > Java pinball game code based on swing

Java pinball game code based on swing

黄舟
Release: 2016-12-24 11:03:22
Original
1989 people have browsed it

The example in this article describes the pinball game code implemented in Java based on swing. Share it with everyone for your reference.

The main function codes are as follows:

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<MyThread> list = new ArrayList<MyThread>();
        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() {
Copy after login

The above is the content of the pinball game code implemented in Java based on swing. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template