/Users/lyon/j4p/src/net/stocks/QuoteFrame.java

1    package net.stocks; 
2     
3    import java.awt.*; 
4    import java.util.Vector; 
5     
6    public class QuoteFrame extends 
7            ip.gui.frames.ClosableFrame { 
8      Vector quotes = new Vector(); 
9      Label labels[]; 
10    
11     public void init() { 
12       getQuotes(); 
13       setBackground(Color.white); 
14       labels = new Label[quotes.size()]; 
15       for (int i = 0; i < quotes.size(); i++) { 
16         String s = 
17             (String) quotes.elementAt(i); 
18         String sa[] = 
19             quoteLineToStringVector(s); 
20         labels[i] = new Label(s); 
21         add(labels[i]); 
22       } 
23       setLayout(new GridLayout(0, 1)); 
24       pack(); 
25       setVisible(true); 
26     } 
27    
28     public String[] quoteLineToStringVector(String pcs) { 
29       Vector stringVector = 
30           new Vector(); 
31       String s = new String(pcs); 
32       //separate the strings delimited by commas 
33       for ( 
34           int i = s.indexOf(','); 
35           i >= 0; 
36           i = s.indexOf(',')) { 
37         stringVector.addElement(s.substring(0, i)); 
38         s = new String(s.substring(i + 1)); 
39       } 
40       // add the last String left 
41       stringVector.addElement(s); 
42       String sa[] = 
43           new String[stringVector.size()]; 
44       for (int i = 0; i < sa.length; i++) 
45         sa[i] = (String) stringVector.elementAt(i); 
46       return sa; 
47     } 
48    
49     public void println(String s[]) { 
50       for (int i = 0; i < s.length; i++) 
51         System.out.println(s[i]); 
52     } 
53    
54     public void print(String s[]) { 
55       for (int i = 0; i < s.length; i++) 
56         System.out.print(s[i] + " "); 
57       System.out.println(); 
58     } 
59    
60     public void updateDisplay() { 
61       getQuotes(); 
62       for (int i = 0; i < quotes.size(); i++) { 
63         labels[i].setText( 
64             (String) quotes.elementAt(i)); 
65       } 
66     } 
67    
68     public void paint(Graphics g) { 
69       updateDisplay(); 
70       repaint(2000); 
71     } 
72    
73     public Vector getQuotes() { 
74       Vector s = new Vector(); 
75       s.addElement("aapl"); 
76       s.addElement("open"); 
77       s.addElement("xlnx"); 
78       s.addElement("altr"); 
79       s.addElement("mot"); 
80       s.addElement("cy"); 
81       s.addElement("crus"); 
82       s.addElement("mtwkf"); 
83       s.addElement("sfa"); 
84       s.addElement("adbe"); 
85       s.addElement("nn"); 
86       s.addElement("msft"); 
87       s.addElement("sunw"); 
88       s.addElement("lxk"); 
89       s.addElement("ATHM"); 
90       s.addElement("AMZn"); 
91       s.addElement("NT"); 
92       return quotes = 
93           Quote.getUrl( 
94               Quote.makeQuoteURLString(s)); 
95     } 
96    
97     public static void main(String args[]) { 
98       QuoteFrame qf = new QuoteFrame(); 
99       qf.init(); 
100    } 
101   
102  }