import java.awt.*; import java.awt.event.*; public class Tallies extends java.applet.Applet implements ActionListener { TextField mQuery,mAnsStu, mAnsFac, mAnsSta, mTotal; Button bStudents,bFaculty,bStaff; int noStu=0, noFac=0, noSta=0, noTotal=0; public void init () { mQuery = new TextField(80); mQuery.setText("Keep track of attendance by pushing the buttons."); bStudents = new Button("Students"); bFaculty = new Button("Faculty"); bStaff = new Button("Staff"); mAnsStu = new TextField(12); mAnsFac = new TextField(12); mAnsSta = new TextField(12); mTotal = new TextField(80); bStudents.addActionListener(this); bFaculty.addActionListener(this); bStaff.addActionListener(this); add(mQuery) ; add(bStudents) ; add(bFaculty) ; add(bStaff) ; add(mTotal) ; add(mAnsStu) ; add(mAnsFac) ; add(mAnsSta) ; mTotal.setText("The total attendance is " + noTotal + " Subtotals are shown below."); mAnsStu.setText(noStu + " students"); mAnsFac.setText(noFac + " faculty"); mAnsSta.setText(noSta + " staff"); } public void actionPerformed(ActionEvent event) { Object cause = event.getSource(); if (cause == bStudents) { noStu = noStu + 1; noTotal = noTotal + 1; mTotal.setText("The total attendance is " + noTotal + " Subtotals are shown below."); mAnsStu.setText(noStu + " students"); } if (cause == bFaculty) { noFac = noFac + 1; noTotal = noTotal + 1; mTotal.setText("The total attendance is " + noTotal + " Subtotals are shown below."); mAnsFac.setText(noFac + " faculty"); } if (cause == bStaff) { noSta = noSta + 1; noTotal = noTotal + 1; mTotal.setText("The total attendance is " + noTotal + " Subtotals are shown below."); mAnsSta.setText(noSta + " staff"); } } }