Nope, this won't work. I presume there you're trying to find the keycode of an event, and while a similar model exists in native Java, Greenfoot uses a simpler mechanism.
I also assume by adding 4 to this.x
you aim to move the component horizontally? Again similar concepts exist, but not in that syntax exactly.
In terms of replicating the above, it would be:
if(Greenfoot.getKey().equals("t")) { //Obviously replace t with whatever key you want
setLocation(getX()+4, getY());
}
You should read the Greenfoot API documentation which shows you what methods you have available - if you simply try and crowbar Actionscript syntax into any Java application then fight the compiler until it works, you'll come more than a bit unstuck! While Actionscript and Java aren't too far apart, they're certainly not so similar you can work in that way.