import java.awt.*; import java.applet.Applet; import java.io.*; import java.net.*; public class ps3e3 extends Applet { int xorig = 10; int yorig = 200; int xsize = 570; int ysize = 82; Choice effectBar = new Choice(); TextField tf = new TextField(20); TextArea tf2 = new TextArea(6,55); TextField it = new TextField(20); Label prompt2 = new Label("enter desired intensity from 0 to 1: (otherwise it will default to 0)"); Label prompt = new Label( "enter a word please: (you must either 'apple' 'cat' or 'igloo')"); Label prompt0 = new Label ("pick a transformation method "); Button btn1 = new Button("TRANSFORM"); Float f1 = new Float(0); String dict[][] = new String[30][3]; public void init() { dict[0][0] = "universe ";dict[0][1] = "universe ";dict[0][2] = "universe "; dict[1][0] = "earth ";dict[1][1] = "earth ";dict[1][2] = "earth "; dict[2][0] = "farm ";dict[2][1] = "biosphere ";dict[2][2] = "hemisphere "; dict[3][0] = "orchard ";dict[3][1] = "lifeform ";dict[3][2] = "continent "; dict[4][0] = "crop ";dict[4][1] = "animal ";dict[4][2] = "region "; dict[5][0] = "plant ";dict[5][1] = "vertebrate ";dict[5][2] = "city "; dict[6][0] = "tree ";dict[6][1] = "quadruped ";dict[6][2] = "community "; dict[7][0] = "branch ";dict[7][1] = "mammal ";dict[7][2] = "erection "; dict[8][0] = "blossom ";dict[8][1] = "feline ";dict[8][2] = "shelter "; dict[9][0] = "fruit ";dict[9][1] = "pet ";dict[9][2] = "dwelling "; dict[10][0] = "apple ";dict[10][1] = "cat ";dict[10][2] = "igloo "; dict[11][0] = "flesh ";dict[11][1] = "tabby ";dict[11][2] = "dome "; dict[12][0] = "core ";dict[12][1] = "body ";dict[12][2] = "wall "; dict[13][0] = "seed ";dict[13][1] = "flesh ";dict[13][2] = "brick "; dict[14][0] = "cellulose ";dict[14][1] = "blood ";dict[14][2] = "snow "; dict[15][0] = "glucose ";dict[15][1] = "cells ";dict[15][2] = "crystal "; dict[16][0] = "carbohydrate ";dict[16][1] = "dna ";dict[16][2] = "water "; dict[17][0] = "hydrogen ";dict[17][1] = "carbon ";dict[17][2] = "oxygen "; dict[18][0] = "molecule ";dict[18][1] = "molecule ";dict[18][2] = "molecule "; dict[19][0] = "atom ";dict[19][1] = "atom ";dict[19][2] = "atom "; dict[20][0] = "particle ";dict[20][1] = "particle ";dict[20][2] = "particle "; add(prompt0); add(effectBar); add(prompt2); add(it); add(prompt); add(tf); add(btn1); // add(tf2); effectBar.addItem("UPPER CASE"); effectBar.addItem("lower case"); effectBar.addItem("blur"); effectBar.addItem("enhance"); effectBar.addItem("noise"); it.setText("0"); resize(540,380); } public boolean action( Event e, Object o ) { String str1; String str2; int intensity = 0; int shift = 0; int rowindex,colindex,i,j; int xpos ; int ypos ; rowindex = 10; colindex = 0; Font font1 = new Font("Serif",Font.PLAIN, 20); Font font2 = new Font("Courier",Font.PLAIN, 14); // tf2.setFont(font2); // tf2.setText(""); Graphics g = getGraphics(); g.setColor(Color.black); g.fillRect(xorig,yorig,xsize,ysize); g.setFont(font1); if (e.target == btn1) { xpos = xorig +10; ypos = yorig +25; shift = 0; str1 = tf.getText(); str1 = str1.toLowerCase(); try { Float F1 = new Float(it.getText()); float f1 = (F1.floatValue() * 10); intensity = (int)Math.rint(f1); } catch (NumberFormatException ee) { it.setText("0"); } if (intensity < 0 | intensity > 10) { intensity = 0; it.setText("0"); } if (str1.equals("apple")| (str1.equals("cat"))| (str1.equals("igloo"))) { if (str1.equals("apple")) colindex = 2; if (str1.equals("cat")) colindex = 0; if (str1.equals("igloo")) colindex = 1; if (effectBar.getSelectedIndex() == 0 |effectBar.getSelectedIndex() == 1 |effectBar.getSelectedIndex() == 4) rowindex = 9; if (effectBar.getSelectedIndex() == 2) rowindex = 9 - intensity; if (rowindex < 1) rowindex = 20; if (effectBar.getSelectedIndex() == 3) rowindex = 9 + intensity; if (effectBar.getSelectedIndex() == 4) shift = intensity; else shift = 0; for (i = 0;i < 3; i++) { g.setColor(Color.gray); for ( j = 0;j < 3; j++) { if (j == 1 && i == 1) g.setColor(Color.white); else g.setColor(Color.gray); if (i != 1) { colindex = colindex + shift; if (colindex == 3) colindex = 0; } if(effectBar.getSelectedIndex() == 0) { // tf2.appendText(dict[rowindex][colindex].toUpperCase() + " "); g.drawString(dict[rowindex][colindex].toUpperCase() + " ",xpos,ypos); } else { // tf2.appendText(dict[rowindex][colindex] + " "); g.drawString(dict[rowindex][colindex] + " ",xpos,ypos); } if (colindex == 2) colindex = 0; else colindex = colindex + 1; if (j == 2) xpos = xorig +10; else xpos = xpos + 125; // if (j == 2) // tf2.appendText("\n"); } ypos = ypos + 25; rowindex = rowindex + 1; if (rowindex == 21) rowindex = 0; } } // else // tf2.setText("you must enter 'apple' 'cat' or 'igloo'"); /* str1 = str1.toUpperCase(); else str1 = str1.toLowerCase(); tf.setText(str1); */ } return true; } public void paint(Graphics g) { g.setColor(Color.black); g.fillRect(xorig,yorig,xsize,ysize); } }