怎么实现java按钮的播放与暂停,按一次就是暂停,按一次就是播放?

import java.awt.EventQueue;
import java.io.*;
import java.util.*;
import javax.swing.JFrame;
import javax.swing.JSlider;
import javax.swing.JButton;
import javax.media.*;
import java.applet.*;
import jmapps.ui.JMFrame;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JList;
import javax.swing.JTextArea;
import javax.swing.JSpinner;
import javax.swing.JComboBox;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.*;
import jmapps.jmstudio.CaptureDialog;
import jmapps.ui.PlayerFrame;
import jmapps.util.CDSWrapper;
import jmapps.util.JMFUtils;
public class bofangqi extends Applet implements ControllerListener{

private JFrame frame;
//播放对象
    private Player player;
    //是否循环播放
    private boolean first,loop;
    //文件路径
    private String path;
    //存放MP3文件
    private List<String> mp3List;
    //当前MP3文件数量
    private int mp3NO=0;
    public boolean i=true;

    bofangqi(List<String> mp3List)
    {
        this.mp3List=mp3List;
    }
/**
 * Launch the application.
 */
    //播放方法
    public void start()
    {
        try {
            player = Manager.createPlayer(new File(mp3List.get(mp3NO)).toURI().toURL());
        } catch (NoPlayerException e) {
            // TODO 自动生成 catch 块
            e.printStackTrace();
            System.out.println("不能播放此文件!");
            return;
        } catch (IOException e) {
            // TODO 自动生成 catch 块
            e.printStackTrace();
            return;
        } 
        if(player==null)
        {
            System.out.println("播放文件为空!");
            return;
        }
        player.addControllerListener(this);
        //提取媒体内容
        player.prefetch();
    }

public void controllerUpdate(ControllerEvent e) {
        //当媒体播放结束时,循环播放
        if(e instanceof EndOfMediaEvent)
        {
            mp3NO++;
            System.out.println(mp3NO);
            if(mp3NO<mp3List.size())
            {

                this.start();
            }
            return;
        }

            //当提取媒体的内容结束 
        if (e instanceof PrefetchCompleteEvent) { 
            System.out.println("内容结束");
            player.start(); 

            return; 
        } 

            //当实例化后 
        if (e instanceof RealizeCompleteEvent) { 
            System.out.println("实例化");
            //pack(); //执行pack()操作 
            return; 
        } 

}
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                bofangqi window = new bofangqi();
                window.frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    List<String> path=new ArrayList<String>();
    path.add("C:\\Users\\Administrator.P5LPMC6WDCYRLP5\\Music\\无言无语.mp3");
    path.add("C:\\Users\\Administrator.P5LPMC6WDCYRLP5\\Music\\美丽之景.mp3");
    path.add("C:\\Users\\Administrator.P5LPMC6WDCYRLP5\\Music\\你的名字我的姓氏.mp3");
    bofangqi play=new bofangqi(path);
    play.start();


}

/**
 * Create the application.
 */
public bofangqi() {
    initialize();
}

/**
 * Initialize the contents of the frame.
 */
public void initialize() {
    frame = new JFrame();
    frame.setBounds(100, 100, 382, 361);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(null);


    JButton btnNewButton = new JButton("\u524D\u4E00\u9996");
    btnNewButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if(mp3NO<0)
            {
            mp3NO=mp3List.size()-1;

            }
            else{
                mp3NO--;

            }
        }
    });
    btnNewButton.setBounds(27, 64, 93, 23);
    frame.getContentPane().add(btnNewButton);

    final JButton btnNewButton_1 = new JButton("\u6682\u505C");
    btnNewButton_1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            if(i==true) {btnNewButton_1.setText("播放");
             i=false;
             player.notify();
            }
            else {btnNewButton_1.setText("暂停");
            i=true;}
        }
    });
    btnNewButton_1.setBounds(130, 64, 93, 23);
    frame.getContentPane().add(btnNewButton_1);

    JButton btnNewButton_2 = new JButton("\u4E0B\u4E00\u9996");
    btnNewButton_2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
        }
    });
    btnNewButton_2.setBounds(235, 64, 93, 23);
    frame.getContentPane().add(btnNewButton_2);
}

}

统计点击次数呗,或者做一个TAG记录播放还是暂停状态,这个应该很好解决吧

设置一个状态标志位,每次触发按键事件时依据状态标志的值执行不同的操作;
你这个就两个状态,当状态‘播放’就执行 暂停操作,并将状态位置 ‘暂停’;反之亦然
祝你好运