Monday 15 April 2013

Conditional statement using accessor methods in Java -


My _holder.getColor () is considered to be red red by default and These conditional statements are not working I think I have a syntax wrong

Actually I want to be able to highlight a paintwatch when I click on it, and if switch color one If it is the same as ColorHolder , then I want to deselect it Swatch.

  Import wheels.users. *; Import java.awt.color; Import java.awt.event.MouseEvent; Public class paintwatch oval {personal color holder _holder; Public int _i; Public PaintSwitch (Color C, Color Holder Holder) {Super (C); _holder = holder; _i = 1; } Public Zero MouseClicked (MouseEvent E) {If (_holder.getColor () !: Super.getColor ()) {super.setFrameColor (Color.BLACK); Super.setFrameThickness (3); _holder.setColor (super.getColor ()); } If (_holder.getColor () == Super.Gate Coiler ()) {Super. SetFrameTenches (10); Super.setFrameColor (Color.WHITE); _holder.setColor (Color.RED); }}}   

Here is my colorhold class:

  import java.awt.color; Public Class Color Holder Color {Personal Color _currentColor; Public ColorHolder () {_currentColor = Color.RED; } Public color getColor () {back _currentColor; } Public Zero Set Collar (Color C) {_currentColor = c; }}    

In addition to using par, you can choose one And should use ifs:

  if (_holder.getColor ()! = Super.getColor ()) {... _holder.setColor (super.getColor ()); } If (_holder.getColor () == super.getColor ()) {...}   

Note that the second condition will always evaluate the truth - if the holder is not the color Equal to the color of the super, if it will be set in the first position.

  if (_holder.getColor (.) Equals (super.getColor ())) {... do sth} else {... do sth else}   

Also make sure that neither the patient nor the super color return to the null or check it out clearly.

No comments:

Post a Comment