Java中是否有监听器来处理某个线程已结束?像这样:Futuretest=workerPool.submit(newTestCalalble());test.addActionListener(newActionListener(){publicvoidactionEnd(ActionEvente){txt1.setText("Button1clicked");}});我知道,这样处理是不可能的,但我想在某个线程结束时得到通知。通常我将这个Timer类用于检查每个Future的状态。但这不是很好的方法。谢谢 最佳答案 有Comple
我有一个带有三个JButton的JFrame。我已将txtSearch(一个JTextField组件)设置为在加载JFrame时获得焦点。其中一个按钮被设置为默认按钮。这是我的代码:privatevoidformWindowOpened(java.awt.event.WindowEventevt){//btnRefresh.setMnemonic(KeyEvent.VK_R);//Evenifthisline//isnotcommented,but//stilltheeventwouldn'tfire.this.getRootPane().setDefaultButton(btnRef
实现java.awt.event.ActionListener接口(interface)的最佳方法是什么?让您的类实现ActionListener并将其添加为ActionListener:classFooimplementsActionListener{publicFoo(){JButtonbutton=newJButton();button.addActionListener(this);}publicvoidactionPerformed(ActionEvente){}}或者添加一个匿名ActionListener类的对象:classFoo{publicFoo(){JButtonb
编译代码后出现两个错误。错误是:1.localvariableinputisaccessedwithininnerclass;needstobedeclaredfinalStringname=input.getText();2.localvariablec_ageisaccessedwithininnerclass;needstobedeclaredfinalObjectchild_age=c_age.getSelectedItem();这是我的代码:importjavax.swing.*;importjava.awt.event.*;publicclassGUI{publicstat
ActionListener和ItemListener都用于通过JCheckBox触发事件?那么,它们之间有什么区别?在哪种情况下,它们中的一个比另一个更受欢迎? 最佳答案 ItemListener和ActionListener,在JCheckBox的情况下具有相同的行为。但是,主要区别在于ItemListener可以通过调用复选框上的setSelected(true)来触发。作为一种编码习惯,不要将ItemListener和ActionListener都注册到JCheckBox,以避免不一致。
ActionListener和ItemListener都用于通过JCheckBox触发事件?那么,它们之间有什么区别?在哪种情况下,它们中的一个比另一个更受欢迎? 最佳答案 ItemListener和ActionListener,在JCheckBox的情况下具有相同的行为。但是,主要区别在于ItemListener可以通过调用复选框上的setSelected(true)来触发。作为一种编码习惯,不要将ItemListener和ActionListener都注册到JCheckBox,以避免不一致。
我有一个在xml中声明的编辑文本,具有以下属性,并且我设置了android:imeOptions="actionNext"在代码中,我添加了这样的编辑器Action监听器。publicbooleanonEditorAction(TextViewv,intactionId,KeyEventevent{if(actionId==EditorInfo.IME_ACTION_DONE||actionId==EditorInfo.IME_ACTION_NEXT){listener.onActionDone(option,etOption);}在ApiactionId作为EditorInfo.IM
最初我有一个JFrame有3个按钮:单击时,哪个按钮0打印0,按钮1打印1,依此类推:JFramejframe=newJFrame();jframe.getContentPane().setLayout(newGridLayout(3,1));for(inti=0;i由于最终变量,我想减少1行,因此重构循环:JFramejframe=newJFrame();jframe.getContentPane().setLayout(newGridLayout(3,1));for(finalint[]arr={0};arr[0]但是这次,所有按钮打印3甚至按钮索引仍然为0,1,2,原因是什么?看答案循环
我目前正在编写一个模板Java应用程序,并且如果我想完全遵循MVC模式,就不确定以何种方式接收ActionListeners。该示例基于Swing,但与框架无关,而是与Java中使用任何框架创建GUI的MVC的基本概念有关。我从一个绝对简单的应用程序开始,该应用程序包含一个JFrame和一个JButton(以放置框架,从而关闭该应用程序)。此帖子后面的代码。没什么特别的,只是为了澄清我们在说什么。我还没有开始使用Model,因为这个问题困扰了我太多。已经有一个以上类似的问题,例如:MVCpatternwithmanyActionListenersJavaswing-Whereshoul
privateJButtonjBtnDrawCircle=newJButton("Circle");privateJButtonjBtnDrawSquare=newJButton("Square");privateJButtonjBtnDrawTriangle=newJButton("Triangle");privateJButtonjBtnSelection=newJButton("Selection");如何向这些按钮添加Action监听器,以便从主方法中我可以对它们调用actionperformed,以便在单击它们时可以在我的程序中调用它们? 最佳答案