简体   繁体   English

Java小程序动作监听器

[英]java help applet action listener

Can anyone point me in the right direct to this? 任何人都可以直接指出我的意思吗? I want the actionlistener in a applet to display 1 of 3 parameters in a jlabel retreived from the html file, When the appropriate option is selected from a combo box. 我希望小程序中的actionlistener在从html文件检索的jlabel中显示3个参数中的1个,当从组合框中选择了适当的选项时。

Cheers 干杯

For a combo box you want to add an ItemListener to your combo box to handle the change. 对于组合框,您想向组合框添加一个ItemListener来处理更改。 You should create some sort of controller class (just a regular class which implements ItemListener ) and add this as your listener. 您应该创建某种控制器类(只是一个implements ItemListener的常规类),并将其添加为侦听器。 Then, in the itemStateChanged method, you program your logic. 然后,在itemStateChanged方法中,对逻辑进行编程。 You probably want to give the ItemListener you create a reference to your panel so that it can make the appropriate changes. 您可能想给ItemListener创建一个对面板的引用,以便可以进行适当的更改。

One other note. 另一注。 If you're reading the HTML file on the fly when the drop down is selected, the user interface will freeze up until this operation is complete. 如果在选择下拉菜单时动态读取HTML文件,则用户界面将冻结,直到完成此操作。 This is because these events are fired and executed on the Event Dispatch Thread, the main thread for user interaction. 这是因为这些事件是在事件分发线程(用户交互的主线程)上触发并执行的。 To avoid this, you can either parse the HTML file ahead of time into memory or you can spawn a separate thread in the itemStateChanged event to parse the HTML file. 为避免这种情况,您可以提前将HTML文件解析到内存中,也可以在itemStateChanged事件中生成单独的线程来解析HTML文件。 Just remember, when you're done, to use SwingUtilities.invokeLater to get another runnable back on the Event Dispatch Thread to update the drop down. 只要记住,当您完成操作后,就可以使用SwingUtilities.invokeLater在Event Dispatch Thread上重新获取另一个可运行对象,以更新下拉列表。 All updates to the Swing user interface must be done from within the Event Dispatch Thread. 对Swing用户界面的所有更新都必须在事件调度线程内完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM