// Clean up program, classes, etc, and use as example. /* The folds are specified as a series of coordinate pairs. A line is drawn on the screen between each coordinate pair, " 70 70 70 300 70 70 250 70 " So the above parameter draws 2 lines. One from 70,70 to 70,300 And one from 70,70 to 250,70. You can also give a name to a line, like so: " Left 70 70 70 300 70 70 250 70 " This gives the name 'Left' to the line from 70,70 to 70,300. Then in future fold, just mention the line's name instead of its coordinate pairs, and it will be drawn. The rest of the parameter information should be self explanatory. Let me know if it's not. Let me know if you write instructions in this format for other interesting paper things. Also, let me know if you improve the "fold" program. Thanks, Peter van der Linden.
Note: you can sometimes better see a fold by flipping backwards and forwards
between diagrams.
Send me email if you successfully
complete this!
The code can be obtained here.
**********************/ /* An applet that draws lines and text * according to the coordinates in the html file. * - a little clunky, but does the job. * - Peter van der Linden, June 24 1996 * */ import java.awt.*; import java.applet.Applet; import java.io.*; import java.util.Hashtable; class Lines { //keeps a record of the lines we have read in // L1[i]..L4[i] holds all the lines on screen at fold i. static final int num_folds = 50; static final int lines_per_fold = 100; int [][] L1 = new int[num_folds][lines_per_fold]; int [][] L2 = new int[num_folds][lines_per_fold]; int [][] L3 = new int[num_folds][lines_per_fold]; int [][] L4 = new int[num_folds][lines_per_fold]; int i = 0; void store_lines(int fold, int w, int x, int y, int z) { for (i = 0; i < L1.length; i++) if (L1[fold][i] == 0) break; L1[fold][i] = w; L2[fold][i] = x; L3[fold][i] = y; L4[fold][i] = z; //System.out.println("Storing [" + i + "] " + w + "," + x); } } class namedLine { // gives a name to the line between x1,y1 and xy,y2 int x1,y1,x2,y2; } public class f2 extends Applet { Panel p = new Panel(); Button bp = new Button("previous"); Button bn = new Button("start"); int j = 0, curr_fold = 0; String s, w; StringBufferInputStream sbis; StreamTokenizer st; Lines L = new Lines(); static final int named_points = 100; Hashtable H = new Hashtable(named_points); public void init() { p.resize(100, 40); //put the "previous" button on a panel p.add(bp); //that isn't displayed at first. p.setBackground(Color.yellow); add(p); p.hide(); add(bn); setForeground(Color.blue); // blue on yellow gives excellent contrast setBackground(Color.yellow); } public void paint(Graphics g) { if (w != null) g.drawString("Step " + curr_fold + ": " + w, 35, 50); //draw all the stored lines for this fold int i = 0; while (L.L1[curr_fold][i] != 0) { g.drawLine(L.L1[curr_fold][i], L.L2[curr_fold][i], L.L3[curr_fold][i], L.L4[curr_fold][i++]); } } public boolean action(Event e, Object o) { if (e.target instanceof Button) { if ("next".equals((String) o)) curr_fold++; else if ("start".equals((String) o)) { bn.setLabel("next"); curr_fold = 1; p.show(); p.validate(); } else if (curr_fold > 1) curr_fold--; if (L.L1[curr_fold][0] == 0) { //need to read in lines s = getParameter("fold" + curr_fold); if (s == null) { curr_fold--; return true; } sbis = new StringBufferInputStream(s); st = new StreamTokenizer(sbis); st.parseNumbers(); int c, w, x, y, z; try { while ((c = st.nextToken()) != st.TT_EOF) { if ( c==st.TT_NUMBER) { w = (int) st.nval; c = st.nextToken(); x = (int) st.nval; c = st.nextToken(); y = (int) st.nval; c = st.nextToken(); z = (int) st.nval; L.store_lines(curr_fold, w, x, y, z); } else { // TT_WORD s = st.sval; // get the word //look it up in the hashtable namedLine nl = (namedLine) H.get(s); if (nl==null) { //if not in hash table, add it. nl = new namedLine(); c = st.nextToken(); nl.x1 = (int) st.nval; c = st.nextToken(); nl.y1 = (int) st.nval; c = st.nextToken(); nl.x2 = (int) st.nval; c = st.nextToken(); nl.y2 = (int) st.nval; try{H.put(s, nl);} catch(NullPointerException npe){System.out.println("point name is null");} } // now store the coords in the fold L.store_lines(curr_fold, nl.x1,nl.y1,nl.x2,nl.y2); } } } catch(IOException ioe) { ioe.printStackTrace(); return true; } } w = getParameter("words" + curr_fold); repaint(); return true; } return false; } }