【发布时间】:2016-12-04 19:01:01
【问题描述】:
每次按下图像时我都会尝试点亮,如果再次按下它,我希望它转到原始照明
// Effect To light up the image once it been pressed to green
Lighting lighting = new Lighting();
lighting.setDiffuseConstant(1.0);
lighting.setSpecularConstant(0.0);
lighting.setSpecularExponent(0.0);
lighting.setSurfaceScale(0.0);
lighting.setLight(new Light.Distant(45, 45, Color.GREEN));
// Effect to show the unavailable images which can't be pressed
Lighting lighting_red = new Lighting();
lighting_red.setDiffuseConstant(1.0);
lighting_red.setSpecularConstant(0.0);
lighting_red.setSpecularExponent(0.0);
lighting_red.setSurfaceScale(0.0);
lighting_red.setLight(new Light.Distant(45, 45, Color.RED));
// the original effect and the one to change back the green effect once it being pressed again
Lighting orginalLighting = new Lighting();
orginalLighting.setDiffuseConstant(1.0);
orginalLighting.setSpecularConstant(0.0);
orginalLighting.setSpecularExponent(0.0);
orginalLighting.setSurfaceScale(0.0);
orginalLighting.setLight(new Light.Distant(85, 85, Color.LIGHTGREY));
// To initialize the original imageview and set its original effect
for(int i = 0;i<30;i++){
seats[i] = new ImageView(seats_image);
seats[i].setEffect(orginalLighting);
}
for(int i=0;i<30;i++){
Node seat = seats[i];
seat.setOnMouseClicked(e->{
if(seat.getEffect()!=lighting_red){
seat.setEffect(lighting); }
if(seat.getEffect()==lighting){
seat.setEffect(orginalLighting); }
});
}
如果不是红色到绿色,我想改变图像效果。如果我已经按下它并再次按下它以恢复原始效果,但不知何故,一旦我按下任何图像,什么都没有改变。
提示:如果我删除第二个 if,只要它不是红色,只要按下它,图像就会变为绿色。但是,一旦我添加了第二个,如果根本没有发生任何事情,似乎每次按下它都会更改为原始图像,而图像中没有任何变化
【问题讨论】:
-
不要用
!=和==比较对象,而是用equals方法。这可能会有所帮助。 -
@hotzst 没用