import java.awt.*; import java.awt.event.*; import java.applet.*; import java.io.*; import java.net.URL; class TutorPage { public TutorPage back; public TutorPage next; public String passcode; public StringBuffer str; public TutorPage wrong; public static String wrongAnswer = new String("Whoops, that was the wrong answer, click back to try again."); public TutorPage(TutorPage b) { back = b; next = null; str = new StringBuffer(); passcode = "N"; wrong = new TutorPage(this,wrongAnswer); } public TutorPage(TutorPage b, String st) { back =b; next = null; str = new StringBuffer(st); passcode = "N"; } public void setNext(TutorPage n) { next = n; } public void append(char ch) { str.append(ch); } public String getText() { return str.toString(); } } class OutputPanel extends Panel { private Image i=null; public void setImage(Image im) { i = im; } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { Dimension d = getSize(); int leftx = d.width-175; int lefty = d.height-175; if (i != null) g.drawImage(i,(int)leftx/2,(int)lefty/2,this); } } public class tutor extends Frame { Panel leftPanel,buttonPanel; Button back,next; Label page; protected int pageNum = 1; protected TextArea text; private FileReader fr; private BufferedReader myInput; private String readstr = new String(); private boolean gotime = false; private TutorPage first = null; private Checkbox A,B,C; private CheckboxGroup group; protected OutputPanel OP; public void parse() { } public tutor(String filename) { super("Java TA"); setSize(410,260); setResizable(false); setBackground(Color.white); setFont(new Font("Serif",Font.PLAIN,12)); this.addWindowListener(new WindowAdapter() { public void windowActivated(WindowEvent e) { repaint(); } public void windowClosing(WindowEvent e) { dispose(); } public void windowDeiconified(WindowEvent e) { repaint(); } public void windowOpened(WindowEvent e) { repaint(); } } ); setLayout(new GridLayout(0,2,0,0)); leftPanel = new Panel(new BorderLayout(0,0)); buttonPanel = new Panel(); back = new Button("Back"); back.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (gotime) { if (first.back != null) { first = first.back; text.setText(first.getText()); pageNum--; page.setText("PAGE "+pageNum); group.setSelectedCheckbox(null); parse(); } } } } ); next = new Button("Next"); next.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (gotime) { //setTitle(group.getSelectedCheckbox().getLabel()); if (first.next != null) { boolean passed = true; if (!first.passcode.equals("N")) { Checkbox box = group.getSelectedCheckbox(); if (box == null) passed = false; else if (!box.getLabel().equals(first.passcode)) passed =false; } if (passed) { first = first.next; text.setText(first.getText()); pageNum++; page.setText("PAGE "+pageNum); group.setSelectedCheckbox(null); parse(); } else { TutorPage wrong = new TutorPage(first,TutorPage.wrongAnswer); first = wrong; text.setText(first.getText()); pageNum++; page.setText("PAGE "+pageNum); group.setSelectedCheckbox(null); } } } } } ); page = new Label("PAGE 1",Label.CENTER); buttonPanel.add(back); buttonPanel.add(page); buttonPanel.add(next); leftPanel.add(buttonPanel,"South"); OP = new OutputPanel(); leftPanel.add(OP,"Center"); add(leftPanel); Panel RightPanel = new Panel(new BorderLayout(0,0)); text = new TextArea("Loading Java TA, please wait...",20,10,TextArea.SCROLLBARS_VERTICAL_ONLY); text.setEditable(false); RightPanel.add(text,"Center"); group = new CheckboxGroup(); A = new Checkbox("A",false,group); B = new Checkbox("B",false,group); C = new Checkbox("C",false,group); Panel CheckBoxPanel = new Panel(new FlowLayout(FlowLayout.CENTER)); CheckBoxPanel.add(A); CheckBoxPanel.add(B); CheckBoxPanel.add(C); RightPanel.add(CheckBoxPanel,"South"); add(RightPanel); show(); ReadFile(filename); } public void ReadFile(String filename) { int size =0; char[] data = null; try { URL url = new URL(filename); Reader fr = new InputStreamReader(url.openStream()); int check = 0, stuff_read = 0; size = 20000; data = new char[size]; while (check != -1) { try { check = fr.read(data,stuff_read,size); } catch (IOException ie) { text.append("ieeeee!"); } if (check != -1) stuff_read+=check; } size = stuff_read; } catch (IOException fe) { text.append("Big IOEx you!"); } int start = 0; TutorPage last = null; TutorPage temp = new TutorPage(last); first = temp; while (start < size) { if (data[start] != '@') { temp.append(data[start]); } else { start++; last = temp; last.passcode = ""+data[start]; temp = new TutorPage(last); last.setNext(temp); } start++; } text.setText(first.getText()); gotime = true; } class TutorWindowAdapter extends WindowAdapter { private tutor KingTut; public TutorWindowAdapter(tutor t) { KingTut = t;} public void windowActivated(WindowEvent e) { KingTut.repaint(); } public void windowClosed(WindowEvent e) { KingTut.dispose(); KingTut = null; } public void windowDeiconified(WindowEvent e) { KingTut.repaint(); } public void windowOpened(WindowEvent e) { KingTut.repaint(); } } }