我怎么知道哪个JProgressBar引发了这个事件呢?

时间:2015-06-05 21:07:30

标签: java user-interface

我有两个JProgressBar,但不知道哪个是知道哪个是引发事件的。 使用e.getPropertyName()都将返回进度

public void propertyChange(PropertyChangeEvent e) {

    if(e.getPropertyName().equals("progress")){
        int progreso =(Integer)e.getNewValue();
        panel.progreso(progreso);
    }

}

尝试这样做

 public void propertyChange(PropertyChangeEvent e) {

    if(e.getSource().getClass().getName().equals("WorkerMontecarlo")){
        int progreso =(Integer)e.getNewValue();
        panel.progreso(progreso);
    }
}

但在运行时我收到以下错误

线程中的异常" AWT-EventQueue-0" java.lang.ClassCastException:javax.swing.SwingWorker $ StateValue无法强制转换为java.lang.Integer     在Controlador.propertyChange(Controlador.java:43)     在java.beans.PropertyChangeSupport.fire(未知来源)     在java.beans.PropertyChangeSupport.firePropertyChange(未知来源)     在javax.swing.SwingWorker $ SwingWorkerPropertyChangeSupport.firePropertyChange(未知来源)     在javax.swing.SwingWorker $ SwingWorkerPropertyChangeSupport $ 1.run(未知来源)     在javax.swing.SwingWorker $ DoSubmitAccumulativeRunnable.run(未知来源)     at sun.swing.AccumulativeRunnable.run(Unknown Source)     at javax.swing.SwingWorker $ DoSubmitAccumulativeRunnable.actionPerformed(Unknown Source)     在javax.swing.Timer.fireActionPerformed(未知来源)     在javax.swing.Timer $ DoPostEvent.run(未知来源)     at java.awt.event.InvocationEvent.dispatch(Unknown Source)     at java.awt.EventQueue.dispatchEventImpl(Unknown Source)     在java.awt.EventQueue.access $ 500(未知来源)     在java.awt.EventQueue $ 3.run(未知来源)     在java.awt.EventQueue $ 3.run(未知来源)     at java.security.AccessController.doPrivileged(Native Method)     at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(Unknown Source)     at java.awt.EventQueue.dispatchEvent(Unknown Source)     at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)     at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)     at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)     在java.awt.EventDispatchThread.run(未知来源)

0 个答案:

没有答案