解决方案 »

  1.   

    你应该学习下SwingWorker这个类;使用netbeans而不是Eclipse、Idea。
      

  2.   

    写了个列子,直接运行可以看到多个按钮触发自身事件,没有卡顿。
    import java.awt.Container;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Date;import javax.swing.JButton;
    import javax.swing.JFrame;public class Window {
    JFrame aq;
    JButton a1, a2; public static void main(String args[]) {
    Window ll = new Window();
    } public Window() {
    JFrame aq = new JFrame("ButtonTest");
    aq.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    a1 = new JButton("0");
    a2 = new JButton("1"); Container af = aq.getContentPane();
    af.setLayout(new GridLayout(2, 1));
    af.add(a1);
    af.add(a2);
    ActionListener ajj = new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) { String rn = e.getActionCommand();
    System.out.println(rn);
    if (rn == "0") {
    System.out.println("0 clicked!"); Runnable r = new Runnable() {
    @Override
    public void run() {
    int i = 0;
    while (i < 10) {
    i++;
    System.out.println("0 : " + new Date());
    try {
    Thread.sleep(1000);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    } }
    }; Thread t = new Thread(r);
    t.start();


    if (rn == "1") {
    System.out.println("1 clicked!");
    Runnable r = new Runnable() {
    @Override
    public void run() {
    int i = 0;
    while (i < 10) {
    i++;
    System.out.println("1 : " + new Date());
    try {
    Thread.sleep(1000);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    } }
    }; Thread t = new Thread(r);
    t.start();
    } }
    };

    a1.addActionListener(ajj);
    a2.addActionListener(ajj); aq.pack();
    aq.setVisible(true);
    }
    };
      

  3.   

    Quote: 引用 9 楼 huxiweng 的回复:

    写了个列子,直接运行可以看到多个按钮触发自身事件,没有卡顿。谢谢!我基础太薄弱了,现在在努力学习基础当中!此问题后面我会决解!