/* lookup applet reads a text file with grade data and reports grade info based on the login and password typed. */ import java.awt.*; import java.applet.Applet; import java.awt.Graphics; import java.awt.event.*; import java.lang.Math; import java.util.*; import java.io.*; import java.io.StreamTokenizer; import java.io.InputStream; import java.io.IOException; import java.net.URL; public class lookup extends Applet { //global variables int MAX=35; // maximum number of students per course Choice daColor = new Choice(); int n=1; int classSize; String courseName[]; String courseFile[]; String studentName[]; String login[]; String password[]; String studentReport[]; String message; TextField loginField = new TextField (12); TextField passwordField = new TextField (12); Button getItButton = new Button("Look Up Grade"); TextArea results = new TextArea("Select Class, and login to get your grade report",20,50); public void init() { String rs; // get params // see how many courses to setup (n) rs = getParameter("n"); if (rs == null) { n = 1; } else { n = Integer.parseInt(rs); } // set up ararys for the different course courseName = new String[n]; courseFile = new String[n]; studentName = new String[MAX]; login = new String[MAX]; password = new String[MAX]; studentReport = new String [MAX]; passwordField.setEchoCharacter('*'); //read params for each course for (int i=0; i < n; i++) { courseName[i] = getParameter("ClassName"+(i+1)); courseFile[i] = getParameter("ClassFile"+(i+1)); daColor.addItem(courseName[i]); // add pop-up menu item } add(daColor); //complete the pop-up menu add(loginField); add(passwordField); add(getItButton); add(results); getReports (courseFile[0]); setBackground(new Color(0xF0F080)); message="1. Select your class, \r2. Type in your login (initials) in the first box\r3. Type your password in the next box\r4. Press button to get your grade report"; repaint(); } public void paint( Graphics g ) { /* This would draw the datafile for daignostic purposes g.drawString(courseFile[daColor.getSelectedIndex()], 130, 45); g.drawString( "login: "+loginField.getText(), 10, 45 ); for (int i = 0; i0){ // check for an empty line studentName[i]=s.substring(0,s.indexOf(":")); s = s.substring(s.indexOf(":")+1); //clip if (s.indexOf(":")>0) { login[i]=s.substring(0,s.indexOf(":")); s = s.substring(s.indexOf(":")+1); //clip } if (s.indexOf(":")>0){ password[i] =s.substring(0,s.indexOf(":")); studentReport[i]= s.substring(s.indexOf(":")+1); //clip } i++; } s = dis.readLine(); } } catch (EOFException err) { message = "Ooops "+err.toString(); } dis.close(); classSize=i; } catch (FileNotFoundException err) { message = "Ooops "+err.toString(); } catch (IOException err) { message = "Ooops "+err.toString(); } } public String convertFromHTML( String S) { while (S.indexOf("
") >=0 ) { S = S.substring(0,S.indexOf("
")) + "\r" + S.substring(S.indexOf("
")+4); } return S; } public boolean action(Event e, Object arg) { if (e.target instanceof Choice) { // read in the data of the course selected String dataFileName = courseFile[daColor.getSelectedIndex()]; getReports( dataFileName ); repaint(); return true; } if (e.target instanceof Button) { //get user login info String l=loginField.getText(); String pw=passwordField.getText(); message="User login not found. Check course name and spelling"; int i=0; while ( (i