永发信息网

NetBeans如何删除监听事件?

答案:2  悬赏:10  手机版
解决时间 2021-04-04 00:01
  • 提问者网友:椧運幽默
  • 2021-04-03 20:42
我通过右键添加了一个按钮的点击事件,但不知道如何取消。

大哥,你确定是esc?
最佳答案
  • 五星知识达人网友:独行浪子会拥风
  • 2021-04-03 20:54
那不关退出键的事,但只要不在你加的这个事件里写什么就没事,应该有代码生成,你如果不消掉心里不舒服就在代码里把那个你加进的buttonClicked事件删掉就行,其实你不删也没事的,不影响什么的
全部回答
  • 1楼网友:持酒劝斜阳
  • 2021-04-03 21:38
package javaapplication5; import javax.swing.comboboxmodel; import javax.swing.event.listdatalistener; public class newjframe extends javax.swing.jframe { public newjframe() { initcomponents(); } @suppresswarnings("unchecked") // private void initcomponents() { jcombobox1 = new javax.swing.jcombobox(); jcombobox2 = new javax.swing.jcombobox(); setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close); jcombobox1.setmodel(new javax.swing.defaultcomboboxmodel(new string[] { "a", "b", "c" })); jcombobox1.additemlistener(new java.awt.event.itemlistener() { public void itemstatechanged(java.awt.event.itemevent evt) { jcombobox1itemstatechanged(evt); } }); jcombobox2.setmodel(new javax.swing.defaultcomboboxmodel(new string[] { "1", "2", "3" })); javax.swing.grouplayout layout = new javax.swing.grouplayout(getcontentpane()); getcontentpane().setlayout(layout); layout.sethorizontalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addgap(33, 33, 33) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.trailing, false) .addcomponent(jcombobox2, javax.swing.grouplayout.alignment.leading, 0, javax.swing.grouplayout.default_size, short.max_value) .addcomponent(jcombobox1, javax.swing.grouplayout.alignment.leading, 0, 123, short.max_value)) .addcontainergap(244, short.max_value)) ); layout.setverticalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addgap(38, 38, 38) .addcomponent(jcombobox1, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size) .addgap(31, 31, 31) .addcomponent(jcombobox2, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size) .addcontainergap(189, short.max_value)) ); pack(); }// private void jcombobox1itemstatechanged(java.awt.event.itemevent evt) { string value = jcombobox1.getselecteditem().tostring(); if(value.equals("a")){ jcombobox2.setmodel(new javax.swing.defaultcomboboxmodel(new string[] { "1", "2", "3" })); } else if(value.equals("b")){ jcombobox2.setmodel(new javax.swing.defaultcomboboxmodel(new string[] { "4", "5", "6" })); } else if(value.equals("c")){ jcombobox2.setmodel(new javax.swing.defaultcomboboxmodel(new string[] { "7", "8", "9" })); } } public static void main(string args[]) { java.awt.eventqueue.invokelater(new runnable() { public void run() { new newjframe().setvisible(true); } }); } // variables declaration - do not modify private javax.swing.jcombobox jcombobox1; private javax.swing.jcombobox jcombobox2; // end of variables declaration }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯