简体   繁体   English

Java:在当前目标上应用样式的方法

[英]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.

相关问题 有没有一种方法可以将样式应用于ap:selectManyMenu中的列? - Is there a way to apply styles to columns in a p:selectManyMenu? 在运行的Java应用程序中更改CSS样式的方法 - Way of changing CSS styles in a running Java app 在这个特定问题中应用 inheritance 的 Java 方法是什么? - What is the Java way to apply inheritance in this particular problem? 我必须使用哪个摆动组件才能在Java的同一字段中应用不同样式的文本 - which swing component i must use to apply different styles of text in a same field in java 如何应用 styles 在带有 Netbeans Java 编辑器工具包(Javakit)的 JEditorPane 中进行语法着色? - How do I apply styles to do syntax coloring in a JEditorPane with Netbeans Java editor kit (Javakit)? 将样式应用于字符串Android中的文本 - Apply styles to text in a string Android Java:确定当前Windows用户的程序化方法 - Java: Programatic Way to Determine Current Windows User 当前生成MD5哈希的方法(Java 8/9) - Current way of generating MD5 hash (Java 8/9) 快速获取Java中当前Calendar对象的方法 - Fast way to get the current Calendar object in Java 有没有更好的方法来获取java中的当前类变量? - Is there a better way to get the current class variable in java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM