Annotation of capa/capa51/JavaTools/TScore.java, revision 1.2
1.1 albertel 1: import java.applet.*;
2: import java.awt.*;
3: import java.lang.*;
4: import java.util.*;
5: import java.net.*;
6: import java.awt.event.*;
7:
8: public class TScore extends Applet implements Runnable {
9: public float W[];
10: public int Entry_cnt, Exam_cnt;
11: public float S[], F[];
12: public int X[], C[], R[];
13: public float SF_ratio[], SF_percent[];
14: public float Sum_ratio[], Sum_percent[];
15: public float Exam_ratio[], Raw_exam_ratio[], Raw_epc_ratio[];
16: public float Term_score;
17:
18: ExpPanel [] HQpanel;
19: ExmPanel [] EXpanel;
20: Label TitleL;
21: Label EqL;
22:
23: public void init() {
24: String p;
25: int fs;
26: int idx;
27:
28: C = new int[2];
29: R = new int[2];
30: W = new float[5];
31:
32: // final exam set number
33: p=getParameter("FS");
34: fs = (p==null)?1:Integer.valueOf(p).intValue();
35: // how many entries
36: Entry_cnt= ((fs == 0)? 2 : 1 + 2*fs);
37: // how many exams
38: Exam_cnt = (Entry_cnt - 3 ) / 2;
39:
40: S = new float[Entry_cnt];
41: F = new float[Entry_cnt];
42: X = new int[Entry_cnt];
43: SF_ratio = new float[Entry_cnt];
44: SF_percent= new float[Entry_cnt];
45: Sum_ratio = new float[Entry_cnt];
46: Sum_percent = new float[Entry_cnt];
47: Raw_exam_ratio = new float[Exam_cnt];
48: Raw_epc_ratio = new float[Exam_cnt];
49: Exam_ratio = new float[Exam_cnt];
50:
51: p=getParameter("HW_W");
52: W[0] =(p==null)?1:Float.valueOf(p).floatValue();
53: p=getParameter("QZ_W");
54: W[1] =(p==null)?1:Float.valueOf(p).floatValue();
55: p=getParameter("EX_W");
56: W[2] =(p==null)?1:Float.valueOf(p).floatValue();
57: p=getParameter("FE_W");
58: W[3] =(p==null)?1:Float.valueOf(p).floatValue();
59: p=getParameter("PC_W");
60: W[4] =(p==null)?1:Float.valueOf(p).floatValue();
61:
62: p=getParameter("HW_C");
63: C[0] =(p==null)?1:Integer.valueOf(p).intValue();
64: p=getParameter("HW_R");
65: R[0] =(p==null)?1:Integer.valueOf(p).intValue();
66: p=getParameter("QZ_C");
67: C[1] =(p==null)?1:Integer.valueOf(p).intValue();
68: p=getParameter("QZ_R");
69: R[1] =(p==null)?1:Integer.valueOf(p).intValue();
70:
71: for(idx=0;idx<Entry_cnt;idx++) {
72: p=getParameter("X"+idx);
73: X[idx]=(p==null)?1:Integer.valueOf(p).intValue();
74: if( (idx>1) && (X[idx]==1) ) { // midterm exam, final extrapolated
75: SF_ratio[idx] = (float)0.0;
76: SF_percent[idx]= (float)0.0;
77: if( idx == (Entry_cnt - 1) ) { // final exam extrapolated, from hw
78: Sum_ratio[idx] = SF_ratio[0];
79: Sum_percent[idx] = SF_percent[0];
80: }
81: } else {
82: // homework, quiz extrapolated or not;exam,final not extrapolated
83: p=getParameter("S"+idx);
84: S[idx]=(p==null)?1:Float.valueOf(p).floatValue();
85: p=getParameter("F"+idx);
86: F[idx] =(p==null)?1:Float.valueOf(p).floatValue();
1.2 ! albertel 87: if ((float)F[idx] < 0.00000001) {
! 88: SF_ratio[idx] = (float) 0.0;
! 89: } else {
! 90: SF_ratio[idx] = (float) ((float)S[idx] / (float)F[idx]);
! 91: }
1.1 albertel 92: int tmp_i = (int) (10000 * SF_ratio[idx] );
93: SF_percent[idx]= (float)tmp_i / (float)100.0;
94: if( idx == (Entry_cnt - 1) ) { // final exam
95: Sum_ratio[idx] = SF_ratio[idx];
96: Sum_percent[idx] = SF_percent[idx];
97: }
98: }
99: }
100: Sum_ratio[0] = (float)(S[0] + ((float)R[0]*F[0]*SF_ratio[0]/(float)C[0])) / (float)(F[0]*(1.0 + (float)R[0]/(float)C[0]));
101: int tmp_i = (int)(10000 * Sum_ratio[0]);
102: Sum_percent[0] = (float)tmp_i / (float)100.0;
103: Sum_ratio[0] = Sum_percent[0] / (float)100.0;
104: Sum_ratio[1] = (float)(S[1] + (R[1]*F[1]*SF_ratio[1]/C[1])) / (float)(F[1]*(1.0 + R[1]/C[1]));
105: tmp_i = (int)(10000 * Sum_ratio[1]);
106: Sum_percent[1] = (float)tmp_i / (float)100.0;
107: Sum_ratio[1] = Sum_percent[1] / (float)100.0;
108:
109:
110: // if exam 1 is not given, use homework as default to extrapolate
111: // if epc 1 is not given, use exam 1 as epc 1
112: // if exam 2 is not given, use exam 1 to extrapolate
113: // if exam 3 is not given, use exam 2 to extrapolate
114: //
115:
116: float exam_sum = (float)0.0;
117: for(idx=0;idx<Exam_cnt;idx++) {
118: if( X[(idx+1)*2] == 1 ) {
119: // taken from homework
120: Raw_exam_ratio[idx] = SF_ratio[0];
121: } else {
122: Raw_exam_ratio[idx] = SF_ratio[(idx+1)*2];
123: }
124: if( X[(idx+1)*2 + 1] == 1 ) {
125: Raw_epc_ratio[idx] = Raw_exam_ratio[idx];
126: } else {
127: Raw_epc_ratio[idx] = SF_ratio[(idx+1)*2 + 1];
128: }
129:
130: if( Raw_epc_ratio[idx] > Raw_exam_ratio[idx] ) {
131: Exam_ratio[idx] = Raw_exam_ratio[idx] + W[4]*( Raw_epc_ratio[idx] - Raw_exam_ratio[idx] ) ;
132: } else {
133: Exam_ratio[idx] = Raw_exam_ratio[idx];
134: }
135:
136: Sum_ratio[2*(idx+1)] = Exam_ratio[idx];
137: tmp_i = (int)(10000 * Exam_ratio[idx] );
138: Sum_percent[2*(idx+1)] = (float)tmp_i / (float)100.0;
139: Sum_ratio[2*(idx+1)] = Sum_percent[2*(idx+1)] / (float)100.0;
140: exam_sum += Exam_ratio[idx];
141: }
142: exam_sum = (float)exam_sum / (float)Exam_cnt;
143:
144: Term_score = Sum_ratio[0] * W[0] + Sum_ratio[1] * W[1] + exam_sum * W[2] + Sum_ratio[Entry_cnt - 1] * W[3];
145:
146: tmp_i = (int)(10000 * Term_score);
147: Term_score = (float)tmp_i / (float)100.0;
148:
149:
150: // call to setup User Interface
151:
152: initGUI();
153:
154: }
155: public void initGUI() {
156: int row_cnt = Exam_cnt + 4;
157: int idx;
158: String [] title = {"Homework", "Quizz" };
159: HQpanel = new ExpPanel[2];
160: EXpanel = new ExmPanel[Exam_cnt+2];
161:
162: setLayout(new GridLayout(row_cnt,0,4,4));
163:
164: String t_str = "Term Score Extrapolation Applet";
165: TitleL = new Label(t_str, Label.CENTER);
166: add(TitleL);
167:
168: for(idx = 0; idx < 2; idx++) {
169: HQpanel[idx] = new ExpPanel(this,title[idx],X[idx],
170: S[idx],F[idx],C[idx],R[idx]);
171: add(HQpanel[idx]);
172: }
173: // Midterm Exam
174: for(idx =0; idx < Exam_cnt; idx++) {
175: EXpanel[idx] = new ExmPanel(this,idx+1,X[2*(idx+1)],1,X[2*idx+3],
176: S[2*(idx+1)],F[2*(idx+1)],W[4],S[2*idx+3],F[2*idx+3],Sum_ratio[2*(idx+1)]);
177: add(EXpanel[idx]);
178: }
179: // Final Exam
180: EXpanel[Exam_cnt] = new ExmPanel(this,0,X[Entry_cnt-1],0,0,
181: S[Entry_cnt-1],F[Entry_cnt-1],W[3],S[Entry_cnt-1],F[Entry_cnt-1],Sum_ratio[Entry_cnt-1]);
182: add(EXpanel[Exam_cnt]);
183:
184: String eq_str = "Term score=" + Sum_percent[0] + "*" + W[0] ;
185: eq_str = eq_str + "+" + Sum_percent[1] + "*" + W[1] ;
186: eq_str = eq_str + "+" + "(" ;
187: for(idx =1;idx<=Exam_cnt;idx++) {
188: if(idx>1) {
189: eq_str = eq_str + "+ ";
190: }
191: eq_str = eq_str + Sum_percent[2*idx] ;
192: }
193: eq_str = eq_str + ") *" + W[2] + "/" + Exam_cnt + "+";
194: eq_str = eq_str + Sum_percent[2*idx] + "*" + W[3] + " = ";
195: eq_str = eq_str + " " + Term_score + "%";
196: // EqL = new Label(eq_str, Label.LEFT);
197: // add(EqL);
198:
199: }
200: public void recalcTermScore() {
201: float score[];
202: int idx;
203: float term_summ, exam_summ;
204:
205: score = new float[Exam_cnt+3];
206: term_summ = (float)0.0;
207: exam_summ = (float)0.0;
208: for(idx=0;idx<2;idx++) {
209: score[idx] = HQpanel[idx].getSubTotal();
210: term_summ = term_summ + score[idx] * W[idx];
211: }
212: for(idx =0; idx < Exam_cnt; idx++) {
213: score[idx+2] = EXpanel[idx].getSubTotal();
214: exam_summ = exam_summ + score[idx+2];
215: }
216: score[Exam_cnt+2] = EXpanel[Exam_cnt].getSubTotal();
217: exam_summ = exam_summ * W[2] / Exam_cnt;
218: term_summ = term_summ + exam_summ + score[Exam_cnt+2] * W[3];
219: int tmp_i = (int) ((float)100.0*term_summ);
220: term_summ = (float)(tmp_i / (float)100.0);
221: String eq_str = "Term score=" + score[0] + "*" + W[0] ;
222: eq_str = eq_str + "+" + score[1] + "*" + W[1] ;
223: eq_str = eq_str + "+" + "(" ;
224: for(idx=0;idx<Exam_cnt;idx++) {
225: if(idx>0) {
226: eq_str = eq_str + "+ ";
227: }
228: eq_str = eq_str + score[idx+2] ;
229: }
230: eq_str = eq_str + ") *" + W[2] + "/" + Exam_cnt + "+";
231: eq_str = eq_str + score[Exam_cnt+2] + "*" + W[3] + " = ";
232: eq_str = eq_str + " " + term_summ + " %";
233: // TitleL.setText("TTT");
234: TitleL.setText(eq_str);
235: }
236: public void paint(Graphics g) {
237: Dimension d = getSize();
238: g.drawRect(0,0, d.width - 1, d.height - 1);
239: }
240: public void run() { }
241: public void start() {
242: recalcTermScore();
243: }
244: public void stop() { }
245:
246: }
1.2 ! albertel 247: class ExpPanel extends Panel
! 248: implements ActionListener,
! 249: AdjustmentListener {
! 250: TScore controller;
! 251: TextField exT;
! 252: Scrollbar sB;
! 253: Label sumL;
! 254: int max = 100;
! 255: int block = 1;
! 256: float ff,ss;
! 257: int rr,cc;
! 258:
! 259: ExpPanel(TScore u,String t,
! 260: int x,float a,float b,int m,int n) {
! 261: GridBagConstraints c = new GridBagConstraints();
! 262: GridBagLayout gridbag = new GridBagLayout();
! 263: setLayout(gridbag);
! 264: int tmp_i;
! 265:
! 266: controller = u;
! 267: ss = a; ff = b; cc = m; rr = n;
! 268: float sf_ratio = (float)ss / (float)ff;
! 269: tmp_i = (int)(10000 * sf_ratio);
! 270: float sf_percent = (float)tmp_i / (float)100.0;
! 271: float sum_ratio = (float)(ss + ((float)rr*ff*sf_ratio/(float)cc)) / (float)(ff*(1.0 + (float)rr/(float)cc));
! 272: tmp_i = (int)(10000 * sum_ratio);
! 273: float sum_percent = (float)tmp_i / (float)100.0;
! 274:
! 275: String cs = " " + ss + "/" + ff;
! 276: cs = cs + " = " + sf_percent + "%";
! 277: String r = "remaining " + rr + " sets at (%) ";
! 278: String s = " " + sum_percent + "%";
! 279:
! 280: //Set up default layout constraints.
! 281: c.fill = GridBagConstraints.NONE;
! 282:
! 283: Label tL = new Label(t, Label.LEFT);
! 284: // c.gridwidth = GridBagConstraints.REMAINDER; //It ends a row.
! 285: c.gridwidth = 1;
! 286: c.gridx = 0;
! 287: c.gridy = 0;
! 288: gridbag.setConstraints(tL, c);
! 289: add(tL);
! 290:
! 291: Label cL = new Label(cs, Label.CENTER);
! 292: c.gridwidth = 2;
! 293: c.gridx = 1;
! 294: c.gridy = 0;
! 295: gridbag.setConstraints(cL, c);
! 296: add(cL);
! 297:
! 298: Label sL = new Label("subtotal=", Label.RIGHT);
! 299: c.gridwidth = 1;
! 300: c.gridx = 3;
! 301: c.gridy = 0;
! 302: gridbag.setConstraints(sL, c);
! 303: add(sL);
! 304:
! 305: sumL = new Label(s, Label.RIGHT);
! 306: c.gridwidth = GridBagConstraints.REMAINDER; //It ends a row.
! 307: c.gridx = 4;
! 308: c.gridy = 0;
! 309: gridbag.setConstraints(sumL, c);
! 310: add(sumL);
! 311: if(x==1) {
! 312: Label rL = new Label(r, Label.RIGHT);
! 313: c.gridwidth = 2;
! 314: c.gridx = 0;
! 315: c.gridy = 1;
! 316: gridbag.setConstraints(rL, c);
! 317: add(rL);
! 318:
! 319: exT = new TextField("0", 3);
! 320: c.anchor = GridBagConstraints.EAST;
! 321: c.gridwidth = 1; //The default value.
! 322: c.gridx = 2;
! 323: c.gridy = 1;
! 324: gridbag.setConstraints(exT, c);
! 325: add(exT);
! 326: exT.addActionListener(this);
! 327: c.anchor = GridBagConstraints.CENTER; // default
! 328:
! 329: //Add the slider. It's horizontal, and it has the maximum
! 330: //value specified by the instance variable max. Its initial
! 331: //and minimum values are the default (0). A click increments
! 332: //the value by block units.
! 333: sB = new Scrollbar(Scrollbar.HORIZONTAL);
! 334: sB.setMaximum(max + 10);
! 335: sB.setBlockIncrement(block);
! 336: // c.gridwidth = GridBagConstraints.REMAINDER; //It ends a row.
! 337: c.fill = GridBagConstraints.HORIZONTAL;
! 338: c.gridwidth = 2;
! 339: c.gridx = 3;
! 340: c.gridy = 1;
! 341: gridbag.setConstraints(sB, c);
! 342: add(sB);
! 343: sB.addAdjustmentListener(this);
! 344: exT.setText(String.valueOf(sf_percent));
! 345: sB.setValue((int)sf_percent);
! 346: }
! 347:
! 348: }
! 349: // Draws a box around this panel.
! 350: public void paint(Graphics g) {
! 351: Dimension d = getSize();
! 352: g.drawRect(0,0, d.width - 1, d.height - 1);
! 353: }
! 354: public Insets getInsets() {
! 355: return new Insets(5,5,5,8);
! 356: }
! 357: float getSubTotal() {
! 358: String s_str = sumL.getText().replace('%','\0').trim();
! 359: float s_real = Float.valueOf(s_str).floatValue();
! 360: return (s_real);
! 361: }
! 362: double getValue() {
! 363: double f;
! 364: try {
! 365: f = (double)Double.valueOf(exT.getText()).doubleValue();
! 366: } catch (java.lang.NumberFormatException e) {
! 367: f = 0.0;
! 368: }
! 369: return f;
! 370: }
! 371: // entered into exT
! 372: public void actionPerformed(ActionEvent e) {
! 373: int tf = (int) getValue();
! 374: if (tf > max)
! 375: tf = max;
! 376: if (tf < 0)
! 377: tf = 0;
! 378: sB.setValue(tf);
! 379: exT.setText(String.valueOf((int)tf));
! 380: recalcSumm(tf);
! 381: }
! 382: // slider sB changed
! 383: public void adjustmentValueChanged(AdjustmentEvent e) {
! 384: Scrollbar source = (Scrollbar)e.getSource();
! 385: int my_i = (int)source.getValue();
! 386: exT.setText(String.valueOf(e.getValue()));
! 387: recalcSumm(my_i);
! 388: }
! 389: void recalcSumm(int tf) {
! 390: float my_r = (float) tf / (float)100.0;
! 391: int tmp_i= (int)(10000*(ss+(rr*ff*my_r/cc))/(float)(ff*(1.0+rr/cc)));
! 392: float sum = (float)tmp_i / (float)100.0;
! 393: sumL.setText(sum + "%");
! 394: controller.recalcTermScore();
! 395: }
! 396: // Set the values in the slider and text field.
! 397: void setValue(double f) {
! 398: setSliderValue(f);
! 399: exT.setText(String.valueOf((float)f));
! 400: }
! 401: void setSliderValue(double f) {
! 402: int sliderValue = (int)f;
! 403:
! 404: if (sliderValue > max)
! 405: sliderValue = max;
! 406: if (sliderValue < 0)
! 407: sliderValue = 0;
! 408: sB.setValue(sliderValue);
! 409:
! 410: }
! 411: }
! 412: class ExmPanel extends Panel
! 413: implements ActionListener,
! 414: AdjustmentListener {
! 415: TScore controller;
! 416: TextField exT_ex, exT_pc;
! 417: Scrollbar sB_ex, sB_pc;
! 418: Label sumL;
! 419: int max = 100;
! 420: int block = 1;
! 421: int show_pc, exam_ex, epc_ex;
! 422: float s_ex, f_ex, s_pc, f_pc;
! 423: float c_factor;
! 424:
! 425: // exam_type 0 Final
! 426: // 1, 2, 3, 4
! 427: ExmPanel(TScore u,int exam_type,int exam_x,int show_epc,int epc_x,
! 428: float a,float b,float w,float m,float n,float ex_default) {
! 429: GridBagConstraints c = new GridBagConstraints();
! 430: GridBagLayout gridbag = new GridBagLayout();
! 431: setLayout(gridbag);
! 432: Label tL;
! 433: float exam_ratio, epc_ratio;
! 434: float sum;
! 435: int tmp_i;
! 436:
! 437: controller = u;
! 438: c_factor = w;
! 439: show_pc = show_epc;
! 440: exam_ex = exam_x;
! 441: epc_ex = epc_x;
! 442: s_ex = a; f_ex = b; s_pc = m; f_pc = n;
! 443: //Set up default layout constraints.
! 444: c.fill = GridBagConstraints.NONE;
! 445:
! 446: //Add the label. It displays this panel's title, centered.
! 447: if(exam_type == 0 ) { // Final exam
! 448: tL = new Label("Final", Label.LEFT);
! 449: } else {
! 450: tL = new Label("Exam " + exam_type, Label.LEFT);
! 451: }
! 452: c.anchor = GridBagConstraints.WEST;
! 453: c.gridwidth = 1;
! 454: c.gridx = 0;
! 455: c.gridy = 0;
! 456: gridbag.setConstraints(tL, c);
! 457: add(tL);
! 458: c.anchor = GridBagConstraints.CENTER;
! 459:
! 460: if( exam_x == 0 ) {
! 461: // exam not extrapolated
! 462: exam_ratio = (float)s_ex / (float)f_ex;
! 463: tmp_i = (int) (10000 * exam_ratio );
! 464: float percent = (float)tmp_i / (float)100.0;
! 465: String cs = " " + a + "/" + b + " = " + percent + " %";
! 466: Label cL = new Label(cs, Label.CENTER);
! 467: c.gridwidth = 2;
! 468: c.gridx = 1;
! 469: c.gridy = 0;
! 470: gridbag.setConstraints(cL, c);
! 471: add(cL);
! 472: } else {
! 473: // extrapolate exam
! 474: exam_ratio = ex_default;
! 475: exT_ex = new TextField("0", 3);
! 476: exT_ex.setName("EXAM");
! 477: c.gridwidth = 1; //The default value.
! 478: c.gridx = 2;
! 479: c.gridy = 0;
! 480: gridbag.setConstraints(exT_ex, c);
! 481: add(exT_ex);
! 482: exT_ex.addActionListener(this);
! 483:
! 484: sB_ex = new Scrollbar(Scrollbar.HORIZONTAL);
! 485: sB_ex.setName("EXAMS");
! 486: sB_ex.setMaximum(max + 10);
! 487: sB_ex.setBlockIncrement(block);
! 488: c.gridwidth = 2;
! 489: c.gridx = 3;
! 490: c.gridy = 0;
! 491: gridbag.setConstraints(sB_ex, c);
! 492: add(sB_ex);
! 493: sB_ex.addAdjustmentListener(this);
! 494: }
! 495: epc_ratio = exam_ratio;
! 496: if(show_pc == 1) {
! 497: if(epc_x == 1) {
! 498: epc_ratio = exam_ratio;
! 499: } else {
! 500: epc_ratio = (float)s_pc / (float)f_pc;
! 501: }
! 502: if( epc_ratio > exam_ratio ) {
! 503: tmp_i= (int)(10000 * (exam_ratio + c_factor * (epc_ratio - exam_ratio)));
! 504: sum = (float)tmp_i / (float)100.0;
! 505: } else {
! 506: tmp_i= (int)(10000 * exam_ratio);
! 507: sum = (float)tmp_i / (float)100.0;
! 508: }
! 509: } else {
! 510: tmp_i= (int)(10000 * exam_ratio);
! 511: sum = (float)tmp_i / (float)100.0;
! 512: }
! 513:
! 514: Label sL = new Label("subtotal=", Label.RIGHT);
! 515: c.gridwidth = 1;
! 516: c.gridx = 5;
! 517: c.gridy = 0;
! 518: gridbag.setConstraints(sL, c);
! 519: add(sL);
! 520:
! 521: String s = " " + sum + "%";
! 522: sumL = new Label(s, Label.CENTER);
! 523: c.anchor = GridBagConstraints.EAST;
! 524: c.gridwidth = GridBagConstraints.REMAINDER; //It ends a row.
! 525: c.gridx = 6;
! 526: c.gridy = 0;
! 527: gridbag.setConstraints(sumL, c);
! 528: add(sumL);
! 529: c.anchor = GridBagConstraints.CENTER;
! 530:
! 531: if( show_epc == 1 ) {
! 532: Label eL = new Label("Correction " + exam_type, Label.LEFT);
! 533: c.gridwidth = 1;
! 534: c.gridx = 0;
! 535: c.gridy = 1;
! 536: gridbag.setConstraints(eL, c);
! 537: add(eL);
! 538: if( epc_x == 0 ) {
! 539: float ratio = (float) ( s_pc / f_pc);
! 540: tmp_i = (int) (10000 * ratio );
! 541: float percent = (float)tmp_i / (float)100.0;
! 542: String cs = " " + s_pc + "/" + f_pc + " = " + percent + " %";
! 543: Label cL = new Label(cs, Label.CENTER);
! 544: c.gridwidth = 2;
! 545: c.gridx = 1;
! 546: c.gridy = 1;
! 547: gridbag.setConstraints(cL, c);
! 548: add(cL);
! 549: } else {
! 550: exT_pc = new TextField("0", 3);
! 551: exT_pc.setName("PC");
! 552: c.anchor = GridBagConstraints.EAST;
! 553: c.gridwidth = 1; //The default value.
! 554: c.gridx = 2;
! 555: c.gridy = 1;
! 556: gridbag.setConstraints(exT_pc, c);
! 557: add(exT_pc);
! 558: exT_pc.addActionListener(this);
! 559:
! 560: sB_pc = new Scrollbar(Scrollbar.HORIZONTAL);
! 561: sB_pc.setName("PCS");
! 562: sB_pc.setMaximum(max + 10);
! 563: sB_pc.setBlockIncrement(block);
! 564: c.gridwidth = GridBagConstraints.REMAINDER;
! 565: c.anchor = GridBagConstraints.CENTER;
! 566: c.fill = GridBagConstraints.HORIZONTAL;
! 567: // c.gridwidth = 2;
! 568: c.gridx = 3;
! 569: c.gridy = 1;
! 570: gridbag.setConstraints(sB_pc, c);
! 571: add(sB_pc);
! 572: sB_pc.addAdjustmentListener(this);
! 573: }
! 574: }
! 575: setExValue(exam_ratio,epc_ratio);
! 576: }
! 577: // Draws a box around this panel.
! 578: public void paint(Graphics g) {
! 579: Dimension d = getSize();
! 580: g.drawRect(0,0, d.width - 1, d.height - 1);
! 581: }
! 582: public Insets getInsets() {
! 583: return new Insets(5,5,5,8);
! 584: }
! 585: float getSubTotal() {
! 586: String s_str = sumL.getText().replace('%','\0').trim();
! 587: float s_real = Float.valueOf(s_str).floatValue();
! 588: return (s_real);
! 589: }
! 590: // entered into exT
! 591: public void actionPerformed(ActionEvent e) {
! 592: TextField source = (TextField)e.getSource();
! 593: String name = source.getName();
! 594: int tf = (int)Integer.valueOf(source.getText()).intValue();
! 595: if (tf > max)
! 596: tf = max;
! 597: if (tf < 0)
! 598: tf = 0;
! 599: if( name.equals(String.valueOf("EXAM")) ) {
! 600: sB_ex.setValue(tf);
! 601: exT_ex.setText(String.valueOf((int)tf));
! 602: } else {
! 603: sB_pc.setValue(tf);
! 604: exT_pc.setText(String.valueOf((int)tf));
! 605: }
! 606: recalcSumm();
! 607: }
! 608: // slider sB changed
! 609: public void adjustmentValueChanged(AdjustmentEvent e) {
! 610: Scrollbar source = (Scrollbar)e.getSource();
! 611: String name = source.getName();
! 612: int my_i = (int)source.getValue();
! 613:
! 614: if( name.equals(String.valueOf("EXAMS")) ) {
! 615: sB_ex.setValue(my_i);
! 616: exT_ex.setText(String.valueOf((int)my_i));
! 617: } else {
! 618: sB_pc.setValue(my_i);
! 619: exT_pc.setText(String.valueOf((int)my_i));
! 620: }
! 621: recalcSumm();
! 622: }
! 623: void recalcSumm() {
! 624: int tmp_i;
! 625: float exam , epc, sum;
! 626:
! 627: if( exam_ex == 1 ) {
! 628: tmp_i = (int)Integer.valueOf(exT_ex.getText()).intValue();
! 629: exam = (float) tmp_i / (float)100.0;
! 630: } else {
! 631: exam = (float)s_ex / (float)f_ex;
! 632: }
! 633: if( show_pc == 1 ) {
! 634: if(epc_ex == 1) {
! 635: tmp_i = (int)Integer.valueOf(exT_pc.getText()).intValue();
! 636: epc = (float) tmp_i / (float)100.0;
! 637: } else {
! 638: epc = (float)s_pc / (float)f_pc;
! 639: }
! 640: if( epc > exam ) {
! 641: tmp_i= (int)(10000 * (exam + c_factor * (epc - exam)));
! 642: sum = (float)tmp_i / (float)100.0;
! 643: } else {
! 644: tmp_i= (int)(10000 * exam);
! 645: sum = (float)tmp_i / (float)100.0;
! 646: }
! 647: } else {
! 648: tmp_i= (int)(10000 * exam);
! 649: sum = (float)tmp_i / (float)100.0;
! 650: }
! 651: sumL.setText(sum + "%");
! 652: controller.recalcTermScore();
! 653: }
! 654: void setExValue (float a, float b) {
! 655: int exm, epc;
! 656: exm = (int) (a*100.0);
! 657: epc = (int) (b*100.0);
! 658: if (exm > max)
! 659: exm = max;
! 660: if (exm < 0)
! 661: exm = 0;
! 662: if (epc > max)
! 663: epc = max;
! 664: if (epc < 0)
! 665: epc = 0;
! 666: if( exam_ex ==1 ) {
! 667: sB_ex.setValue(exm);
! 668: exT_ex.setText(String.valueOf(exm));
! 669: }
! 670: if( (show_pc == 1) && (epc_ex==1) ) {
! 671: sB_pc.setValue(epc);
! 672: exT_pc.setText(String.valueOf(epc));
! 673: }
! 674: }
! 675: }
! 676:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>