import java.awt.event.MouseListener; import java.awt.event.MouseEvent; import java.awt.Font; import java.awt.FontMetrics; import java.applet.Applet; import java.awt.Graphics; import java.util.ArrayList; import java.util.Random; /* * Very boring Java Applet to generate pin yin characters, * to help me with recall. * @author Arup Ghose, James Warren, April 2007 */ public class CharApplet extends Applet implements MouseListener { StringBuffer buffer; //just so my compiler would shut up static final long serialVersionUID = 3; Random r; ArrayList a; Font font = new Font("Times Roman", Font.PLAIN, 12); int rnum; public void init() { addMouseListener(this); buffer = new StringBuffer(); buffer.append("Keep Clicking to get a new character!"); a = new ArrayList(); //add all chapter 1 characters to it, ArrayList indices are 0-10 a.add("ah"); a.add("dad"); a.add("hundred"); a.add("byebye"); a.add("to do"); a.add("half"); a.add("to help"); a.add("newspaper"); a.add("to feel sorry"); a.add("Beijing"); a.add("Bei4bei"); a.add("notebook"); a.add("number of times (of action)"); a.add("no"); a.add("to feel embarassed"); a.add("need not"); a.add("to participate or attend"); a.add("dining room"); a.add("toilet"); a.add("story or floor"); a.add("to be short of or to lack"); a.add("often (2 versions)"); a.add("Chen2"); a.add("to eat"); a.add("to eat (a meal)"); a.add("to be born"); a.add("kitchen"); a.add("to wear"); a.add("to make a phone call"); a.add("to have a part-time job"); a.add("to play ball"); a.add("to clean"); a.add("big or large"); a.add("cake"); a.add("as it should be (or naturally)"); a.add("to arrive"); a.add("to have or to get"); a.add("to wait"); a.add("younger brother"); a.add("oclock"); a.add("telephone or phone call"); a.add("movie"); a.add("Ding1 Li4 bo1"); a.add("things or objects"); a.add("both or all"); a.add("to do physical exercise"); a.add("right or correct"); a.add("i am sorry"); a.add("how old"); a.add("how"); a.add("how many or how much"); a.add("many or much"); a.add("two"); a.add("to have a fever"); a.add("to become inflamed"); a.add("house"); a.add("rent"); a.add("minute"); a.add("cent (money)"); a.add("to review"); a.add("to have a cold"); a.add("just now"); a.add("happy or pleased"); a.add("to tell"); a.add("elder brother"); a.add("ge (measure word)"); a.add("to give"); a.add("to or for"); a.add("with or to follow"); a.add("to work or work"); a.add("company"); a.add("dog"); a.add("girl"); a.add("to register"); a.add("CD"); a.add("expensive or precious"); a.add("what is your honorable surname?"); a.add("country or nation"); a.add("to spend time or to celebrate"); a.add("in addition"); a.add("or"); a.add("chinese language"); a.add("chinese character"); a.add("good or well or fine or OK"); a.add("number"); a.add("to drink"); a.add("and"); a.add("very"); a.add("red wine"); a.add("to return"); a.add("how many or how much"); a.add("reporter"); a.add("to post or to mail"); a.add("Canada"); a.add("family or home"); a.add("Jia1 mei3"); a.add("measure word for room or house"); a.add("a measure word (piece)"); a.add("to be called"); a.add("to teach"); a.add("professor"); a.add("festival"); a.add("elder sister"); a.add("to introduce"); a.add("this year"); a.add("year"); a.add("today"); a.add("measure word of weight"); a.add("to enter"); a.add("to come in"); a.add("beijing opera"); a.add("manager"); a.add("get-together or party"); a.add("coffee"); a.add("to start school"); a.add("to watch or to look at"); a.add("to see a doctor"); a.add("roast duck"); a.add("lovely or cute"); a.add("maybe"); a.add("but"); a.add("may"); a.add("quarter (of an hour)"); a.add("class or lesson"); a.add("text"); a.add("perhaps or to be afraid that"); a.add("measure word for people in a family"); a.add("spoken language"); a.add("dollar (money)"); a.add("happy"); a.add("to come"); a.add("teacher"); a.add("cold"); a.add("gift or present"); a.add("Li4bo1"); a.add("to practice"); a.add("two"); a.add("a chinese violin concerto"); a.add("Lin2 Na4"); a.add("zero"); a.add("international student"); a.add("building"); a.add("Lu4 Yu3ping2"); a.add("to travel"); a.add("mom"); a.add("Ma3 Da4 Wei2"); a.add("to buy"); a.add("busy"); a.add("dime (money)"); a.add("not (not bu)"); a.add("nevermind or it doesn't matter"); a.add("every or each"); a.add("america"); a.add("fine arts"); a.add("younger sister"); a.add("calling card"); a.add("name"); a.add("tomorrow"); a.add("which"); a.add("where"); a.add("no (modest denial)"); a.add("that"); a.add("there"); a.add("paternal grandmother"); a.add("male"); a.add("south"); a.add("can or to be able to"); a.add("you"); a.add("you (plural)"); a.add("to read"); a.add("you (polite)"); a.add("female"); a.add("europe"); a.add("friend"); a.add("pretty or beautiful or nice"); a.add("bottle"); a.add("apple"); a.add("grape"); a.add("to get up"); a.add("money"); a.add("please"); a.add("may i ask"); a.add("to go"); a.add("all over (the body)"); a.add("to let or to allow or to make"); a.add("people or person"); a.add("to know (somebody)"); a.add("easy"); a.add("to take a walk or to walk"); a.add("throat"); a.add("market or bazaar or mall"); a.add("shanghai"); a.add("to go to class"); a.add("morning"); a.add("who or whom"); a.add("body or health"); a.add("what"); a.add("new word"); a.add("birthday"); a.add("christmas"); a.add("master worker"); a.add("time (moment)"); a.add("time (eg. have time)"); a.add("matter or affair or thing"); a.add("to be"); a.add("longevity noodles"); a.add("book"); a.add("comfortable"); a.add("water"); a.add("to sleep (2 versions)"); a.add("to say or to speak"); a.add("driver"); a.add("four"); a.add("Song4 Hua2"); a.add("to give as a present"); a.add("dormitory"); a.add("year (of age)"); a.add("years (of age)"); a.add("granddaughter on son's side"); a.add("they or them"); a.add("he or him"); a.add("she or her"); a.add("too or extremely"); a.add("painful"); a.add("day"); a.add("weather"); a.add("to be told"); a.add("head"); a.add("foreign country"); a.add("maternal grandmother"); a.add("foreign language"); a.add("to have fun or to play"); a.add("late"); a.add("evening or night"); a.add("why"); a.add("Wang2 Xiao3 Yun2"); a.add("a polite measure word for person"); a.add("hello or hey"); a.add("literature"); a.add("to ask"); a.add("question"); a.add("i or me"); a.add("we or us"); a.add("western medicine"); a.add("to wash"); a.add("to like or to prefer"); a.add("faculty or department"); a.add("afternoon"); a.add("mr."); a.add("now"); a.add("apple with a banana taste"); a.add("banana"); a.add("to think or to miss or to want to do sth"); a.add("little or small"); a.add("miss or young lady"); a.add("to write"); a.add("to thank"); a.add("week"); a.add("sunday"); a.add("to be OK"); a.add("surname"); a.add("to take a rest"); a.add("student"); a.add("to learn or to study"); a.add("institute r college"); a.add("Yang2 (surname)"); a.add("medicine"); a.add("to want or must or to want to do something"); a.add("too or also"); a.add("a little bit"); a.add("altogether"); a.add("together"); a.add("yixia"); a.add("clothes"); a.add("doctor or physician"); a.add("hospital"); a.add("music"); a.add("should or ought to"); a.add("great britain or england"); a.add("english"); a.add("post office"); a.add("to swim"); a.add("to have"); a.add("somewhat or rather or a bit"); a.add("famous"); a.add("interesting"); a.add("grammar"); a.add("language"); a.add("to be willing to do something"); a.add("goodbye"); a.add("again"); a.add("to be (here or there) or to be (in or at)"); a.add("dirty"); a.add("how"); a.add("how is it?"); a.add("Zhang1 (surname)"); a.add("measure word for flat objects"); a.add("to look for"); a.add("to give change"); a.add("picture or photo"); a.add("this"); a.add("here"); a.add("real or really"); a.add("to know"); a.add("china"); a.add("chinese"); a.add("noon"); a.add("middle school"); a.add("traditional chinese medicine"); a.add("to be born in the year of"); a.add("to be in hospital or hospitalized"); a.add("to live or to stay"); a.add("to congratulate"); a.add("to wish"); a.add("major or specialty"); a.add("to rent"); a.add("yesterday"); a.add("to sit"); a.add("to do or to make"); a.add("parcel"); a.add("to include"); a.add("cup of"); a.add("measure word for books"); a.add("pen"); a.add("cheap"); a.add("watch"); a.add("tea"); a.add("to sing"); a.add("car"); a.add("spring festival"); a.add("dictionary"); a.add("to take a taxi"); a.add("to have an injection"); a.add("stool"); a.add("computer"); a.add("TV"); a.add("abdomen or stomach"); a.add("convenient"); a.add("measure word for newspapers"); a.add("easter"); a.add("thanksgiving"); a.add("engineer"); a.add("child"); a.add("hamburger"); a.add("suitable"); a.add("chemistry"); a.add("to have a medical test"); a.add("to answer"); a.add("a reply or to reply"); a.add("education"); a.add("economy"); a.add("pleasant surprise"); a.add("to drive a car"); a.add("to have an operation"); a.add("coke"); a.add("living room"); a.add("history"); a.add("cool"); a.add("lawyer"); a.add("in disorder or in a mess"); a.add("to sell"); a.add("(cooked) rice"); a.add("bread"); a.add("difficult"); a.add("milk"); a.add("beer"); a.add("coincidental"); a.add("sunny"); a.add("hot"); a.add("hotdog"); a.add("enthusiastic"); a.add("diary"); a.add("life"); a.add("Santa Claus"); a.add("salesperson"); a.add("book store"); a.add("a study"); a.add("mathematics"); a.add("utility"); a.add("suite"); a.add("gym"); a.add("to dance"); a.add("maternal grandfather"); a.add("culture"); a.add("bedroom"); a.add("physics"); a.add("western food"); a.add("to smoke"); a.add("chairman of the department"); a.add("to get out of class or finish class"); a.add("urine"); a.add("new"); a.add("to take an elective course"); a.add("Sprite"); a.add("blood"); a.add("tooth"); a.add("paternal grandfather"); a.add("music"); a.add("English"); a.add("yuan"); a.add("New Year's Day"); a.add("philosophy"); a.add("to put in order or to arrange"); a.add("measure word for sticklike things"); a.add("Chinese food"); a.add("teaching assistant"); a.add("writer"); } void addItem(String newWord) { //System.out.println(newWord); buffer.delete(0, buffer.length()); buffer.append(newWord); font = new Font("Times Roman", Font.PLAIN, 14); repaint(); } public void paint(Graphics g) { //Draw a Rectangle around the applet's display area. FontMetrics fm = getFontMetrics(font); g.setFont (font); int stringWidth = fm.stringWidth (buffer.toString()); int x = (getWidth() - stringWidth) / 2; int y = (getHeight() - fm.getHeight()) / 2; g.drawRect(0, 0, getWidth() - 1, getHeight() - 1); //Draw the current string inside the rectangle. g.drawString(buffer.toString(), x, y + 15); } //The following empty methods could be removed //by implementing a MouseAdapter (usually done //using an inner class). public void mouseEntered(MouseEvent event) { } public void mouseExited(MouseEvent event) { } public void mousePressed(MouseEvent event) { } public void mouseReleased(MouseEvent event) { } public void mouseClicked(MouseEvent event) { if (a.size() == 0) { addItem("Done! Refresh to go again."); } else if (a.size() == 1) { addItem(a.get(0)); a.remove(0); } else { r = new Random(); rnum = r.nextInt(a.size()-1); addItem(a.get(rnum)); a.remove(rnum); } } }