java从另一个动作调用动作
countresultsfrom.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
Color orginalColor = mcoef.getBackground();
switch(countresultsfrom.getSelectedIndex())
{
case 0: // Mech Cnt;
mtotal.setBackground(Color.YELLOW);
if(mstatus.getSelectedIndex() == 2)
{
countresultsfrom.setSelectedIndex(2);
// countresultsfrom <----- CALL EVENT ???
}
etotal.setBackground(orginalColor);
ctotal.setBackground(orginalColor);
break;
case 1: // El Cnt;
etotal.setBackground(Color.YELLOW);
if(estatus.getSelectedIndex() == 2)
{
countresultsfrom.setSelectedIndex(2);
}
mtotal.setBackground(orginalColor);
ctotal.setBackground(orginalColor);
break;
case 2:
ctotal.setBackground(Color.YELLOW);
etotal.setBackground(orginalColor);
mtotal.setBackground(orginalColor);
break;
}
}
});
如何再次调用监听者???
countresultsfrom.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
Color orginalColor = mcoef.getBackground();
switch(countresultsfrom.getSelectedIndex())
{
case 0: // Mech Cnt;
mtotal.setBackground(Color.YELLOW);
if(mstatus.getSelectedIndex() == 2)
{
countresultsfrom.setSelectedIndex(2);
// countresultsfrom <----- CALL EVENT ???
}
etotal.setBackground(orginalColor);
ctotal.setBackground(orginalColor);
break;
case 1: // El Cnt;
etotal.setBackground(Color.YELLOW);
if(estatus.getSelectedIndex() == 2)
{
countresultsfrom.setSelectedIndex(2);
}
mtotal.setBackground(orginalColor);
ctotal.setBackground(orginalColor);
break;
case 2:
ctotal.setBackground(Color.YELLOW);
etotal.setBackground(orginalColor);
mtotal.setBackground(orginalColor);
break;
}
}
});
how to call listener one more time ???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
yourListener.actionPerformed(/*some event*/ e)
。请注意,它不会作为事件处理,而是作为常规方法调用处理。yourListener.actionPerformed(/*some event*/ e)
. Note that it will not be handled as an event, but as a regular method call.首先,将执行操作的方法提取到代码中的单独类中。它可能是您希望调用的同一类中的私有静态类。例如
,并在 countresultsfrom 按钮的 addActionListener 中传递此类的实例。
First of all extract your action performed method to a separate class in your code. It could be a private static class in the same class you wish to call. e.g
and pass an instance of this class in the addActionListener of your countresultsfrom button.
你的描述对我来说不清楚,但基本上有两种方法
1/ 创建自己的
Class someName Implements ActionListener
2/ 创建
java.swing.Action
一些示例操作编辑:
如果您的 countresultsfrom 是 JList,那么我们所有的建议(也许)根本不正确 http://download.oracle.com/javase/tutorial/uiswing/components/list.html
your descriptions isn't clear for me, but there is basicall two ways
1/ create own
Class someName implements ActionListener
2/ create
java.swing.Action
some examples for that on ActionEDIT:
if your countresultsfrom is JList, then all ours advices (maybe) didn't correct at all http://download.oracle.com/javase/tutorial/uiswing/components/list.html
您是否希望每个操作都调用
actionPerformed(ActionEvent e)
两次?如果是这样,请将以
Color orinalColor = mcoef.getBackground()
开头的块包装在 for 循环中。for (int i=0; i<2; i++) { ... }
Do you wish
actionPerformed(ActionEvent e)
to be invoked twice on every action?If so, wrap the block starting with
Color orginalColor = mcoef.getBackground()
in a for-loop.for (int i=0; i<2; i++) { ... }