/Users/lyon/j4p/src/gui/browser/LinkQueue.java
|
1 package gui.browser;
2
3 import java.net.MalformedURLException;
4 import java.net.URL;
5 import java.util.Vector;
6
7
8 /**
9 * LinkQueue
10 * Features:
11 * 1. A way to go back to the previous link.
12 * 2. A way to go forward to the next visited link.
13 */
14
15 public class LinkQueue {
16 private Vector v = new Vector();
17 private int i = 0;
18 BrowserLogic bl;
19
20 public LinkQueue() {
21 try {
22 v.addElement(new URL("http://lyon.fairfield.edu"));
23 } catch (MalformedURLException e) {
24 e.printStackTrace();
25 }
26 }
27
28 public void enQueue(URL u) {
29 i++;
30 v.add(i, u);
31 System.out.println("en i = " + i + v.elementAt(i));
32
33 }
34
35 public URL next() {
36 i++;
37 if (i >= v.size()) i = 0;
38 System.out.println("next i = " + i + v.elementAt(i));
39 return (URL) v.elementAt(i);
40
41 }
42
43 public URL previous() {
44 i--;
45 if (i < 0) i = v.size() - 1;
46 System.out.println("prev i = " + i + v.elementAt(i));
47 return (URL) v.elementAt(i);
48
49 }
50
51 public String toString() {
52 String s = "";
53 for (int j = 0; j < 10; j++)
54 s = s + (next()).toString() + "\n";
55 return s;
56 }
57
58 public static void main(String args[]) throws
59 MalformedURLException {
60 LinkQueue lq = new LinkQueue();
61 // System.out.println(lq);
62 }
63 }
64