import java.applet.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class poet extends Applet implements ActionListener { Button btn; String line1, line2, line3, line4; String noun1 = new String(); String noun2 = new String(); String noun3 = new String(); String noun6 = new String(); String noun5 = new String(); String adj1 = new String(); String adj2 = new String(); String adj3 = new String(); String adj4 = new String(); String adj5 = new String(); String adj6 = new String(); String verb1 = new String(); String verb2 = new String(); String nouns[] = {"stranger", "danger", "arranger", "habit", "rabbit", "guest", "west", "chest", "shark", "spark", "train", "rain","vector", "sector","lector", "wishes", "pool", "brain", "tail", "snail", "nail", "mail", "berth", "earth", "fload", "toad", "road", "boat", "coat", "strain", "loot", "boot", "foot", "root", "stoat", "smirch", "birch", "tub", "stub", "broom", "room", "boom", "ticket", "cricket", "book", "crook", "brook", "stool", "tool", "fool", "wool", "wood", "mood", "rest", "food", "watch", "match", "hall", "mall", "gall", "fall", "whirl", "girl", "bird", "weird","wretch", "retch", "shock", "clock", "flock", "lock", "block","scope", "slope", "envelope", "mouse", "house", "knishes", "ball", "thriller", "chiller"}; String verbs[] = { "went", "sent", "saw", "ate", "killed", "kissed", "missed", "bent", "bound", "threw", "drove", "draw", "got", "gave", "took", "told", "said to", "bored", "forced", "forgot", "filled", "fired", "exstracted", "dragged", "clicked", "drunk", "cut", "caught", "caused", "bit", "asked", "hated", "held", "hurt", "leapt", "left", "led", "lay", "lost", "loaded", "melted", "needed","noted", "offered", "opened", "splitted", "paid", "painted", "passed", "pulled", "pushed", "tried", "spreaded", "spent", "spoke", "faced", "met", "proved", "froze", "fooled","tought"}; String adj[]= { "white", "black", "blue", "wet", "small", "huge", "tiny", "green", "sloppy", "boring", "scared", "sweet", "sour", "red", "fat", "thin", "sick", "tall", "weak", "firm"}; int seed; public void init() { btn = new Button("Create Poem"); btn.addActionListener(this); setLayout(new BorderLayout()); add(btn, BorderLayout.SOUTH); seed = (int)System.currentTimeMillis(); generate(); } public String getwords(String w[]) { int i; Random rnd = new Random(seed); i = Math.abs(rnd.nextInt() % (w.length)); return w[i]; } public boolean IsRhyme(String word1, String word2) { String rhyme1; String rhyme2; int length1, length2; length1 = word1.length(); rhyme1 = new String(word1.substring( length1 - 3)); length2 =word2.length(); rhyme2 = new String(word2.substring(length2 - 3)); if (rhyme1.equals(rhyme2)) return true; else return false; } public String GetRhyme(String w[], String word1) { int i,j; Random rnd = new Random(System.currentTimeMillis()); String buffer[] = new String[3]; String word2 = new String(); j = 0; for(i = 0; i < w.length-1; i++) { if (IsRhyme(w[i], word1)) { word2 = w[i]; j++; } } i = 0; j = 0; return word2; } public void paint(Graphics g) { Font f = new Font("TimesRoman", Font.BOLD, 18); g.setFont(f); int h = g.getFontMetrics(f).getHeight(); int H = h; h += H; g.setColor(Color.red); g.drawRect(0, 0, getSize().width, getSize().height); g.setColor(Color.white); g.fillRect(2, 2, getSize().width-4, getSize().height-4); g.setColor(Color.blue); g.drawString("Java Poems", 30, 20); h += H; Font F = new Font("TimesRoman", Font.BOLD, 14); g.setFont(F); g.drawString(line1.toUpperCase() , 15, h); h += H; g.drawString(line2.toUpperCase(), 15, h); h += H; g.drawString(line3.toUpperCase(), 15, h); h += H; g.drawString(line4.toUpperCase(), 15, h); } public void actionPerformed(ActionEvent e) { if(e.getSource() == btn) generate(); } public void generate() { seed += 33; int l = 50; noun1 = getwords(nouns); seed += 17; noun2 = getwords(nouns); seed += 37; int i = 0; while((noun1.equals(noun2))&(i