待辦事項 #14177

ActionPerformed is executed two times when a MenuItem is selected.
啟用日期: 2008-11-30 21:45 最後更新: 2008-12-02 00:22

回報者:
負責人:
類型:
狀態:
開啟 [Owner assigned]
元件:
里程碑:
(無)
優先權:
5 - 中
嚴重程度:
5 - 中
處理結果:
檔案:

細節

Here you have a bug test code.

import java.awt.*;
import java.awt.event.*;

public class TestBug extends Frame implements ActionListener{

    public TestBug(){
	setSize(1024,1280);
	MenuBar menuBar = new MenuBar();
	Menu menu = new Menu("Menú");
	menu.addActionListener(this);

	MenuItem mi;
	mi = new MenuItem("Exit");
	mi.addActionListener(this);
	menu.add(mi);
	mi = new MenuItem("TEST");
	mi.addActionListener(this);
	menu.add(mi);
	menuBar.add(menu);
	setMenuBar(menuBar);
	show();
    }

    public static void main(String[] args) {
	new TestBug();
    }

    public void actionPerformed(ActionEvent e) {
	String command = e.getActionCommand();
	if (command.equals("Exit")) {
	    dispose();
	    System.exit(0);
	}else if (command.equals("TEST")) {
	    System.out.println("TEST SELECTED");
	}
    }
}


Ticket History (3/4 Histories)

2008-11-30 21:45 Updated by: freebeans
  • New Ticket "ActionPerformed is executed two times when a MenuItem is selected." created
2008-12-01 08:37 Updated by: freebeans
評語

デバッグ文を入れてみたところ、WCEMenuItemPeer.postActionEvent()は1回だけ呼び出されていることが分かった。少なくとも、ネイティブライブラリからは1回しかイベントが発生していない模様。 ほかの部分に原因があると考えられる。

2008-12-02 00:22 Updated by: freebeans
評語

Menuとそこにadd()されているMenuItemの両方にActionListenerを登録した場合、イベントはMenuとMenuItemの両方から通知される。 しかし、Windows XP上のJDKだと、1回しか通知されない。 OpenJDKのソースとGNU Classpathのソースとを比べてみる。

2008-12-02 21:53 Updated by: None
評語

I think this is a bug of GNU Classpath. I reported to Bugzilla. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38372

Attachment File List

No attachments

編輯

Please login to add comment to this ticket » 登入