am i missing some thing?
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 53 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class poi here. * * @author (your name) * @version (a version number or a date) */ public class poi extends Actor { public final String LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; public final String letters = "abcdefghijklmnopqrstuvwxyz" ; public final String Numbers = "0123456789" ; public final String Symbols = "`~!@#$%^&*()_+-=[]{}|;':<>?,./" ; public String txtString = "" ; public void act() { String myKey = Greenfoot.getKey(); if (myKey == null ) { return ; } String myText = "" ; if (myKey == "space" ) { myKey = " " ; } // If spaces are not wanted, change 'myKey = " ";' to 'return;' if (myKey == "backspace" ) { // Code for when 'backspace' is pressed if (txtString.length() > 0 ) { txtString = txtString.substring( 0 , txtString.length() - 1 ); } return ; } if (myKey == "enter" ) { // Code for when 'enter' is pressed return ; } // You can continue for other keys: arrow keys, function keys, 'tab' and 'escape' (and any others I may have missed) // Change the concatenation in the following statement to only wanted characters String goodChars = LETTERS + letters + Numbers + Symbols + " " ; int myIndex = goodChars.indexOf(myKey.charAt( 0 )); if (myIndex > - 1 ) { myText = goodChars.substring(myIndex, myIndex + 1 ); txtString = txtString + myText; } new GreenfootImage( 70 , 60 ); // wrong method? drawString(txtString, 60 , 50 ); setImage(txtString); } } |