dispatchEvent对JButton好用,队Button不好用,原因我不知道,你用JButton 试试吧!

解决方案 »

  1.   

    我用的是JAbstractButton的子类。JRadioButtonMenuItem
    dispatchEvent怎么用?我用AWTEvent的子类ActionEvent,但ActionEvent有三个参数,What's mean?
      

  2.   

    一个是发送消息的源对象,一个是命令ID,最后是命令字串。你想构建一个ActionEvent再传给它的响应方法吗?就是这样啊 ^_^
      

  3.   

    一个是发送消息的源对象,一个是命令ID,最后是命令字串。你想构建一个ActionEvent再传给它的响应方法吗?就是这样啊 ^_^
    在AWT的事件机制中,没有把事件发给谁的说法,只有谁来监听这种说法。
      

  4.   

    再帮我看看喽!/*
     * Test2.java
     *
     * Created on 2002年7月23日, 下午3:21
     *//**
     *
     * @author  Qiao Jian-nan
     */
    public class Test2 extends javax.swing.JFrame {
        
        /** Creates new form Test2 */
        public Test2() {
            initComponents();
        }
        
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        private void initComponents() {
            java.awt.GridBagConstraints gridBagConstraints;        jButton1 = new javax.swing.JButton();
            jLabel1 = new javax.swing.JLabel();
            jButton2 = new javax.swing.JButton();        getContentPane().setLayout(new java.awt.GridBagLayout());        addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
                }
            });        jButton1.setText("ChangeUpperText");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });        gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = 1;
            getContentPane().add(jButton1, gridBagConstraints);        jLabel1.setText("WillChangedByNextButton");
            getContentPane().add(jLabel1, new java.awt.GridBagConstraints());        jButton2.setText("WantSendMessageToUpperButton");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton2ActionPerformed(evt);
                }
            });        gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = 2;
            getContentPane().add(jButton2, gridBagConstraints);        pack();
        }    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
            // Add your handling code here:
            jButton1.dispatchEvent( new java.awt.event.ActionEvent( jButton2 , 12 , jButton1.getText() ) );
        }    int clickTimes;
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            // Add your handling code here:
            jLabel1.setText( "Button click " + ++clickTimes+ " times." );
        }
        
        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
        }
        
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            new Test2().show();
        }
        
        
        // Variables declaration - do not modify
        private javax.swing.JButton jButton2;
        private javax.swing.JButton jButton1;
        private javax.swing.JLabel jLabel1;
        // End of variables declaration
        
    }