This is my text file I would like to make a caesar cipher. Can you tell me what to add?
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; /** * Write a description of class TextField here. * * @author (your name) * @version (a version number or a date) */ public class TextField extends Actor { private boolean active = false ; private boolean cursorActive = false ; private boolean displayKeyNames; private boolean enabled = true ; private static int activeTextField = 1 ; private int textFieldNumber; private int textFontSize; private int cursorPosition = 0 ; private long cursorTime = System.currentTimeMillis(); private String input = "" ; private String text = "" ; private String temp = "" ; private Color bgColor = Color.white; private Color textColor = Color.black; /** * Creates a new TextField of a default size of 250 x 50 with black letters on white background. */ public TextField() { this ( 250 , 50 , false , true , Color.white, Color.black, "" ); } /** * Creates a new TextField with a default size of 250 x 50 with black letters on white background and a starting text. * * @param text * The text that is shown directly. */ public TextField(String text) { this ( 250 , 50 , false , true , Color.white, Color.black, text); } /** * Creates a new TextField with a default size of 250 x 50 with black letters on white background and a starting text. * * @param text * The text that is shown directly. * * @param enabled * If you want the textfield to be enabled (able to write in it) this boolean has to be true. */ public TextField(String text, boolean enabled) { this ( 250 , 50 , false , enabled, Color.white, Color.black, text); } /** * Creates a new TextField of the given size with black letters on white background. * * @param width * The TextFields width (which has to be greater than 50). * * @param height * The TextFields height (which has to be greater than 20). */ public TextField( int width, int height) throws IllegalArgumentException { this (width, height, false , true , Color.white, Color.black, "" ); } /** * Creates a new TextField of the given size with black letters on white background. * * @param width * The TextFields width (which has to be greater than 50). * * @param height * The TextFields height (which has to be greater than 20). * * @param enabled * If you want the textfield to be enabled (able to write in it) this boolean has to be true. */ public TextField( int width, int height, boolean enabled) throws IllegalArgumentException { this (width, height, false , enabled, Color.white, Color.black, "" ); } /** * Creates a new TextField of the given size with black letters on white background and a starting text. * * @param width * The TextFields width (which has to be greater than 50). * * @param height * The TextFields height (which has to be greater than 20). * * @param text * The text that is shown directly. */ public TextField( int width, int height, String text) throws IllegalArgumentException { this (width, height, false , true , Color.white, Color.black, text); } /** * Creates a new TextField of the given size with black letters on white background and a starting text. * * @param width * The TextFields width (which has to be greater than 50). * * @param height * The TextFields height (which has to be greater than 20). * * @param displayKeyNames * If you want to use the textfield for only one key this parameter has to be true. * * @param text * The text that is shown directly. */ public TextField( int width, int height, boolean displayKeyNames, String text) throws IllegalArgumentException { this (width, height, displayKeyNames, true , Color.white, Color.black, text); } /** * Creates a new TextField of the given size and the given colors. * * @param width * The TextFields width (which has to be greater than 50). * * @param height * The TextFields height (which has to be greater than 20). * * @param bgColor * The color of the TextFields background. * * @param textColor * The color of the text. */ public TextField( int width, int height, Color bgColor, Color textColor) throws IllegalArgumentException { this (width, height, false , true , bgColor, textColor, "" ); } /** * Creates a new TextField of the given size and the given colors. * * @param width * The TextFields width (which has to be greater than 50). * * @param height * The TextFields height (which has to be greater than 20). * * @param displayKeyNames * If you want to use the textfield for only one key this parameter has to be true. * * @param bgColor * The color of the TextFields background. * * @param textColor * The color of the text. */ public TextField( int width, int height, boolean displayKeyNames, Color bgColor, Color textColor) throws IllegalArgumentException { this (width, height, false , true , bgColor, textColor, "" ); } /** * Creates a new TextField of the given size, the given colors and a starting text. * * @param width * The TextFields width (which has to be greater than 50). * * @param height * The TextFields height (which has to be greater than 20). * * @param bgColor * The color of the TextFields background. * * @param textColor * The color of the text. */ public TextField( int width, int height, Color bgColor, Color textColor, String text) throws IllegalArgumentException { this (width, height, false , true , bgColor, textColor, text); } /** * Creates a new TextField of the given size, the given colors and a starting text. * * @param width * The TextFields width (which has to be greater than 50). * * @param height * The TextFields height (which has to be greater than 20). * * @param displayKeyNames * If you want to use the textfield for only one key this parameter has to be true. * * @param bgColor * The color of the TextFields background. * * @param textColor * The color of the text. */ public TextField( int width, int height, boolean displayKeyNames, Color bgColor, Color textColor, String text) throws IllegalArgumentException { this (width, height, displayKeyNames, true , bgColor, textColor, text); } /** * Creates a new TextField of the given size, the given colors and a starting text. * * @param width * The TextFields width (which has to be greater than 50). * * @param height * The TextFields height (which has to be greater than 20). * * @param displayKeyNames * If you want to use the textfield for only one key this parameter has to be true. * * @param enabled * If you want the textfield to be enabled (able to write in it) this boolean has to be true. * * @param bgColor * The color of the TextFields background. * * @param textColor * The color of the text. */ public TextField( int width, int height, boolean displayKeyNames, boolean enabled, Color bgColor, Color textColor, String text) throws IllegalArgumentException { if (width < 50 ) { throw new IllegalArgumentException( "The width of the text field has to be greater or equal 50" ); } else if (height < 20 ) { throw new IllegalArgumentException( "The height of the text field has to be greater or equal 20" ); } this .bgColor = bgColor; this .textColor = textColor; this .text = text; this .displayKeyNames = displayKeyNames; this .enabled = enabled; cursorPosition = text.length(); getImage().clear(); getImage().scale(width, height); textFontSize = height - 10 ; resetImage(); displayText(); } /** * Assigns this field a number. * This method is called when the object is added to the world. */ public void addedToWorld(World world) { textFieldNumber = getWorld().getObjects(TextField. class ).size(); } /** * Control the TextFields action. */ public void act() { if (Greenfoot.mouseClicked( this )) { activeTextField = textFieldNumber; active = true ; } if (active) { if (activeTextField != textFieldNumber) { active = false ; cursorActive = false ; displayText(); return ; } if (System.currentTimeMillis() - cursorTime > 750 ) { cursorTime = System.currentTimeMillis(); cursorActive = !cursorActive; } input = Greenfoot.getKey(); if (enabled) { if (displayKeyNames) { if (input != null && input != "" ) { text = input; } } else { if (input == "backspace" && text.length() != 0 && cursorPosition != 0 ) { if (cursorPosition == text.length()) { text = text.substring( 0 , text.length()- 1 ); } else { temp = text.substring( 0 , cursorPosition - 1 ); temp += text.substring(cursorPosition, text.length()- 1 ); text = temp; temp = "" ; } cursorPosition--; } else if (input == "enter" ) { setActiveTextField(); } else if (input == "space" ) { if (cursorPosition == text.length()) { text += " " ; } else { temp = text.substring( 0 , cursorPosition); temp += " " ; temp += text.substring(cursorPosition, text.length() - 1 ); text = temp; temp = "" ; } cursorPosition++; } else if (input == "left" ) { if (cursorPosition > 0 ) { cursorPosition--; cursorTime = System.currentTimeMillis(); cursorActive = true ; } } else if (input == "right" ) { if (cursorPosition < text.length()) { cursorPosition++; cursorTime = System.currentTimeMillis(); cursorActive = true ; } } else if (input != null && input.length() == 1 ) { if (cursorPosition == text.length()) { text += input; } else { temp = text.substring( 0 , cursorPosition); temp += input; temp += text.substring(cursorPosition, text.length() - 1 ); text = temp; temp = "" ; } cursorPosition++; } } } else if (input == "enter" ) { setActiveTextField(); } displayText(); } else { if (activeTextField == textFieldNumber) { active = true ; } } } /** * Display the text onto the TextField. */ private void displayText() { GreenfootImage textImage = new GreenfootImage(text, textFontSize, textColor, new Color( 0 , 0 , 0 , 0 )); GreenfootImage textBeforeCursor = new GreenfootImage(text.substring( 0 , cursorPosition), textFontSize, textColor, new Color( 0 , 0 , 0 , 0 )); resetImage(); getImage().drawImage(textImage, (textImage.getWidth() > getImage().getWidth() - 10 ? -(textImage.getWidth() - getImage().getWidth()) - 10 : 5 ), (getImage().getHeight() / 2 - textImage.getHeight() / 2 )); getImage().setColor(textColor); if (cursorActive) { getImage().fillRect((textBeforeCursor.getWidth() > getImage().getWidth() - 10 ? getImage().getWidth() - 8 : textBeforeCursor.getWidth() + 7 ), getImage().getHeight() / 2 - textFontSize / 2 , 2 , textFontSize); } getImage().setColor(bgColor); getImage().fillRect( 0 , 0 , 3 , getImage().getHeight()- 2 ); } /** * Clears the image of the TextField so that it is empty again. */ private void resetImage() { getImage().setColor(bgColor); getImage().fill(); getImage().setColor(Color.black); getImage().fillRect( 0 , getImage().getHeight()- 2 , getImage().getWidth(), 3 ); getImage().fillRect(getImage().getWidth()- 2 , 0 , 3 , getImage().getHeight()); } /** * Set the active TextField to the given number. * * @param activeTextField * The number of the TextField that is activated. */ public void setActiveTextField( int activeTextField) { this .activeTextField = activeTextField; } /** * Set the active TextField to the next textfield. */ public void setActiveTextField() { activeTextField++; if (activeTextField > getWorld().getObjects(TextField. class ).size()) { activeTextField = 1 ; } } /** * Check whether this textfield is enabled (if you can change the text in it). * * @return * Returns true if the text field is enabled. */ public boolean isEnabled() { return enabled; } /** * Enable or disenable the textfield. * * @param enabled * If you want the textfield to be enabled (able to write in it) this boolean has to be true. */ public void setEnabled( boolean enabled) { this .enabled = enabled; } /** * Returns the text of this textfield. * * @return * The text that is currently displayed in the textfield. */ public String getText() { return text; } /** * Set the text of this textfield. * * @param text * The text that should be displayed in the textfield. */ public void setText(String text) { this .text = text; cursorPosition = text.length(); } /** * Returns the backgroundcolor of this TextField. * * @return * The backgroundcolor of this TextField. */ public Color getBackgroundColor() { return bgColor; } /** * Set the backgroundcolor to the given color. * * @param bgColor * The new backgroundcolor. */ public void setBackgroundColor(Color bgColor) { this .bgColor = bgColor; } /** * Returns the textcolor of this TextField. * * @return * The textcolor of this TextField. */ public Color getTextColor() { return textColor; } /** * Set the textcolor to the given color. * * @param textColor * The new textcolor. */ public void setTextColor(Color textColor) { this .textColor = textColor; } } |