import java.applet.Applet; import java.awt.*; import java.awt.Graphics.*; import java.awt.event.*; public class maagilruudud extends Applet implements ActionListener{ TextField[][] ruudud = new TextField[4][4]; int i; public void init(){ setLayout(new GridLayout(4,4)); for(int m=0; m<4; m++){ for(int n=0; n<4; n++){ ruudud[m][n] = new TextField(); if((m<3)&&(n<3)){ ruudud[m][n].addActionListener(this); }else{ ruudud[m][n].setEditable(false);} add(ruudud[m][n]); } } } public void actionPerformed(ActionEvent e){ System.out.println(((TextField)e.getSource()).getText()); int[] rsum = new int[3]; int[] vsum = new int[3]; for(int n=0; n<3; n++){ vsum[n]=0; for(int m=0; m<3; m++){ vsum[n]+=Integer.parseInt(ruudud[m][n].getText()); } ruudud[3][n].setText(""+vsum[n]); } for(int m=0; m<3; m++){ rsum[m]=0; for(int n=0; n<3; n++){ rsum[m]+=Integer.parseInt(ruudud[m][n].getText()); } ruudud[m][3].setText(""+rsum[m]); } for(int m=0; m<3; m++){ for(int n=0; n<3; n++){ if(vsum[n]==rsum[m]){ ruudud[3][3].setText("Õige!"); }else{ ruudud[3][3].setText("Vale!"); } } } } }