S8356: Java Swing User Experience with real code examples.
SHARE Technical Conference
March 7, 2000

Abstract:
SHARE: It's not an acronym. It's what we do!
The Java classes (programs) that were used to count ballots for the August 1999 SHARE meeting election will be used as a examples of SWING and 2D coding. The example classes include Java objects the author has developed over the past four three years which serve as working examples of overloading, encapsulation, polymorphism, and inheritance.

This technical session is intended for the Java coder, and centers around working Java code. These are not just sample Java classes, but working classes that the author has found useful in developing Java applications.

The author has been writing programs since 1965 in Fortran, COBOL, PL/1, Algol, Pascal, C, C++, and various assembly languages. He has been exploring Java since 1996.



Steve Ryder, Senior Director
JSR Systems (SHARE Code: JSR)
2 Margranita Crescent
Austin, Texas 78703-1717

sryder@jsrsys.com
www.jsrsys.com
512.917.0823


Clients for whom the speaker has developed code include:
The University of Texas at Austin 1965-1966
Texas Education Agency 1966-2000
Houston Ind. School District 1975-1981
Conroe Ind. School District 1980-1993
United States Navy 1966-1994
Capitol Appraisal Group, Inc. 1981-2000
SHARE: It's not an acronym. It's what we do!
SHARE: It's not an acronym. It's what we do! Books that were helpful:

"Java in 21 Days " by Laura Lemay (SAMS)
"Java in a Nutshell" by David Flanagan (O'Reilly)
"Java SWING " by Robert Eckstein, Marc Loy & Dave Wood (O'Reilly)
"Java 2D Graphics" by Jonathan Knudsen (O'Reilly)


SHARE: It's not an acronym. It's what we do!


SHARE: 
It's not an acronym.

It's
 what we do!
test00.bat             66 Tue Feb 15 11:18:00 CST 2000
  1: %jdkdir%\bin\java JsrVote test00
  or--
     %jdkdir%\bin\java -jar JsrVote.jar test00 



SHARE: 
It's not an acronym.

It's
 what we do!
test00i.txt           889 Tue Feb 15 11:38:30 CST 2000
  1: =comment  may be any # of optional "=" lines.
  2: =         column 1 = "=", column 2-10 = parameter name, col 11...= value.
  3: =         ... below is printer name or network path name.  
  4: =printNAM LPT1
  5: =         ... valid printTYP are "hplj"=laser jet, "hpdj"=desk jet.
  6: =         ... only ascii printer tested is Canon BJ-200E
  7: =printTYP hl1040
  8: =printLPP 060   lines per page (columns 11-13).  
  9: SHARE 95 Board Election, July 26, 2000
 10: 010 maximum # of batches (for memory allocation)
 11: 50  batch size (used for reporting only)...first 3 lines may be changed
 12: 04  # races ...these #s can NOT be changed!!!
 13: 10  # candidates, all races
 14: 01  Vice President
 15: (1) Bob Ascott
 16: (2) David Barrow
 17: 01  Secretary
 18: (3) David Butler
 19: (4) Jack Eccles
 20: 01  Treausrer
 21: (5) Mary Nell Frucella
 22: (6) Fred Goodwin
 23: 02  Director
 24: (7) Cliff Harrison
 25: (8) John W. Moody
 26: (9) Michael Ridout
 27: (0) Barbara Varnado


SHARE: 
It's not an acronym.

It's
 what we do!
test00r.txt          4675 Tue Feb 15 13:10:54 CST 2000
  1: 1        JsrVote    SHARE 95 Board Election, July 26, 2000
  2:          2000-02-15@13:10      Plot Votes
  3: 0        # Ballots Cast:          277
  4:                 277+                                                                  
  5:                    |                                                                  
  6:                    |                                                                  
  7:                    |                                                                  
  8:                    |                                                                  
  9:                    |                                                                  
 10:                    |                                                                  
 11:                    |                                                                  
 12:                    |                                                                  
 13:                    |                                                                  
 14:                    |                                                                  
 15:                    |                                                                  
 16:                    |                                                                  
 17:                 207+                                                                  
 18:                    |                                                                  
 19:                    |                                                                  
 20:                    |                                                                 9
 21:                    |                                                                  
 22:                    |                                                                 4
 23:                    |                                                    9             
 24:                    |                                                    4            5
 25:                    |                                                                  
 26:                    |                                                    5             
 27:                    |                                                                 2
 28:                    |                                                    2            1
 29:                 138+                                       9            1             
 30:                    |                                                                  
 31:                    |                                                                 7
 32:                    |                                       4                          
 33:                    |                                       5                         8
 34:                    |                                       *            7            3
 35:                    |                                                                  
 36:                    |                          9                         3            0
 37:                    |                          *                         8             
 38:                    |                          1            *            0             
 39:                    |                          2            8                         6
 40:                    |                                                                  
 41:                    |                                       0            6             
 42:                  69+             9            7                                       
 43:                    |             *            3            6                          
 44:                    |             *            *                                       
 45:                    |                                                                  
 46:                    |             *            6                                       
 47:                    |             *                                                    
 48:                    |9                                                                 
 49:                    |*                                                                 
 50:                    |*                                                                 
 51:                    |                                                                  
 52:                    |                                                                  
 53:                    |                                                                  
 54:                   0+---------+---------+---------+---------+---------+---------+---------+---------+
 55:                     Batches->


SHARE: 
It's not an acronym.

It's
 what we do!
test00v.txt           479 Thu Mar 02 11:16:56 CST 2000
  1: (1) Bob Ascott,(2) David Barrow,(3) David Butler,(4) Jack Eccles,(5) Mary Nell Frucella,(6) Fred Goodwin,(7) Cliff Harrison,(8) John W. Moody,(9) Michael Ridout,(0) Barbara Varnado
  2: 0,1,1,1,1,0,0,1,0,0,00001
  3: 0,1,1,1,1,1,0,0,0,0,00002
  4: 0,0,1,1,1,1,0,0,0,0,00003
  5: 0,1,1,1,1,1,0,0,0,0,00004
  6: 0,1,0,1,1,0,0,0,0,0,00005
  7: 1,1,0,1,1,0,1,0,0,0,00006
  8: 1,1,0,1,1,0,0,0,1,0,00007
  9: 1,1,0,1,1,0,0,0,1,0,00008
 10:    votes 9-275 were here.
 11: 1,0,0,1,0,0,0,1,0,0,00276
 12: 0,0,1,1,0,0,1,1,0,1,00277



SHARE: 
It's not an acronym.

It's
 what we do!
JsrVoteJar.bat        683 Tue Aug 10 23:39:48 CDT 1999
  1: jar cmf JsrVote.mnf JsrVote.jar -C \jsr\java\bin JsrVote.class
  2: jar  uf JsrVote.jar -C \jsr\java\bin JsrVote$1.class
  3: jar  uf JsrVote.jar -C \jsr\java\bin JsrVote$1$VoteActionListener.class
  4: jar  uf JsrVote.jar -C \jsr\java\bin JsrVote$1$VoteItemListener.class
  5: jar  uf JsrVote.jar -C \jsr\java\bin JsrVote$1$VoteMenuListener.class
  6: jar  uf JsrVote.jar -C \jsr\java\bin JsrWindowExit.class
  7: jar  uf JsrVote.jar -C \jsr\java\bin JsrUtil.class
  8: jar  uf JsrVote.jar -C \jsr\java\bin JsrSysout.class
  9: jar  uf JsrVote.jar -C \jsr\java\bin JsrPrint1.class
 10: jar  uf JsrVote.jar -C \jsr\java\bin JsrLineIn.class
 11: jar  uf JsrVote.jar -C \jsr\java\bin JsrLineOut.class
 12: jar  tf JsrVote.jar
 13: 



SHARE: 
It's not an acronym.

It's
 what we do!

JsrLineIn.java       2641 Fri Mar 12 17:17:42 CST 1999
  1: /******************************************************************************
  2: // JsrLineIn.java:    
  3:  * to simplify display/accept logic for debugging.
  4:  * Sample Use:
  5:  * import JsrLineIn;                  ... 
  6:  * JsrLineIn file1 = new JsrLineIn();
  7:  * String[] strfile1[2];
  8:  * strfile1[0] = "C:\reqlook.dxx"
  9:  * while (0 <= file1.read(strfile1[]))
 10:       {   process records from strfile1[1];           }
 11: */
 12: 
 13: import java.io.*;
 14: 
 15: public class JsrLineIn
 16: { 
 17:   static final String COPYRIGHT = 
 18:   "Copyright 1998, JSR Systems.  See: www.Jsrsys.com/copyright.";
 19: 
 20:   int                   recNum = 0;
 21:   String                fileName = "";
 22: //1.0  DataInputStream       inFileStream;
 23: //1.0  DataInput             inFile;
 24:   BufferedReader             inFile;
 25: 
 26:   JsrSysout sysout = new JsrSysout();
 27: 
 28:   public JsrLineIn()  // null constructor
 29:   {
 30:   }
 31: 
 32:   int open(String parmName)   
 33:   {
 34:      if (recNum != 0)
 35:      {
 36:         close();
 37:      }
 38:      sysout.display("Open   Input: " + parmName);   
 39:      // open code here
 40:      fileName = parmName;
 41:      recNum = 0;
 42: 
 43: //1.0     try {inFileStream =
 44: //1.0             new DataInputStream(new FileInputStream ( fileName));
 45: //1.0          inFile =  inFileStream;
 46:      try {inFile = new BufferedReader(new InputStreamReader
 47:                                      (new FileInputStream ( fileName)),1000000);
 48:          } catch (FileNotFoundException eFNF)
 49:                  {System.out.println("FileNotFound: " + fileName);
 50:                   recNum=-1; 
 51:                  } 
 52:      return recNum;
 53:   } 
 54:   int close()   
 55:   {  
 56:      sysout.display("Close  Input: " + fileName + " Records in=" + recNum
 57:                    +"                          ");   
 58:      if (recNum >= 0)
 59:      {
 60: //1.0  try {inFileStream.close();   // free up resource
 61:        try {inFile.close();   // free up resource
 62:            }catch ( IOException  eIO )
 63:                   {System.out.println("I/OError! "   + fileName); }
 64:      }
 65:      recNum   = - recNum;
 66:      fileName = "";
 67:      return recNum;
 68:   } 
 69:   int read(String nameRecord[])   
 70:   {
 71:      // sysout.display("Read: " + nameRecord[0]);   
 72:      if (!nameRecord[0].equals(fileName))
 73:      {
 74:         open(nameRecord[0]);
 75:      }
 76:      if (recNum >= 0)
 77:      {
 78:        try {nameRecord[1] = inFile.readLine();
 79:            } 
 80:              catch ( IOException  eIO )
 81:                    {System.out.println("I/OError! "   + fileName); }
 82:        if (nameRecord[1] == null)
 83:           close();
 84:        else
 85:           recNum++;
 86:      }
 87:      // sysout.display ("recNum="+recNum+ "Rec="+ nameRecord[1]);
 88:      return recNum;
 89:   } 
 90: } 
 91: 


SHARE: 
It's not an acronym.

It's
 what we do!

JsrLineOut.java      2369 Wed Aug 25 09:46:42 CDT 1999
  1: /******************************************************************************
  2: // JsrLineOut.java:    
  3:  * Sample Use:
  4:  * import JsrLineOut;                  ... 
  5:  * JsrLineOut file1 = new JsrLineOut();
  6:  * String[] strfile1[2];
  7:  * strfile1[0] = "C:\reqlook.dxx"
  8:  * file1.Write(strfile1[]))
  9: */
 10: 
 11: import java.io.*;
 12: import JsrDebug;
 13: public class JsrLineOut
 14: { 
 15:   static final String COPYRIGHT = 
 16:   "Copyright 1998, JSR Systems.  See: www.Jsrsys.com/copyright.";
 17: 
 18:   int                   recNum = 0;
 19:   String                fileName = "";
 20:   DataOutputStream       outFileStream;
 21:   DataOutput             outFile;
 22:   JsrSysout d;
 23:   boolean displayOn;
 24:   public JsrLineOut()  // null constructor
 25:   {
 26:      d = new JsrSysout();
 27:      displayOn = true;
 28:   }
 29:   public JsrLineOut(String noLog)  // constructor to not log
 30:   {  displayOn = false;            // used by JsrSysout itself
 31:   }                                // to avoid recursive calls
 32: 
 33:   int open(String parmName)   
 34:   {
 35:      if (recNum != 0)
 36:      {
 37:         close();
 38:      }
 39:      if (displayOn) d.display("Open  Output: " + parmName);   
 40:      // open code here
 41:      fileName = parmName;
 42:      recNum = 0;
 43:      try {outFileStream =
 44:              new DataOutputStream(new FileOutputStream ( fileName));
 45:           outFile =  outFileStream;
 46:          } catch ( IOException  eIO )
 47:                  {System.out.println("I/OError! "   + fileName); 
 48:                   recNum=-1; 
 49:                  } 
 50:      return recNum;
 51:   } 
 52:   int close()   
 53:   {  
 54:      if (recNum > 0)
 55:      {
 56:        if (displayOn) d.display("Close Output: " + fileName + " Records out=" + recNum);   
 57:        try {outFileStream.close();   // free up resource
 58:            }catch ( IOException  eIO )
 59:                   {System.out.println("I/OError! "   + fileName); }
 60:      }
 61:      recNum   = - recNum;
 62:      fileName = "";
 63:      return recNum;
 64:   } 
 65:   int write(String nameRecord[])   
 66:   {
 67:      // if (displayOn) d.display("Read: " + nameRecord[0] + nameRecord[1]);   
 68:      if (!nameRecord[0].equals(fileName))
 69:      {
 70:         open(nameRecord[0]);
 71:      }
 72:      if (recNum >= 0)
 73:      {
 74:        try { outFile.writeBytes(nameRecord[1]+"\r\n");
 75:            } catch ( IOException  eIO )
 76:                    {System.out.println("I/OError! "   + fileName); }
 77:      }
 78:      recNum++;
 79:      return recNum;
 80:   } 
 81: } 


SHARE: 
It's not an acronym.

It's
 what we do!

JsrPrint1.java       6403 Wed Sep 15 23:00:36 CDT 1999
  1: import java.io.PrintWriter;
  2: import java.io.FileWriter;
  3: import java.io.IOException;
  4: 
  5: class JsrPrint1
  6: {
  7: 
  8:   static final String COPYRIGHT = 
  9:   "Copyright 1999, JSR Systems.  See: www.Jsrsys.com/copyright.";
 10: 
 11:   static    JsrSysout sysout = new JsrSysout();
 12:   static    JsrUtil   u      = new JsrUtil();
 13:   static    String[]  inputFile = {" ", " "};
 14:   static    JsrLineIn input     = new JsrLineIn();
 15:   static    int lineCount = 0;
 16:   static    int pageCount = 0;
 17:             // default printer is "old style" ASCII
 18:   static    boolean hplj  = false;      // 17 cpi 
 19:   static    boolean hplj20= false;      // 20 cpi 
 20:   static    boolean hpdj  = false;      // 24 cpi 
 21:   static    boolean brotherHL = false;  // 17 cpi
 22:   static    boolean cc    = true;   // default is cc (nocc sets to false)
 23:   static    String  ccChar = " ";  
 24:   static    int linesPerPage = 60;
 25:     public static void main(String parm[])
 26:     {
 27:       sysout.display("JsrPrint1--"+COPYRIGHT);
 28:       sysout.display("JsrPrint1--usage: JsrPrint1 <input file> <printer/LPT1> <cc/nocc>");
 29:       sysout.display("---------------------------    ");                
 30:       if (parm.length < 2)
 31:       {
 32:         sysout.display("JsrPrint1--requires two parameters");
 33:         return;
 34:       }
 35:       for (int i = 2; i < parm.length; i++)
 36:       {
 37:          if  (parm[i].equalsIgnoreCase("nocc"))
 38:              cc = false;
 39:          if  (parm[i].equalsIgnoreCase("hplj"))      // 17 cpi
 40:              hplj = true;
 41:          if  (parm[i].equalsIgnoreCase("hplj20"))    // 20 cpi
 42:              hplj20 = true;
 43:          if  (parm[i].equalsIgnoreCase("hpdj"))      // 24 cpi
 44:              hpdj = true;
 45:          if  (parm[i].equalsIgnoreCase("BrotherHL")) // 17 cpi
 46:              brotherHL = true;
 47:       }
 48:           
 49:       inputFile [0] = parm[0];
 50:       sysout.display("Reading from: " + inputFile[0]);
 51: 
 52:       PrintWriter out;
 53:       try
 54:       {out = new PrintWriter(new FileWriter(parm[1]));
 55:       } catch(IOException e) {sysout.display("Printer IO exception"+e);
 56:                               return;
 57:                              }
 58:       sysout.display("Printing  to: " + parm[1]);
 59:    
 60:       if  (hplj20)                    // HP Laser Jet @ 20 cpi
 61:       {
 62:           out.print("\033E");         // Reset to defaults (for HP printers)
 63:           out.print("\033&l8d&l88P"); // 8 lines per inch, 88 lpp
 64:           out.print("\033&l4e&l80F"); // top margin 4 lines, 80 text lines
 65:           out.print("\033(s0p(s20H"); // fixed pitch 20 char / inch
 66:           out.print("\033(s0b(s6T");  // Normal strike wt. Letter Gothic typeface
 67:           linesPerPage = 80;
 68:       }
 69:       else 
 70:       if  (brotherHL || hplj)         // Brother HL-1040 Laser Jet or HPLJ @ 17 cpi
 71:       {                               
 72:           out.print("\033E");         // Reset to defaults (for HP printers)
 73:           out.print("\033&l8d&l88P"); // 8 lines per inch, 88 lpp
 74:           out.print("\033&l4e&l80F"); // top margin 4 lines, 80 text lines
 75:           out.print("\033(s0p(s17H"); // fixed pitch 17 char / inch
 76:           out.print("\033(s0b(s6T");  // Normal strike wt. Letter Gothic typeface
 77:           linesPerPage = 80;
 78:       }
 79:       else 
 80:       if  (hpdj)                      // HP Desk Jet
 81:       {
 82:           out.print("\033E");         // Reset to defaults (for HP printers)
 83:           out.print("\033&l6d&l66P"); // 6 lines per inch, 66 lpp
 84:           out.print("\033&l3e&l60F"); // top margin 3 lines, 60 text lines
 85:           out.print("\033(s0p(s24H"); // fixed pitch 24 char / inch
 86:           out.print("\033(s0b(s6T");  // Normal strike wt. Letter Gothic typeface
 87:           out.print("\033*o-1M");     // EconoFast 300X300 dpi
 88:           linesPerPage = 60;
 89:       }
 90:       else
 91:       {
 92:           out.print("\017");         // compressed print on Canon
 93:           linesPerPage = 59;
 94:       }
 95: 
 96:       int recNum = 0;
 97:       while (0 <= (recNum=input.read(inputFile))) 
 98:       {
 99:         lineCount++;
100:         if (cc)
101:         {
102:            if (inputFile[1].length() < 2)
103:            {
104:               ccChar = " ";
105:               inputFile[1] = " ";
106:            }
107:            else
108:            {
109:               ccChar = inputFile[1].substring(0,1);
110:               inputFile[1] = inputFile[1].substring(1);
111:            }
112:            if (ccChar.equals("1"))
113:            {
114:               if (pageCount > 0 || lineCount > 1)
115:               {
116:                  out.print("\f"); // eject page
117:                  pageCount++;
118:                  lineCount--;
119:                  sysout.display("Printing page: "  +pageCount +
120:                                " (lines on page: "+lineCount+")");
121:                  lineCount = 1;
122:                  ccChar = " ";
123:               }
124:            }
125:       
126:         }
127: 
128:         if (cc && ccChar.equals("+")) lineCount--;
129:         if (cc && ccChar.equals("0")) lineCount++;
130:         if (cc && ccChar.equals("-")) lineCount+=2;
131: 
132:         // newpage if lineCount > linesPerPage, even if cc...
133:         if (lineCount > linesPerPage)
134:         {  pageCount++;
135:            out.print('\f'); // eject page
136:            lineCount--;
137:            sysout.display("Printing page: "+pageCount +
138:                          " (lines on page: "+lineCount+")");
139:            lineCount = 1;
140:         }
141:         if (cc)
142:         {
143:            if (ccChar.equals("+")) out.print("\r");
144:            else
145:            if (ccChar.equals("0")) out.print("\r\n\r\n");
146:            else
147:            if (ccChar.equals("-")) out.print("\r\n\r\n\r\n");
148:            else
149:                                    out.print("\r\n");
150:        
151:            out.print(inputFile[1]);
152:         }
153:         else   
154:            out.println(inputFile[1]);
155:    
156:       }
157: 
158:         // flush and check if we got any errors from those
159:         // print() and println() calls
160:         if (out.checkError()) {
161:             System.err.println("Got errors printing");
162:             System.exit(-1);
163:         }
164:         pageCount++;
165:         sysout.display("Printing page: "  +pageCount +
166:                       " (lines on page: "+lineCount+")");
167:         out.print('\f'); // eject page then close stream
168:         if  (hplj || hpdj || brotherHL || hplj20)
169:             out.print("\033E"); // Reset to defaults
170:         
171:         out.flush();    // not needed; close() will flush
172:         out.close();
173:     }
174: }


SHARE: 
It's not an acronym.

It's
 what we do!

JsrSysout.java       3167 Wed Aug 25 09:48:54 CDT 1999
  1:  /******************************************************************************
  2: // JsrSysout.java:    
  3:  * to simplify display/accept logic for debugging.
  4:  * Sample Use:
  5:  * import JsrSysout;                  ... 
  6:  * JsrSysout d = new JsrSysout();  ...
  7:  * d.display("Text to display");
  8:  * d.accept ("Text to display");  
  9:  * each instance of JsrSysout will save the last character entered from accept.
 10:  * if that character is "q" (113), lower case q, subsequent calls to that
 11:  *    instance will neither display (System.out.println), 
 12:  *                      nor accept  (System.in.read()).     
 13:  * 1998/08/18 modification.  If user enters "R" (for Run),
 14:  *    displays will continue, but user will not be prompted for input.
 15:  *
 16:  * 1999-08-25 modifications:
 17:  *    d.syslog("syslog.txt");  // will log to file syslog.txt.
 18:  *    d.setNoStop();           // sets qBig to "R".
 19: 
 20:  
 21: */
 22: 
 23: import java.io.*;
 24: public class JsrSysout
 25: { 
 26:   static final String COPYRIGHT = 
 27:   "Copyright 1998, JSR Systems.  See: www.Jsrsys.com/copyright.";
 28: 
 29:   static final int MAXLINELEN = 80;
 30:   static final int MAXSCREEN  = 21;
 31:   static int qBig = ' ';  //  81 "Q" to terminate all instances 
 32:                           //  82 "R" run, do not query user any more
 33:   int       qChar = ' ';  // 113 "q" to terminate this instance
 34:   static int nLines = 0;
 35:   static String[]   syslogLine = new String[] {"",""};
 36:   static JsrLineOut syslogFile = new JsrLineOut("NoLog");
 37:   // any string in constructor will suppress recursive calls to JsrSysout
 38:   public JsrSysout()  // null constructor
 39:   {
 40:   }
 41: 
 42:   void display(String displayString)
 43:   {  
 44:      if (qChar != 113 && qBig != 81)
 45:      {
 46:         // System.out.println("Last q="+qChar+", Last Q="+qBig);
 47:         nLines += (displayString.length()+MAXLINELEN)/MAXLINELEN;
 48:         if (nLines > MAXSCREEN)
 49:            accept(displayString);
 50:         else   
 51:         System.out.println(displayString);
 52:         if (syslogLine[0].length() > 0)
 53:         {
 54:             syslogLine[1] = displayString;
 55:             syslogFile.write(syslogLine);
 56:         }
 57:      }
 58:      return;
 59:   } 
 60: 
 61:   void accept(String displayString)
 62:   {
 63:      if (qChar != 113 && qBig != 81) 
 64:      {
 65:         // System.out.println("Last q="+qChar+", Last Q="+qBig);
 66:         System.out.println(displayString);
 67:         if (syslogLine[0].length() > 0)
 68:         {
 69:             syslogLine[1] = displayString;
 70:             syslogFile.write(syslogLine);
 71:         }
 72:         nLines = (displayString.length()+MAXLINELEN)/MAXLINELEN;
 73:         if (qBig != 82)
 74:         {
 75:           System.out.println("Waiting for input..."+
 76:              "(Press [Enter], or \"q\", or \"Q\", "+
 77:              "or \"R\", then [Enter].)");
 78:           try {qChar = System.in.read();System.in.read();}
 79:                catch (IOException eIO){}
 80:           qBig = qChar;  // if "Q" will terminate all instances.
 81:                          // if "q" will terminate this instance.
 82:         }
 83:      }
 84:      return;
 85:   }
 86:   void setNoStop()
 87:   {
 88:       qBig = 'R';
 89:       return;
 90:   }
 91: 
 92:   void syslog(String fileName)
 93:   {
 94:       syslogLine[0] = fileName;
 95:       return;
 96:   }
 97:   
 98: } 


SHARE: 
It's not an acronym.

It's
 what we do!

JsrUtil.java         2673 Sun Aug 08 16:36:48 CDT 1999
  1: /******************************************************************************
  2: // JsrUtil.java:   padLeft, padRight, string or integer input.
  3: //                 output is padded or truncated as necessary.
  4:  * Sample Use:
  5:  * import JsrUtil;                  ... 
  6:  * JsrUtil u = new JsrUtil();
  7:  * paddedString  = u.padLeft(oldString,10);
  8:  * paddedInteger = u.padLeft(oldInt,10);
  9:  * zeroPadInt    = u.padZero(oldInt,10);
 10:  * paddedString  = u.padRight(oldString,10);
 11:  * dateTime      = u.getDateTime();
 12:  * 
 13: */
 14: import java.util.*;
 15: 
 16: public class JsrUtil
 17: { 
 18:   static final String COPYRIGHT = 
 19:   "Copyright 1998, JSR Systems.  See: www.Jsrsys.com/copyright.";
 20: 
 21:   public JsrUtil()  // null constructor
 22:   {
 23:   }
 24: 
 25:   String padLeft(String parmString, int parmLen)   
 26:   {
 27:      String tempString = parmString;
 28:      if (tempString.length()    > parmLen)
 29:         tempString = tempString.substring(tempString.length()-parmLen,
 30:                                           tempString.length());
 31:      else
 32:      {
 33:         while (tempString.length() < parmLen)
 34:           tempString = " "+tempString;
 35:      }
 36:      return tempString;  
 37:   } 
 38: 
 39:   String padLeft(int parmInt, int parmLen)   
 40:   {
 41:      Integer tempInt    = new Integer(parmInt);
 42:      String  tempString = tempInt.toString();
 43:      return padLeft(tempString, parmLen);
 44:   } 
 45: 
 46:   String padZero(int parmInt, int parmLen)   
 47:   {
 48:      Integer tempInt    = new Integer(parmInt);
 49:      String  tempString = tempInt.toString();
 50:      if (tempString.length()    > parmLen)
 51:         tempString = tempString.substring(tempString.length()-parmLen,
 52:                                           tempString.length());
 53:      else
 54:      {
 55:         while (tempString.length() < parmLen)
 56:           tempString = "0"+tempString;
 57:      }
 58:      return tempString;  
 59:   } 
 60: 
 61:   String padRight(String parmString, int parmLen)   
 62:   {
 63:      String tempString = parmString;
 64:      if (tempString.length()    > parmLen)
 65:         tempString = tempString.substring(0,parmLen+1);
 66:      else
 67:      {
 68:         while (tempString.length() < parmLen)
 69:           tempString = tempString + " ";
 70:      }
 71:      return tempString;  
 72:   } 
 73: 
 74:   String getDateTime()   
 75:   {
 76:       Calendar rightNow = Calendar.getInstance();
 77:       String   today = rightNow.get(Calendar.YEAR)+"-"+
 78:                padZero(rightNow.get(Calendar.MONTH)+1,2)+"-"+
 79:                padZero(rightNow.get(Calendar.DAY_OF_MONTH),2)+"@"+
 80:                padZero(rightNow.get(Calendar.HOUR_OF_DAY),2)+":"+
 81:                padZero(rightNow.get(Calendar.MINUTE),2);
 82:        // add 1 to month because Calendar returns 0 for January!!!
 83:      return today;
 84:   }
 85: 
 86: } 


SHARE: 
It's not an acronym.

It's
 what we do!

JsrVote.java        26949 Tue Feb 22 16:30:30 CST 2000
  1: // JsrVote.java
  2: //
  3: //  2000-02-15 changes:
  4: //  add logic for multiple races
  5: //
  6: //  Assumptions:  the following are assumed to exist, current version has
  7: //  no error checking, it just assumes these states.
  8: //  1)  p1+i.txt exists and is well formed (see share93i.txt for example).
  9: //      in particular # races, and # candidates is critical.
 10: //  2)  race title lines are in format ## title (## is max votes this race).
 11: //  3)  candidate  lines are in format (k) Name (k is shortcut key).
 12: //  4)  current version only supports one race, extra loop logic will be added.
 13: //      however [race] variables are all arrays, only loop logic is missing.
 14: //  5)  p1+v.txt is assumed to always exist.
 15: //      first line is assumed to be titles (for Excel).
 16: //      first action (ALWAYS) is to rename p1+v.txt to p1+v.$$$
 17: //      then program reads p1+v.$$$, copying to p1+v.txt,
 18: //      building vote count (batch and total) arrays.
 19: //  6)  after initial run, contents of p1+i.txt must NOT be changed, except:
 20: //      title line, maximum batches (used for array size calculation), and
 21: //      batch size may be changed.
 22: //  7)  each ballot voted is immediately written to p1+v.txt, so recovery
 23: //      is always to last ballot voted.  However, ballot # is part of data
 24: //      so recovery could be modified by editing p1+v.txt file.
 25: 
 26: import javax.swing.*;
 27: import java.awt.*;
 28: import java.awt.event.*;
 29: import java.io.File;
 30: import java.util.*;
 31: 
 32: 
 33: public class JsrVote
 34: {
 35:   static final String COPYRIGHT = 
 36:   "Copyright 2000, JSR Systems.  See: www.Jsrsys.com/copyright.";
 37:   static JsrSysout  d = new JsrSysout();
 38:   static JsrUtil    u = new JsrUtil();
 39:   // static Font defaultFont = new Font("Lucida Sans",Font.BOLD,18);        
 40:   static Font defaultFont = new Font("Comic Sans MS",Font.BOLD,18);        
 41: 
 42:   static String[] inputFile = {" ", " "};
 43:   static JsrLineIn input = new JsrLineIn();
 44: 
 45:   static String[] outputFile = {" ", " "};
 46:   static JsrLineOut output = new JsrLineOut();
 47: 
 48:   static String[] reportFile = {" ", " "};
 49:   static JsrLineOut report = new JsrLineOut();
 50: 
 51:   static String[]  print1Parm = new String[] {"*r.txt", "LPT1", "cc", " "};
 52:   static JsrPrint1 print1     = new JsrPrint1();
 53:   static int       printLPP   = 66;  // lines per page
 54:   static int       lineCount  = 999; // line count to force immediate page break
 55:   
 56:   static String voteTitle;     // Title         (card input)
 57:   static int    maxBatch  = 0; // max # batches (card input)
 58:   static int    batchSize = 0; // batch size    (card input)
 59:   static int    maxRace   = 0; // max # Races   (card input)
 60:   static int    maxVote   = 0; // max # Votes   (card input, all Races)
 61:   static JLabel batHead     = new JLabel("Batch #  1 ",SwingConstants.RIGHT);
 62:   static JLabel totHead     = new JLabel("Vote Totals",SwingConstants.RIGHT);
 63:   static JLabel dotLabel1   = new JLabel("Race(s) & Candidates",SwingConstants.LEFT);
 64:   static JLabel dotLabel2   = new JLabel("   ",SwingConstants.RIGHT);
 65:   static JLabel dotLabel3   = new JLabel("   ",SwingConstants.RIGHT);
 66:   static JLabel batSumLabel = new JLabel("Batch: xxxxxxxxx",SwingConstants.RIGHT);
 67:   static JLabel totSumLabel = new JLabel("Total: xxxxxxxxx",SwingConstants.RIGHT);
 68: 
 69:   // for following arrays, actual allocation size will be determined in main
 70:   static int[]    voteMax;   // Max # votes/Race (card input)
 71:   static String[] raceName;  // Race Name        (card input)
 72:   static String[] voteName;  // Candidate name   (card input)
 73:                              // (#) name... where # is selection key (sets box true)
 74:   static int[]    raceVotes; // # votes this Ballot by Race
 75:   static int[]    voteCount; // # votes by candidate
 76:   static int[]    cummCount; // cumm votes for All Batch report (or plots).
 77:   static int[]    voteRace;  // Race index by candidate   
 78:   static char[]   voteArray; // the votes for this Ballot
 79:   static int   voteBallot = 0; // total Ballots
 80:   static int   b          = 0; // current batch #               
 81:   static int     cummBallot; // cumm ballot for All Batch report (or plots).
 82:   static int[]  batchBallot; // # ballots per batch
 83:   static int[][]  batchVote; // votes per batch
 84:   static JLabel    []   raceLabel1; // = new JLabel[maxRace];
 85:   static JLabel    []   raceLabel2; // = new JLabel[maxRace];
 86:   static JLabel    []   raceLabel3; // = new JLabel[maxRace];
 87:   static JCheckBox []   voteBox;    // = new JCheckBox[maxVote];
 88:   static JLabel    []    totLabel;  // = new JLabel[maxVote];
 89:   static JLabel    []    batLabel;  // = new JLabel[maxVote];
 90:   static boolean   printOn = false;    // print reports?
 91:   static String    today;              // set by MenuAction Listener
 92: 
 93:   static JFrame frame; 
 94: 
 95:   //notes on static and final: -----------------------------------------------
 96:   //  static means it is a class variable, not an instance variable.
 97:   //  static means it can be accessed from any method (funtionally global)
 98:   //  final means it can not be changed, however if it is an array,
 99:   //        then the individual array values can be changed.
100:   //  final can be accessed from the "inner" classes, but not other methods.
101:   //  ------------------------------------------------------------------------
102:   
103:   public static void main(String[] parm) 
104:   {
105:     
106:     Integer tempInt;
107:     d.syslog("syslog.txt");
108:     d.setNoStop();
109:     
110:     d.display("JsrVote--"+COPYRIGHT);
111:     d.display("JsrVote--Font: "+defaultFont.toString());
112:     if (parm.length < 1)
113:     {  d.display("JsrVote-must contain one argument:");
114:        d.display("--------parm 1: file prefixy (i.e., 'share93')");
115:        return;
116:     }
117:     inputFile  [0] = parm[0]+"i.txt"; // input "INI" file 
118:     reportFile [0] = parm[0]+"r.txt"; // report file
119:     print1Parm [0] = reportFile[0];   // print from report file 
120:     input.read(inputFile);
121:     while (inputFile[1].substring(0,1).equals("="))
122:     {
123:         if (inputFile[1].substring(0,10).equals("=printNAM "))
124:         {
125:             print1Parm[1] = inputFile[1].substring(10);
126:             d.display("JsrVote--printNAM: "+print1Parm[1]);
127:         }
128:         if (inputFile[1].substring(0,10).equals("=printTYP "))
129:         {
130:             print1Parm[3] = inputFile[1].substring(10);
131:             d.display("JsrVote--printTYP: "+print1Parm[3]);
132:         }
133:         if (inputFile[1].substring(0,10).equals("=printLPP "))
134:         {
135:             tempInt = new Integer(inputFile[1].substring(10,13));
136:             printLPP = tempInt.intValue();
137:             d.display("JsrVote--printLPP="+printLPP);
138:         }
139:         input.read(inputFile);
140:     }
141:     
142:     voteTitle = inputFile[1];
143:     d.display("JsrVote--Title: "+voteTitle);
144:     input.read(inputFile);
145:     tempInt = new Integer(inputFile[1].substring(0,3));
146:     maxBatch = tempInt.intValue();
147:     d.display("JsrVote--maxBatch: "+maxBatch);
148:     input.read(inputFile);
149:     tempInt = new Integer(inputFile[1].substring(0,2));
150:     batchSize = tempInt.intValue();
151:     d.display("JsrVote--batchSize: "+batchSize);
152:     input.read(inputFile);
153:     tempInt = new Integer(inputFile[1].substring(0,2));
154:     maxRace = tempInt.intValue();
155:     d.display("JsrVote--maxRace: "+maxRace);
156:     input.read(inputFile);
157:     tempInt = new Integer(inputFile[1].substring(0,2));
158:     maxVote = tempInt.intValue();
159:     d.display("JsrVote--maxVote: "+maxVote);
160:     
161:     // the following are static (class) variables, accessible from inner classes
162:     // and from all methods.  They are declared static at top of class, then
163:     // their actual allocation size determined after size parameters are input.
164:      voteMax   = new       int[maxRace];  // Max # votes/Race (card input)
165:      raceName  = new    String[maxRace];  // Race Name        (card input)
166:      voteName  = new    String[maxVote];  // Candidate name   (card input)
167:     
168:      raceVotes = new       int[maxRace];  // # votes this Ballot by Race
169:      voteCount = new       int[maxVote];  // # votes by candidate 
170:      cummCount = new       int[maxVote];  // # votes by candidate 
171:      voteRace  = new       int[maxVote];  // Race index by candidate   
172:      voteArray = new      char[maxVote];  // the votes for this Ballot
173: 
174:    batchBallot = new       int[maxBatch]; // # ballots per batch
175:      batchVote = new       int[maxBatch][maxVote]; // votes per batch
176: 
177:     // d.display("Initializing b="+b);
178:     batchBallot[b] = 0;
179:     for (int i=0; i < maxVote; i++) batchVote[b][i] = 0;
180: 
181:     raceLabel1 = new JLabel[maxRace];
182:     raceLabel2 = new JLabel[maxRace];
183:     raceLabel3 = new JLabel[maxRace];
184:     voteBox   = new JCheckBox[maxVote];
185:     totLabel  = new JLabel[maxVote];
186:     batLabel  = new JLabel[maxVote];
187: 
188:     for (int i = 0; i < maxRace; i++)
189:     {
190:         raceVotes[i] = 0;
191:         raceName[i]  = "  ";
192:     }
193:     int ir = -1;  // individual race counter! 
194: 
195:     for (int iv = 0; iv < maxVote; iv++)
196:     {
197:         input.read(inputFile);  // add checking for input file and race change
198:         // d.display("Input: "+inputFile[1]+"***");
199:         if (!(inputFile[1].substring(0,1).equals("(")))
200:         {
201:             tempInt = new Integer(inputFile[1].substring(0,2));
202:             ir++;
203:             voteMax[ir] = tempInt.intValue();
204:             raceName[ir] = inputFile[1].substring(3);
205:             d.display("JsrVote--voteMax["+ir+"]: " + voteMax[ir] +
206:                       " raceName["+ir+"]: " + raceName[ir]);
207:             input.read(inputFile);
208:         } // can't have two ##Race Name in a row,
209:           // so next card is assumed to be in (k) Candidate Name format
210:         voteName[iv] = inputFile[1];
211:         d.display("JsrVote--Candidate: " + voteName[iv]
212:                   +" Race: " + raceName[ir]);
213:         voteRace[iv] =  ir;
214:     }
215:     //  ini file finished, now set up frame
216:     
217: 


SHARE: 
It's not an acronym.

It's
 what we do!

218:     try {        UIManager.setLookAndFeel(
219:             UIManager.getSystemLookAndFeelClassName());
220:         } catch (Exception e) { }  // set Look and Feel to Windows
221:         // System=Windows on Win32 systems, CrossPlatform=Metal (Java default)
222: 
223:     frame = new JFrame(voteTitle);
224:     frame.addWindowListener(new JsrWindowExit());
225:     // System.out.println("Frame created ");
226: 


SHARE: 
It's not an acronym.

It's
 what we do!

227:     // A simple menu class w/ Action listener (see page 419-420 Java Swing)
228:     class VoteMenuListener extends JMenuBar implements ActionListener
229:     {
230:         String[]   fileItems   = new String[] {"Exit"};
231:         char[]     fileShortCuts =            {'x'};
232:         String[]   reportItems = new String[] {"This Batch",
233:                                                "All Batches",
234:                                                "Plot Votes"};
235:         char[] reportShortCuts =              {'T','A','P'};
236:         public VoteMenuListener()  // constructor
237:         {
238:             JMenuItem fileItem;
239:             JMenu fileMenu = new JMenu("File");
240:             fileMenu.setMnemonic('F');
241:             for (int i=0; i < fileItems.length; i++)
242:             {
243:                 fileItem = new JMenuItem(fileItems[i], fileShortCuts[i]);
244:                 fileItem.addActionListener(this);
245:                 fileMenu.add(fileItem);
246:             }
247:             add(fileMenu); 
248:             JMenuItem reportItem;
249:             JMenu reportMenu = new JMenu("Reports");
250:             reportMenu.setMnemonic('R');
251:             for (int i=0; i < reportItems.length; i++)
252:             {
253:                 reportItem = new JMenuItem(reportItems[i], reportShortCuts[i]);
254:                 reportItem.addActionListener(this);
255:                 reportMenu.add(reportItem);
256:             }
257:             reportMenu.add(reportItem = new JCheckBoxMenuItem("Print On/Off"));
258:             reportItem.addActionListener(this);
259:             add(reportMenu);
260:         }


SHARE: 
It's not an acronym.

It's
 what we do!

261:         public void actionPerformed(ActionEvent menuEvent)
262:         {
263:             String menuItem=menuEvent.getActionCommand();
264:             // will do report logic from here
265:             Calendar rightNow = Calendar.getInstance();
266:             today = u.getDateTime();
267:             if (menuItem.equals("Print On/Off")) printOn = !printOn;
268:             // intuit printOn value rather than generate ItemListener 
269:             System.out.println("Menu="+ menuItem+" printOn/Off="+printOn+" "+today);
270:             if (menuItem.equals("This Batch"))  doThisReport();
271:             if (menuItem.equals("All Batches")) doAllReport();
272:             if (menuItem.equals("Plot Votes")) doPlotVotes();
273:             if (menuItem.equals("Exit"))
274:             {
275:                 d.display("Exiting");
276:                 output.close();
277:                 System.exit(0);
278:             }
279:         }
280:     }  // end class VoteMenuListener
281: 


SHARE: 
It's not an acronym.

It's
 what we do!

282:     // A simple ActionListener.
283:     class VoteActionListener implements ActionListener
284:     {
285:       public void actionPerformed(ActionEvent ex)
286:       {
287:         String choice = ex.getActionCommand();
288:         Integer vInteger = new Integer(choice);
289:         int v = vInteger.intValue();
290:         System.out.println("ACTION Candidate[" + choice + "] Selected!");
291:         voteBox[v].setSelected(true);
292:         // the above invokes itemStateChanged if it is a change
293:       }
294:     } // end class VoteActionListener
295: 
296:     // A simple ItemListener, showing each selection and deselection.


SHARE: 
It's not an acronym.

It's
 what we do!

297:     class VoteItemListener implements ItemListener
298:     {
299:       public void itemStateChanged(ItemEvent ex)
300:       {
301:        String item =
302:           ((AbstractButton)ex.getItemSelectable()).getActionCommand();
303:         
304:         boolean selected = (ex.getStateChange() == ItemEvent.SELECTED);
305:         Integer vInteger = new Integer(item);
306:         int v = vInteger.intValue();
307:         if (selected)
308:         {
309:             // System.out.println("voteArray[v]="+voteArray[v]+ "true");
310:             if (voteArray[v] == '0')
311:             {
312:                 if (raceVotes[voteRace[v]] == voteMax[voteRace[v]])
313:                 {
314:                     JOptionPane.showMessageDialog(frame,
315:                      "Maximum Votes this Race = "+voteMax[voteRace[v]]);
316:                      voteBox[v].setSelected(false);
317:                 }
318:                 else
319:                 {
320:                     voteArray[v] = '1';
321:                     raceVotes[voteRace[v]]++;
322:                 }
323:             }
324:         }
325:         else
326:         {
327:             // System.out.println("voteArray[v]="+voteArray[v]+ "false");
328:             if (voteArray[v] == '1')
329:             {
330:                 voteArray[v] = '0';
331:                 raceVotes[voteRace[v]]--;
332:             }
333:         }
334:         String voteString = "";
335:         for (int i = 0; i < maxVote; i++) voteString += voteArray[i]+",";
336:         
337:         System.out.println("  ITEM Candidate[" + item + "]: "  +
338:           " Votes=" + voteString + "* On/off=" + selected +
339:           " raceVotes=" + raceVotes[voteRace[v]] +
340:           " " + voteName[v]);
341:       }
342:     } // end class VoteItemListener
343: 
344: 
345: 
346:     // p1+i.txt Initialization file read
347:     // following renames will only work if files are closed (OK here, see JsrEdit.java).
348:      inputFile[0] = parm[0]+"v.$$$";
349:     outputFile[0] = parm[0]+"v.txt";
350:     File  txtFD = new File(outputFile[0]);
351:     File tempFD = new File( inputFile[0]);
352:     if (txtFD.exists() != true)
353:     {
354:         d.display("JsrVote--File: "+outputFile[0]+" does not exist!");
355:         System.exit(4);
356:     }
357:     if (tempFD.exists() == true) 
358:         d.display("JsrVote--delete " + tempFD+"=" + tempFD.delete());
359:     d.display("JsrVote--rename "+txtFD+ " to "
360:                        + tempFD+"=" + txtFD.renameTo(tempFD));
361:     input.read(inputFile);  // copy header line
362:     outputFile[1] = inputFile[1];
363:     output.write(outputFile);
364: 
365:     String         acString  = " "; 


SHARE: 
It's not an acronym.

It's
 what we do!

366:     ActionListener al = new VoteActionListener();
367:     ItemListener   il = new VoteItemListener();
368: 
369:     // System.out.println("Initializing constants");
370: 
371:     for (int i = 0; i < maxRace; i++)
372:     {
373:         d.display("Initializing raceLabel["+ i +"]: "+raceName[i]);
374:         raceLabel1[i] = new JLabel(raceName[i]);
375:         raceLabel1[i].setFont(defaultFont);
376:         raceLabel2[i] = new JLabel("   ",SwingConstants.RIGHT);
377:         raceLabel3[i] = new JLabel("   ",SwingConstants.RIGHT);
378:     }
379: 
380:     for (int i = 0; i < maxVote; i++)
381:     {
382:         // System.out.println("Initializing totLabel["+i+"]");
383:         voteArray[i] = '0';
384:         voteCount[i] =  0;
385:         batLabel[i] = new JLabel("0",JLabel.RIGHT);
386:         batLabel[i].setFont(defaultFont);
387:         totLabel[i] = new JLabel("0",JLabel.RIGHT);
388:         totLabel[i].setFont(defaultFont);
389:         voteBox[i] = new JCheckBox(" "+voteName[i], false);
390:         voteBox[i].setToolTipText("Check Box or type underlined # to select.");
391:         voteBox[i].setFont(defaultFont);
392:         tempInt = new Integer(i);
393:         acString   = tempInt.toString();
394:         voteBox[i].setActionCommand(acString);
395:         voteBox[i].setMnemonic(voteName[i].charAt(1));
396:         KeyStroke aKey = KeyStroke.getKeyStroke(voteName[i].charAt(1));
397:         voteBox[i].addItemListener(il);
398:         voteBox[i].registerKeyboardAction(al,acString,aKey,
399:                JComponent.WHEN_IN_FOCUSED_WINDOW);
400:     }
401: 
402: 
403:     // System.out.println("Constants set ");


SHARE: 
It's not an acronym.

It's
 what we do!

404:     // now can continue with input file
405:     String vChar;
406:     while (0 <= input.read(inputFile))
407:     {
408:         // System.out.println("Input VoteString: "+inputFile[1]);
409:         if (inputFile[1].length() < (maxVote*2))
410:         {
411:            d.display("Skipping line of length="+inputFile[1].length());
412:         }
413:         else
414:         {   
415:             newVote (); 
416:             for (int v=0; v < maxVote; v++)
417:             {
418:                 vChar = inputFile[1].substring(v*2,v*2+1);    
419:                 // System.out.println("v="+v+"v*2="+(v*2)+"=="+vChar);
420:                 if (vChar.equals("1"))
421:                 {
422:                    voteCount[v]++;
423:                    batchVote[b][v]++;
424:                 }
425:             }
426:             voteBallot++;
427:             batchBallot[b]++;
428:             writeBallot(inputFile[1]);
429:         }
430:        
431:     }
432:     // System.out.println("After input votes.");
433:     batSumLabel.setText(" "+ batchBallot[b]);
434:     totSumLabel.setText("Total: " + voteBallot);
435:     for (int v=0; v < maxVote; v++)
436:     {
437:         batLabel[v].setText(" "+batchVote[b][v]);
438:        totLabel[v].setText(" "+voteCount[v]);
439:     }
440:    
441: 


SHARE: 
It's not an acronym.

It's
 what we do!

442:     // Throw everything together.
443:     frame.setJMenuBar(new VoteMenuListener());
444:     Container c = frame.getContentPane();
445: 
446:     c.setLayout(new GridLayout(maxVote+maxRace+2,3)); // items added left to right
447: 
448:     batHead.setText("Batch # "+(b+1));
449:     batHead.setFont(defaultFont);
450:     totHead.setFont(defaultFont);
451:     c.add(dotLabel1);
452:     c.add(batHead);
453:     c.add(totHead);
454: 
455:     ir = -1;
456:     for (int i = 0; i < maxVote; i++)
457:     {
458:         if (voteRace[i] != ir)
459:         {
460:             ir = voteRace[i];
461:             c.add(raceLabel1[ir]);
462:             c.add(raceLabel2[ir]);
463:             c.add(raceLabel3[ir]);
464:         }
465:         c.add(voteBox[i]);
466:         c.add(batLabel[i]);
467:         c.add(totLabel[i]);
468:      
469:     }


SHARE: 
It's not an acronym.

It's
 what we do!

470:     JButton voteButton = (new JButton("Vote"));
471:     voteButton.setMnemonic('V');
472:     voteButton.setToolTipText("Press Vote button (or enter) to cast one ballot.");
473:     voteButton.addActionListener(new ActionListener()
474:     {
475:         public void actionPerformed(ActionEvent ev)
476:         {
477:             String voteString = "";
478:             newVote(); 
479:             if (batchBallot[b] == 0)
480:             {
481:                 batHead.setText("Batch # "+(b+1));
482:                 for (int i = 0; i < maxVote; i++)
483:                     batLabel[i].setText(" "+batchVote[b][i]);
484:                     // reset labels to zero if batch changes
485:             }
486:             
487:             for (int i = 0; i < maxVote; i++)
488:             {
489:                 voteString += voteArray[i]+",";
490:                 if (voteArray[i] == '1')
491:                 {
492:                     // voteArray[i] = '0'; this will be done by itemListener
493:                     voteBox[i].setSelected(false);
494:                     batchVote[b][i]++;
495:                     voteCount[i]++;
496:                     batLabel[i].setText(" "+batchVote[b][i]);
497:                     totLabel[i].setText(" "+voteCount[i]);
498:                 }
499:             }
500:             voteBallot++;
501:             batchBallot[b]++;
502:             batSumLabel.setText(" "+ batchBallot[b]);
503:             totSumLabel.setText("Total: " + voteBallot);
504:             voteString += u.padZero(voteBallot,5);
505:             for (int i = 0; i < maxRace; i++)  raceVotes[i] = 0;
506: 	               
507:             System.out.println("Vote Button Pressed, Votes=" + voteString);
508:             writeBallot(voteString);
509:             if (batchBallot[b] == batchSize)
510:                     JOptionPane.showMessageDialog(frame,
511:                      "Please generate This Batch Report now.  \n"+
512:                      "Thanks, and Have a Nice Day!");
513:         }
514:     });   //  yes that is } bracket and ) parenthesis.
515:     
516:     c.add(voteButton);
517:     batSumLabel.setFont(defaultFont);
518:     totSumLabel.setFont(defaultFont);
519:     c.add(batSumLabel);
520:     c.add(totSumLabel);
521: 

SHARE: 
It's not an acronym.

It's
 what we do!



SHARE: 
It's not an acronym.

It's
 what we do!

522:     // System.out.println("Frame display ");
523:     
524:     frame.pack(); // sets size to just as big as it needs to be
525:     // frame.setSize(600,600); // or could set to specific size
526:    
527:     frame.setVisible(true);
528:     voteButton.grabFocus();  // must be done after screen is visible
529:                              // try grabFocus vs. requestFocus   
530:   }
531: 
532:   public static void newVote()
533:   {
534:       // d.display("newVote: b="+b+" batchBallot[b]="+batchBallot[b]+"batchSize="+batchSize);      
535:       if (batchBallot[b] == batchSize)
536:       {
537:           b++;
538:           batchBallot[b] = 0;
539:           for (int i=0; i < maxVote; i++) batchVote[b][i] = 0;
540:       }
541:   }
542: 
543:   public static void writeBallot(String voteString)
544:   {
545:       outputFile[1] = voteString;  
546:       output.write(outputFile);   
547:   }
548: 


SHARE: 
It's not an acronym.

It's
 what we do!

549:   public static void doAllReport()
550:   {
551:     d.display("doAllReport called, Last Batch # "+(b+1));
552:     for (int i=0; i < maxVote; i++) cummCount[i] = 0;
553:     cummBallot = 0;
554:     lineCount = 999; // force report to page break
555:     for (int bt=0; bt <= b; bt++)
556:     {
557:       //d.display("lineCount="+lineCount+"/"+printLPP);
558:       if  ((lineCount+maxVote+4) > printLPP)
559:       {
560:           printOneLine("1JsrVote    "+voteTitle);
561:           printOneLine(" "+today+"        All Batches  Report");
562:           lineCount = 4;
563:       }
564:       lineCount++;  // extra bump for double space
565:       printOneLine("0Race & Candidate         Batch #"+u.padLeft(bt+1, 3)+"  All Batches");
566:       for (int i=0; i < maxVote; i++)
567:       {
568:           if ((i == 0) || (voteRace[i] != voteRace[i-1]))
569:               printOneLine(raceName[voteRace[i]]);
570:           cummCount[i] += batchVote[bt][i];
571:           printOneLine(" "+u.padRight(voteName[i],25)
572:                           +u.padLeft(batchVote[bt][i],10)
573:                           +u.padLeft(cummCount[i],12));
574:       }
575:       cummBallot += batchBallot[bt];
576:       printOneLine(" Totals                   " +u.padLeft(batchBallot[bt],10)
577:                                                 +u.padLeft(cummBallot,12));
578:     }
579:     report.close();
580:     if (printOn) print1.main(print1Parm);
581:   }
582: 
583:   public static void doThisReport()
584:   {
585:       System.out.println("doThisReport called, Batch # "+(b+1));
586:       lineCount = 999; // force report to page break
587:       if  (lineCount > printLPP)
588:       {
589:           printOneLine("1JsrVote    "+voteTitle);
590:           printOneLine(" "+today+"      Current Batch  Report");
591:           lineCount = 4;
592:       }
593:       printOneLine("0Race & Candidate         Batch #"+u.padLeft(b+1, 3)+"  All Batches");
594:       for (int i=0; i < maxVote; i++)
595:       {
596:           if ((i == 0) || (voteRace[i] != voteRace[i-1]))
597:               printOneLine(raceName[voteRace[i]]);
598:           printOneLine(" "+u.padRight(voteName[i],25)
599:                           +u.padLeft(batchVote[b][i],10)
600:                           +u.padLeft(voteCount[i],12));
601:       }
602:       printOneLine(" Totals                   " +u.padLeft(batchBallot[b],10)
603:                                                 +u.padLeft(voteBallot,12));
604:       report.close();
605:       if (printOn) print1.main(print1Parm);
606:   }
607: 
608:   public static void doPlotVotes()
609:   {
610:       
611:       d.display("doPlotVotes called, Batch # "+(b+1));
612:       lineCount = 999; // force report to page break
613:       if  (lineCount > printLPP)
614:       {
615:           printOneLine("1JsrVote    "+voteTitle);
616:           printOneLine(" "+today+"      Plot Votes");
617:           lineCount = 4;                           
618:       }
619:       printOneLine("0# Ballots Cast: "+u.padLeft(voteBallot,12));
620:       int plotSpread = 80 / (b+1);
621:       //d.display("alloc plotChar[50]["+plotSpread*(b+1)+"]");
622:       char [][] plotChar = new char[50][plotSpread*(b+1)];
623:       for (int i=0; i < 50; i++)
624:           for (int j=0; j < (plotSpread*(b+1)); j++)
625:               plotChar[i][j] = ' ';
626:       //d.display("init cummCount");
627:       for (int i=0; i < maxVote; i++) cummCount[i] = 0;
628:       for (int bt=0; bt <= b; bt++)
629:       {
630:         for (int i=0; i < maxVote; i++)
631:         {
632:             //d.display("CummCount set="+ cummCount[i] +"+="+ batchVote[bt][i] );
633:             cummCount[i] += batchVote[bt][i];
634:             int p = (cummCount[i] * 50) / voteBallot;
635:             //d.display("bt="+bt+" * X="+(plotSpread*bt)+" p="+p+
636:               //        " Vote="+cummCount[i]+" Who: "+voteName[i]);
637:             if (plotChar[p][plotSpread*bt] == ' ')
638:                 plotChar[p][plotSpread*bt] = voteName[i].charAt(1);
639:             else
640:                 plotChar[p][plotSpread*bt] = '*';
641:             //d.display("after set plotChar...");
642:         }
643:       }
644:       for (int p=49; p >=0; p--)
645:       {
646:          String printString = new String("          |");
647:          if (p == 49) printString = u.padLeft(voteBallot,10) + "+";
648:          if (p == 36) printString = u.padLeft(voteBallot*3/4,10) + "+";
649:          if (p == 24) printString = u.padLeft(voteBallot/2,10) + "+";
650:          if (p == 11) printString = u.padLeft(voteBallot/4,10) + "+";
651:          for (int bt=0; bt<=(plotSpread*b); bt++) printString += plotChar[p][bt];
652:          printOneLine(" "+printString);
653:       }
654:       printOneLine("          0+---------+---------+---------+---------+"+
655:                                "---------+---------+---------+---------+");
656:       printOneLine("            Batches->");
657:       report.close();
658:       if (printOn) print1.main(print1Parm);
659:   }
660: 
661: 
662:   public static void printOneLine(String oneLine)
663:   {
664:       reportFile[1] = oneLine.substring(0,1)+"        "+oneLine.substring(1);
665:       report.write(reportFile);
666:       lineCount++;
667:   }
668: 
669: 
670:   
671: }
672: // end of JsrVote.java program


SHARE: 
It's not an acronym.

It's
 what we do!

JsrWindowExit.java    245 Sat Jul 31 14:51:44 CDT 1999
  1: import java.awt.event.*;
  2: import java.awt.Window;
  3: 
  4: public class JsrWindowExit extends WindowAdapter {
  5: 
  6:   public void windowClosing(WindowEvent e) {
  7:     Window w = e.getWindow();
  8:     w.setVisible(false);
  9:     w.dispose();
 10:     System.exit(0);
 11:   }
 12: }

Return to JSR Systems Services.
Return to JSR Systems' home page.
Copyright © 2000, JSR Systems, All rights reserved.