2019-03-27 DDS

import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.EventQueue;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.Serializable;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;
import javax.swing.JProgressBar;
import javax.swing.Timer;
import javax.swing.border.TitledBorder;
import java.awt.Color;


public class DDS extends JFrame implements Runnable, MouseListener, ActionListener {

    /**
     * 
     */
    private Score[] sc;   //英雄榜序列化对象数组
    private static final long serialVersionUID = 1L;
    private JPanel contentPane;
    private JLabel lm[];
    private JLabel lscore;
    Thread  t;
    private int score=0;
    private Cursor c1,c2;
    private AudioClip clip1,clip2;
    private JMenuItem mon,moff;
    private JProgressBar progressBar;
    private Timer timer;
    private JMenuItem mstart;
    private boolean threadStarted = false;
    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    DDS frame = new DDS();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    static class Score implements Serializable{
        /**
         *英雄榜类 
         */
        private static final long serialVersionUID = 1L;
        String id;
        int score;
        Score()
        {
            id="匿名";
            score=0;
        }
    }
    public DDS() {
        setResizable(false);
        setTitle("\u6253\u5730\u9F20\u6E38\u620F");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100,506, 577);
        
        JMenuBar menuBar = new JMenuBar();
        setJMenuBar(menuBar);
        
        JMenu gameControl = new JMenu("\u6E38\u620F\u63A7\u5236");
        menuBar.add(gameControl);
        
        mstart = new JMenuItem("\u5F00\u59CB");
        mstart.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                if(threadStarted==false) t.start();
                timer.start();
                progressBar.setString(null);
                mstart.setEnabled(false);
            }
        });
        gameControl.add(mstart);
        
        JMenuItem mpause = new JMenuItem("\u6682\u505C");
        mpause.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                t.suspend();
            }
        });
        gameControl.add(mpause);
        
        JMenuItem mcontinue = new JMenuItem("\u7EE7\u7EED");
        mcontinue.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                t.resume();
            }
        });
        gameControl.add(mcontinue);
        
        JMenuItem mexit = new JMenuItem("\u9000\u51FA");
        mexit.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        gameControl.add(mexit);
        
        JMenu mnNewMenu_1 = new JMenu("\u80CC\u666F\u97F3\u4E50");
        menuBar.add(mnNewMenu_1);
        
        mon = new JMenuItem("ON");
        mon.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                clip1.loop();
                mon.setEnabled(false);
                moff.setEnabled(true);
            }
        });
        mnNewMenu_1.add(mon);
        
        moff = new JMenuItem("OFF");
        moff.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                clip1.stop();
                mon.setEnabled(true);
                moff.setEnabled(false);
            }
        });
        mnNewMenu_1.add(moff);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);
        
        lscore = new JLabel("\u5F97\u5206");
        lscore.setFont(new Font("幼圆", Font.PLAIN, 36));
        lscore.setBounds(215, 31, 270, 57);
        contentPane.add(lscore);
        
        progressBar = new JProgressBar();
        progressBar.setMaximum(10);
        progressBar.setStringPainted(true);
        progressBar.setBorder(new TitledBorder(null, "\u6E38\u620F\u8FDB\u5EA6", TitledBorder.CENTER, TitledBorder.ABOVE_TOP, null, Color.RED));
        progressBar.setBounds(0, 29, 186, 59);
        contentPane.add(progressBar);
        
        JLabel im1 = new JLabel("");
        im1.setIcon(new ImageIcon(this.getClass().getResource("mouse.png")));
        im1.setBounds(240, 408, 63, 67);
        contentPane.add(im1);
        
        JLabel im3 = new JLabel("");
        im3.setIcon(new ImageIcon(this.getClass().getResource("mouse.png")));
        im3.setBounds(250, 304, 63, 67);
        contentPane.add(im3);
        
        JLabel im4 = new JLabel("");
        im4.setIcon(new ImageIcon(this.getClass().getResource("mouse.png")));
        im4.setBounds(192, 363, 63, 67);
        contentPane.add(im4);
        
        JLabel im5 = new JLabel("");
        im5.setIcon(new ImageIcon(this.getClass().getResource("mouse.png")));
        im5.setBounds(104, 335, 63, 67);
        contentPane.add(im5);
        
        JLabel im6 = new JLabel("");
        im6.setIcon(new ImageIcon(this.getClass().getResource("mouse.png")));
        im6.setBounds(240, 263, 63, 67);
        contentPane.add(im6);
        
        JLabel im7 = new JLabel("");
        im7.setIcon(new ImageIcon(this.getClass().getResource("mouse.png")));
        im7.setBounds(389, 304, 63, 67);
        contentPane.add(im7);
        
        JLabel im8 = new JLabel("");
        im8.setIcon(new ImageIcon(this.getClass().getResource("mouse.png")));
        im8.setBounds(358, 363, 63, 67);
        contentPane.add(im8);
        
        JLabel im2 = new JLabel("");
        im2.setIcon(new ImageIcon(this.getClass().getResource("mouse.png")));
        im2.setBounds(337, 263, 63, 67);
        contentPane.add(im2);
        
        JLabel lback = new JLabel("New label");
        lback.setIcon(new ImageIcon(this.getClass().getResource("background.jpg")));
        lback.setBounds(0, 0, 500, 515);
        contentPane.add(lback);
        
        lm = new JLabel[8];
        lm[0]=im1;
        lm[1]=im2;
        lm[2]=im3;
        lm[3]=im4;
        lm[4]=im5;
        lm[5]=im6;
        lm[6]=im7;
        lm[7]=im8;
        
        for(int i=0;i

你可能感兴趣的:(2019-03-27 DDS)