import java.io.*; import javax.swing.*; import javax.swing.event.*; import java.lang.*; import java.net.URL; import java.applet.*; import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.text.*; import javax.swing.text.html.*; import javax.swing.text.html.parser.*; public class htm3 extends JInternalFrame { String s; Object o; static int i =0; static JEditorPane pane = new JEditorPane(); static JTextField t = new JTextField("",30); String st; //JFrame frame = new JFrame(); JPanel up = new JPanel(new FlowLayout()); JPanel down = new JPanel(new FlowLayout()); JPanel bottom=new JPanel(new FlowLayout()); JPanel middle=new JPanel(new FlowLayout()); final JPanel verybottom=new JPanel(new FlowLayout()); JPanel top=new JPanel(new FlowLayout()); static Vector v = new Vector(20); Vector combo = new Vector(); public htm3(String urlstring) { super("WebBrowser", true, true, true, true); try{ //pane = new JEditorPane(); pane.setEditable(false); }catch (Exception e) { System.out.println("error1"); } try { pane.setPage(urlstring); }catch (IOException e) {System.out.println("cannot set page"+e);} pane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent ev) { if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { try{ // i=i+1; String filname; int loopvar; char c='/'; //pane.setPage(ev.getURL()); URL url; url = ev.getURL(); loadpage(url); st=url.toString(); }catch (Exception e1) {System.out.println("it is here");} //System.out.println(" i is incresed to "+i); } } }); up.setLayout(new BorderLayout()); up.add(bottom,BorderLayout.SOUTH); up.add(middle,BorderLayout.CENTER); bottom.setLayout(new BorderLayout()); bottom.add(top,BorderLayout.NORTH); bottom.add(verybottom,BorderLayout.SOUTH); JButton b = new JButton("GO"); JButton b1 = new JButton("HOME"); JButton b2 = new JButton("<>"+i+" "+v.size()); Enumeration enum= v.elements(); while (enum.hasMoreElements()) System.out.println(enum.nextElement()); if (i>0) { o = v.elementAt(i-1); System.out.println("the page to be disp --"+o.toString()); pane.setPage(o.toString()); t.setText(o.toString()); if (v.elementAt(i)!=null) { o= v.elementAt(i); v.removeElement(o); System.out.println("i is decreased to "+i); } i=i-1; } }catch (Exception e) {System.out.println("error is"+e);} System.out.println("Button pressed"); } }); top.add(b3); b3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try{ DataOutputStream DOS = new DataOutputStream(new FileOutputStream("book.txt",true)); String st1= t.getText(); DOS.writeBytes(st1+"\n"); com.addItem(st1); /*try { BufferedReader DIS = new BufferedReader(new InputStreamReader(new FileInputStream("book.txt"))); try { String cop = DIS.readLine(); while (cop!=null) { combo.addElement(cop); //System.out.println("THe op is "+cop); cop=DIS.readLine(); }}catch(EOFException eof){} } catch (IOException e) { System.out.println(e);}*/ //verybottom.add(com); }catch (IOException e) {System.out.println("file exceptio"+e);} } }); verybottom.add(com); com.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try{ String cbox = (String)com.getSelectedItem(); URL url1 = new URL(cbox); //pane.setPage(cbox); //t.setText(cbox); loadpage(url1 ); }catch (IOException e) {System.out.println("this is the error"+e);} } }); //frame.setSize(950,500); show(); } static void loadpage(URL url){ try { Reader r; boolean bad=false; String st = url.toString(); HTMLEditorKit hk = new HTMLEditorKit(); HTMLEditorKit.ParserCallback pc; HTMLDocument hd = new HTMLDocument(); InputStreamReader isr = new InputStreamReader(url.openStream()); pc =hd.getReader(1); ParserDelegator pd = new ParserDelegator(); hk.read(isr,hd,0); ElementIterator it = new ElementIterator(hd); javax.swing.text.Element e = it.first(); do { //System.out.println(e.getName()); if (e.getName().equals("applet")) { bad=true; System.out.println("this contains applets"); pane.setPage("http://osprey4.npac.syr.edu:8001/Browser/applet.html"); i=i+1; v.addElement("http://osprey4.npac.syr.edu:8001/Browser/applet.html"); } //System.out.print(e.getElementCount()); e=it.next(); // System.out.println(); }while (e!=null); if (bad==false) { pane.setPage(url); // i=i+1; } t.setText(st); //System.out.println("The string is "+st); i=i+1; v.addElement(st); System.out.println("i is increased to "+i); }catch (Exception e) {System.out.println("The error is obviously is "+e); try { //System.out.println("this contains applets"); i=i+1; pane.setPage("http://osprey4.npac.syr.edu:8001/Browser/applet.html"); v.addElement("http://osprey4.npac.syr.edu:8001/Browser/applet.html"); t.setText("http://osprey4.npac.syr.edu:8001/Browser/applet.html"); }catch (IOException e1) {System.out.println("it is here");} } } } /*class listen implements HyperlinkListener { }*/