나는 이미지를 누르면 그것을 다시 누르면 됐어요 경우 경우에 나는 그것이 내가 변경을 원자바 FX
// 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
@hotzst가 작동하지 않았습니다 – MrRizk