Hi, i've tried everything but i can't seem to set a custom font with the solutions i've found recently. If i try the following code:
Greenfoot won't let me compile the code because 'incompatible types: java.lang.String cannot be converted to boolean'. I find this very confusing because i don't get why it tries to convert to a boolean. Can anyone show an example where the font can be changed?
Here's the rest of the act() if necessary:
1 | notification.setFont( new Font( "Courier New" , java.awt.Font.PLAIN, 12 )); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | public void act() { World world = getWorld(); currentTime=System.currentTimeMillis(); if (currentTime>=timerBegin) { if (currentTime>=timer2Begin) { timer2Begin=timer2Begin+fadeSpeed; transparency=transparency-fadeStepsize; //this is a debugger, it does nothing else but display variables world.removeObjects(world.getObjects(Announcement. class )); world.addObject ( new Announcement( "custom announcement" , "-Terminal window-\n" +transparency), 500 , 500 ); if (transparency<= 0 ) { transparency= 0 ; world.removeObject( this ); } } } else { if (currentTime>=timer2Begin) { //this is a debugger, it does nothing else but display variables world.removeObjects(world.getObjects(Announcement. class )); world.addObject ( new Announcement( "custom announcement" , "-Terminal window-\n" +transparency), 500 , 500 ); timer2Begin=timer2Begin+fadeSpeed; if (isTouching(Rocket. class )) { transparency=transparency-fadeStepsize; if (transparency< 100 ) { transparency= 100 ; } } else { transparency=transparency+fadeStepsize; if (transparency> 255 ) { transparency= 255 ; } } } } GreenfootImage notification = new GreenfootImage( "notificationboard.gif" ); notification.setTransparency(transparency); notification.setFont( new Font( "Courier New" , java.awt.Font.PLAIN, 12 )); notification.drawString(text, 30 , 30 ); setImage(notification); } |