如何自己发送消息? dispatchEvent对JButton好用,队Button不好用,原因我不知道,你用JButton 试试吧! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我用的是JAbstractButton的子类。JRadioButtonMenuItemdispatchEvent怎么用?我用AWTEvent的子类ActionEvent,但ActionEvent有三个参数,What's mean? 一个是发送消息的源对象,一个是命令ID,最后是命令字串。你想构建一个ActionEvent再传给它的响应方法吗?就是这样啊 ^_^ 一个是发送消息的源对象,一个是命令ID,最后是命令字串。你想构建一个ActionEvent再传给它的响应方法吗?就是这样啊 ^_^在AWT的事件机制中,没有把事件发给谁的说法,只有谁来监听这种说法。 再帮我看看喽!/* * 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 } oracle中使用union all查询速度变慢? 请帮忙修改一下一段java小代码 这是什么意思啊? 求助: 用jawin的getObject()方法时报80020006:Unknown name错误 一个java小程序 请大家帮小妹一下 多谢了 在线等待 java的c/s架构怎么写啊 ! netscape.javascript.JSObject在IE中不定期出错.在线等..高手请进.. 谁有《java编程思想 第2版》简体完整电子版 如何把int类型的转化成String类型的 船的航行模拟 面向对象 JBuilder下怎样生成可执行文件? 找不到运行环境?????
dispatchEvent怎么用?我用AWTEvent的子类ActionEvent,但ActionEvent有三个参数,What's mean?
在AWT的事件机制中,没有把事件发给谁的说法,只有谁来监听这种说法。
* 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
}