如何创建组合框actionListener? [英] How to create a combo box actionListener?

查看:49
本文介绍了如何创建组合框actionListener?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建组合框动作侦听器? 到目前为止,我有以下内容:

How do I create a combo box action listener? I have the following so far:

myCombo = new JComboBox();
myCombo.addActionListener();

我不确定该如何进行,似乎与按钮所用的有所不同.

I am not sure how to proceed, it seems that it is different from the one used for the buttons.

推荐答案

尝试一下:

 myCombo.addActionListener(new actionListener() {
   public void actionPerformed(ActionEvent eventSource) {
   JComboBox combo = (JComboBox) myCombo.getSource();
   Object selected = combo.getSelectedItem();
   if("whatever...") {

}
}
}
);

这篇关于如何创建组合框actionListener?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆