/* A basic extension of the java.applet.Applet class */ import java.awt.*; import java.applet.*; public class sigfig extends Applet { public int nRichtig = 0; public int nFalsch = 0; public int i = 0; public int imax = 12; public String zahl[][] = { {"1.000","4","Zeros after the decimal point count, too."}, {"1.1E7","2","The exponent is irrelevant."}, {"987600.0","7","The zeros count, too."}, {"1. + 0.4212","1","The lower number of significant figures counts."}, {"0.002","1","Leading zeros do not count."}, {"2.0E3","2","The exponent is irrelevant."}, {"0.002002","4","The leading 0's don't count, but the 0's between the 2's do"}, {"3.211 - 3.21","3","The lower number of significant figures counts."}, {"0.123","3","The zero in front of the decimal point does not count."}, {"987600.","6","The zeros count, too."}, {"3.1 + 1.222","2","The lower number of significant figures counts."}, {"2.101E-8","4","The exponent is irrelevant."}, {"112.1100","7","The two trailing zeros count, too."}}; public String richtig; public String falsch; public void init() { super.init(); i = (int)(Math.random()*imax); setBackground(Color.white); setForeground(Color.black); //{{INIT_CONTROLS setLayout(null); resize(500,300); button1 = new java.awt.Button("New Number"); button1.reshape(21,12,93,27); add(button1); label1 = new java.awt.Label("",Label.CENTER); label1.reshape(21,59,318,31); label1.setFont(new Font("TimesRoman", Font.BOLD, 18)); label1.setForeground(new Color(16711680)); label1.setBackground(new Color(16776960)); add(label1); panel1 = new java.awt.Panel(); panel1.setLayout(new GridLayout(0,1,5,5)); panel1.reshape(373,2,124,296); add(panel1); label2 = new java.awt.Label("Number of"); label2.reshape(0,0,124,18); label2.setForeground(new Color(255)); panel1.add(label2); label3 = new java.awt.Label("significant"); label3.reshape(0,23,124,18); label3.setForeground(new Color(255)); panel1.add(label3); label4 = new java.awt.Label("figures"); label4.reshape(0,46,124,18); label4.setForeground(new Color(255)); panel1.add(label4); Group1 = new CheckboxGroup(); radioButton1 = new java.awt.Checkbox("1", Group1, false); radioButton1.reshape(0,69,124,18); panel1.add(radioButton1); radioButton2 = new java.awt.Checkbox("2", Group1, false); radioButton2.reshape(0,92,124,18); panel1.add(radioButton2); radioButton3 = new java.awt.Checkbox("3", Group1, false); radioButton3.reshape(0,115,124,18); panel1.add(radioButton3); radioButton4 = new java.awt.Checkbox("4", Group1, false); radioButton4.reshape(0,138,124,18); panel1.add(radioButton4); radioButton5 = new java.awt.Checkbox("5", Group1, false); radioButton5.reshape(0,161,124,18); panel1.add(radioButton5); radioButton6 = new java.awt.Checkbox("6", Group1, false); radioButton6.reshape(0,184,124,18); panel1.add(radioButton6); radioButton7 = new java.awt.Checkbox("7", Group1, false); radioButton7.reshape(0,207,124,18); panel1.add(radioButton7); radioButton8 = new java.awt.Checkbox("8", Group1, false); radioButton8.reshape(0,230,124,18); panel1.add(radioButton8); radioButton9 = new java.awt.Checkbox("9", Group1, false); radioButton9.reshape(0,253,124,18); panel1.add(radioButton9); radioButton10 = new java.awt.Checkbox("10", Group1, false); radioButton10.reshape(0,276,124,18); panel1.add(radioButton10); textArea1 = new java.awt.Label("",Label.CENTER); textArea1.reshape(1,146,374,90); textArea1.setFont(new Font("TimesRoman", Font.BOLD, 14)); textArea1.setForeground(new Color(255)); textArea1.setBackground(new Color(16777215)); add(textArea1); label5 = new java.awt.Label("Result: 0 correct, 0 false"); label5.reshape(26,261,314,31); label5.setFont(new Font("TimesRoman", Font.PLAIN, 18)); add(label5); canvas1 = new java.awt.Canvas(); canvas1.reshape(349,3,144,295); canvas1.setBackground(new Color(16777215)); add(canvas1); //}} canvas1.hide(); } public boolean handleEvent(Event event) { if (event.target == button1 && event.id == Event.ACTION_EVENT){ neueZahl(); canvas1.hide(); } if (event.target instanceof Checkbox && event.id == Event.ACTION_EVENT && !(label1.getText() == "")){ Checkbox currentCheckbox = (Checkbox)event.target; if (currentCheckbox.getLabel() == richtig){ textArea1.setText("Correct!"); nRichtig++; label5.setText("Result: "+nRichtig+" correct, "+nFalsch+" false"); if (nRichtig == imax) { button1.hide(); label5.setForeground(Color.red); label5.setText("Final Result: "+nRichtig+" correct, "+nFalsch+" false"); } else { canvas1.show(); } } else { textArea1.setText(zahl[i][2]); nFalsch++; label5.setText("Result: "+nRichtig+" correct, "+nFalsch+" false"); } } return super.handleEvent(event); } public boolean neueZahl(){ i++; radioButton10.setState(false); radioButton9.setState(false); radioButton8.setState(false); radioButton7.setState(false); radioButton6.setState(false); radioButton5.setState(false); radioButton4.setState(false); radioButton3.setState(false); radioButton2.setState(false); radioButton1.setState(false); if (i>imax) i = 0; label1.setText(zahl[i][0]); richtig = zahl[i][1]; falsch = zahl[i][2]; textArea1.setText(""); return true; } //{{DECLARE_CONTROLS java.awt.Button button1; java.awt.Label label1; java.awt.Panel panel1; java.awt.Label label2; java.awt.Label label3; java.awt.Label label4; java.awt.Checkbox radioButton1; CheckboxGroup Group1; java.awt.Checkbox radioButton2; java.awt.Checkbox radioButton3; java.awt.Checkbox radioButton4; java.awt.Checkbox radioButton5; java.awt.Checkbox radioButton6; java.awt.Checkbox radioButton7; java.awt.Checkbox radioButton8; java.awt.Checkbox radioButton9; java.awt.Checkbox radioButton10; java.awt.Label textArea1; java.awt.Label label5; java.awt.Canvas canvas1; //}} }