[英]Java: Way to apply styles on current target
Is there a method to apply styles or transformation to a component when targeted it with an event (eg: mouse_click) like in AS3? 是否有风格或转换应用 到组件的方法时,与事件有针对性它(例如:mouse_click)就像在AS3?
AS3 example use: AS3示例使用:
...
event.currentTarget.setX(50);
...
In my code, I do compare all the targeted components to know on any one of them I should apply the style. 在我的代码中,我确实比较了所有目标组件,以了解在其中任何一种组件上我都应该应用样式。 Like this:
像这样:
...
If(event.getTarget().equals(lbl_menu1))
{
lbl_menu1.setLayoutX(50);
}
else If(event.getTarget().equals(lbl_menu2))
{
lbl_menu2.setLayoutX(50);
}
...
But I feel this is a very bad idea. 但是我觉得这是一个非常糟糕的主意。
I do compare all the targeted components
我会比较所有目标组件
Why are you doing that? 你为什么要这么做? You aren't doing it in As3 either.
您也不会在As3中执行此操作。
event.getTarget().setLayoutX(50);
is the equivalent line in Java
. 是
Java
的等效行。 To make it work, you have to cast event.getTarget()
to some type that has a method .setLayoutX(50)
. 为了使其工作,必须将
event.getTarget()
为具有方法.setLayoutX(50)
某种类型。
Only call the method if the cast succeeds. 如果强制转换成功,则仅调用该方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.