About Java and xBaseJ- P8 - Pdf 76

Chapter 2 – Mega­Zillionaire Application
707) megaNoStat = new StatElms[ ELM_COUNT];
708) System.out.println( "Initializing megaNoStat");
709) for (l_x=1; l_x < ELM_COUNT; l_x++ ) {
710) megaNoStat[ l_x] = new StatElms();
711) megaNoStat[ l_x].elmNo = l_x;
712) } // end for loop to init stats
713)
714)
715) megaDBF.open_database();
716)
717) // Create a statement
718) try {
719) l_record_count = megaDBF.getDBF().getRecordCount();
720)
721) for (l_x=1; l_x <= l_record_count; l_x++) {
722) megaDBF.getDBF().gotoRecord( l_x);
723) l_draw_no++;
724) updateDrawStats( Integer.parseInt( megaDBF.No_1.get().trim
()));
725) updateDrawStats( Integer.parseInt( megaDBF.No_2.get().trim
()));
726) updateDrawStats( Integer.parseInt( megaDBF.No_3.get().trim
()));
727) updateDrawStats( Integer.parseInt( megaDBF.No_4.get().trim
()));
728) updateDrawStats( Integer.parseInt( megaDBF.No_5.get().trim
()));
729) updateMegaStats( Integer.parseInt( megaDBF.Mega_No.get
().trim()));
730)

761)
762) drawStatDBF.create_database( "drawst");
763) megaStatDBF.create_database( "megast");
141
Chapter 2 – Mega­Zillionaire Application
764)
765)
766) System.out.println( "Writing mega stats records");
767) System.out.println( "Value of l_draw_no " + l_draw_no);
768)
769) for (l_x=1; l_x < ELM_COUNT; l_x++ ) {
770) drawNoStat[ l_x].pctHits = (double)( megaNoStat[ l_x].hitCount) /
771) (double)( l_draw_no);
772) l_missed = l_draw_no - megaNoStat[ l_x].hitCount;
773) megaNoStat[ l_x].aveBtwn = (double)( l_missed) /
774) (double)( drawNoStat[ l_x].hitCount);
775) megaNoStat[ l_x].sinceLast = l_draw_no - megaNoStat
[l_x].lastDrawNo;
776)
777) try {
778) megaStatDBF.Elm_No.put( megaNoStat[ l_x].elmNo);
779) megaStatDBF.Hit_Count.put( megaNoStat[ l_x].hitCount);
780) megaStatDBF.Last_Draw_No.put( megaNoStat[ l_x].lastDrawNo);
781) megaStatDBF.Since_Last.put( megaNoStat[ l_x].sinceLast);
782) megaStatDBF.Curr_Seq.put( megaNoStat[ l_x].currSeq);
783) megaStatDBF.Longest_Seq.put( megaNoStat[ l_x].longestSeq);
784) megaStatDBF.Pct_Hits.put( megaNoStat[ l_x].pctHits);
785) megaStatDBF.Max_Btwn.put( megaNoStat[ l_x].maxBtwn);
786) megaStatDBF.Ave_Btwn.put( megaNoStat[ l_x].aveBtwn);
787)

817) drawStatDBF.Ave_Btwn.put( drawNoStat[ l_x].aveBtwn);
818)
819) drawStatDBF.getDBF().write();
820) } catch( xBaseJException s) {
821) display_error_msg( "Error adding Drawing Stat record " +
822) s.toString());
823) } catch( IOException i) {
824) display_error_msg( "Error reading DBF " + i.toString());
142
Chapter 2 – Mega­Zillionaire Application
825) }
826) } // end for l_x loop
827)
828) System.out.println( "All Stats records successfully written");
829) JRootPane j = (JRootPane) SwingUtilities.getAncestorOfClass
( JRootPane.class, no1);
830) if ( j != null) {
831) JOptionPane.showMessageDialog(j,"All Stats records successfully
written",
832) "Stats Generated",
JOptionPane.PLAIN_MESSAGE);
833) }
834) else
835) System.out.println( "j was null");
836)
837) } // end writeDrawStats method
838)
839)
840) private void updateDrawStats( int num_sub) {
841) int l_x;

870)
871) if (l_x == 1)
872) {
873) megaNoStat[ num_sub].currSeq++;
874) if (megaNoStat[ num_sub].currSeq > megaNoStat
[ num_sub].longestSeq)
875) {
876) megaNoStat[ num_sub].longestSeq = megaNoStat
[ num_sub].currSeq;
877) }
878) }
879) else {
880) megaNoStat[ num_sub].currSeq = 0;
143
Chapter 2 – Mega­Zillionaire Application
881) if (l_x > megaNoStat[num_sub].maxBtwn)
882) {
883) megaNoStat[ num_sub].maxBtwn = l_x;
884) }
885) } // end test for sequence
886)
887) megaNoStat[ num_sub].hitCount++;
888) megaNoStat[ num_sub].lastDrawNo = l_draw_no;
889) megaNoStat[ num_sub].sinceLast = l_x;
890) } // end updateMegaStats method
891)
892)
893) private boolean is_record_valid() {
894) if (no1.getValue() == null) {
895) errorMsg = "No 1 Invalid";

926) megaNo.requestFocus();
927) return false;
928) }
929)
930) return true;
931) } // end is_record_valid method
932)
933) void display_error_msg( String msg) {
934) JRootPane m = (JRootPane)
935) SwingUtilities.getAncestorOfClass( JRootPane.class, drawingDate);
936) if ( m != null)
937) {
938) JOptionPane.showMessageDialog(m, msg, "Entry",
939) JOptionPane.ERROR_MESSAGE);
940) }
941) else
942) System.out.println( "m was null msg was |" + msg + "|");
943) } // end display_error_msg
144
Chapter 2 – Mega­Zillionaire Application
944)
945)
946) /*;;;;;
947) * method to find first record
948) *;;;;;
949) */
950) private boolean firstRecord() {
951) int l_x=0;
952) boolean retVal=false;
953) String find_str;

982) no3.setValue( new Integer(lNo3));
983) no4.setValue( new Integer(lNo4));
984) no5.setValue( new Integer(lNo5));
985) megaNo.setValue( new Integer(lMegaNo));
986) retVal = true;
987) } catch( xBaseJException s) {
988) display_error_msg( "Unable to find " + localDateStr +
989) "Error was " + s.toString());
990) draw_dt_str = " ";
991) lNo1 = lNo2 = lNo3 = lNo4 = lNo5 = lMegaNo = 0;
992) no1.setValue( null);
993) no2.setValue( null);
994) no3.setValue( null);
995) no4.setValue( null);
996) no5.setValue( null);
997) megaNo.setValue( null);
998) deletedFlg.setText(" ");
999) drawingDate.setValue( null);
1000) } catch( IOException i) {
1001) display_error_msg( "Unable to find " + localDateStr +
1002) "Error was " + i.toString());
1003) draw_dt_str = " ";
1004) lNo1 = lNo2 = lNo3 = lNo4 = lNo5 = lMegaNo = 0;
145
Chapter 2 – Mega­Zillionaire Application
1005) no1.setValue( null);
1006) no2.setValue( null);
1007) no3.setValue( null);
1008) no4.setValue( null);
1009) no5.setValue( null);

1040)
1041) return retVal;
1042) } // end firstRecord method
1043)
1044) /*;;;;;
1045) * method to find previous record based upon drawing date
1046) *;;;;;
1047) */
1048) private boolean prevRecord() {
1049) int l_x=0;
1050) boolean retVal=false;
1051) String find_str;
1052) String localDateStr=null;
1053)
1054) if (currMode != FIND_MODE) {
1055) display_error_msg( "Must have previously found to move back one
record");
1056) return false;
1057) }
1058)
1059) draw_dt_str = drawingDate.getText();
1060) pad_draw_dt_str();
1061)
1062) try {
1063) localDateStr = out_format.format( out_format.parse
(draw_dt_str));
1064) }
1065) catch( ParseException p) {
146
Chapter 2 – Mega­Zillionaire Application

1095) drawingDate.setValue( new Integer(out_format.format
(dDrawingDate)));
1096) draw_dt_str = out_format.format( dDrawingDate);
1097) no1.setValue( new Integer(lNo1));
1098) no2.setValue( new Integer(lNo2));
1099) no3.setValue( new Integer(lNo3));
1100) no4.setValue( new Integer(lNo4));
1101) no5.setValue( new Integer(lNo5));
1102) megaNo.setValue( new Integer(lMegaNo));
1103) retVal = true;
1104) } catch( xBaseJException s) {
1105) display_error_msg( "Unable to find " + localDateStr +
1106) "Error was " + s.toString());
1107) draw_dt_str = " ";
1108) lNo1 = lNo2 = lNo3 = lNo4 = lNo5 = lMegaNo = 0;
1109) no1.setValue( null);
1110) no2.setValue( null);
1111) no3.setValue( null);
1112) no4.setValue( null);
1113) no5.setValue( null);
1114) megaNo.setValue( null);
1115) drawingDate.setValue( null);
1116) deletedFlg.setText(" ");
1117) } catch( IOException i) {
1118) display_error_msg( "Unable to find " + localDateStr +
1119) "Error was " + i.toString());
1120) draw_dt_str = " ";
1121) lNo1 = lNo2 = lNo3 = lNo4 = lNo5 = lMegaNo = 0;
1122) no1.setValue( null);
1123) no2.setValue( null);

1152) no5.setValue( null);
1153) megaNo.setValue( null);
1154) drawingDate.setValue( null);
1155) deletedFlg.setText(" ");
1156) }
1157)
1158) return retVal;
1159) } // end prevRecord method
1160)
1161) /*;;;;;
1162) * method to find a next record based upon drawing date
1163) *;;;;;
1164) */
1165) private boolean nextRecord() {
1166) int l_x=0;
1167) boolean retVal=false;
1168) String find_str;
1169) String localDateStr=null;
1170)
1171) draw_dt_str = drawingDate.getText();
1172) pad_draw_dt_str();
1173)
1174) try {
1175) localDateStr = out_format.format( out_format.parse
(draw_dt_str));
1176) }
1177) catch( ParseException p) {
1178) display_error_msg( "Error parsing date " + p.toString());
1179) localDateStr = null;
1180) }


Nhờ tải bản gốc
Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status