Results 1 to 5 of 5
- 06-02-2010, 07:30 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 17
- Rep Power
- 0
Unable to retrieve stock quotes from yahoo
Hi all, im able to populate my file from textfile to the comboboxes however it's just not retriving data. What's wrong with my symbols? Can anyone help me troubleshoot this code? I want to retrive the stock quotes from the various company on my combobox. If i change the portion Stock.add(StockInfo[1] it can get the yahoo fiance data. however when i put it to Stock.add(StockInfo[1] and want to retrieve it using the name it cant be done. anyone can help?
Java Code:import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.util.ArrayList; import java.util.Scanner; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class fyp6 { JLabel label1 = new JLabel("Symbol: "); JLabel label2 = new JLabel("Symbol: "); JLabel label3 = new JLabel("Last price: "); JLabel label4 = new JLabel("Change: "); JLabel label5 = new JLabel("volume: "); JLabel read1 = new JLabel(""); JLabel read2 = new JLabel(""); JLabel read3 = new JLabel(""); JLabel read4 = new JLabel(""); ArrayList<Object> Stock; Object[] arr; public fyp6() { Stock = new ArrayList<Object>(); String line = null; try { FileInputStream fis = new FileInputStream( ("C:/Java Sem 2/FYP SEM 1/stock.txt")); InputStreamReader isr = new InputStreamReader(fis); BufferedReader input = new BufferedReader(isr); while ((line = input.readLine()) != null){ String[] StockInfo = line.split(","); Stock.add(StockInfo[0]); } } catch(FileNotFoundException FNF) { System.err.println("File not found: " + FNF); } catch(IOException E) { System.err.println("IOException: " + E); } arr = Stock.toArray(); final JComboBox ipList = new JComboBox(arr); JFrame frame1 = new JFrame("stock"); frame1.setBounds(50, 50, 400, 200); frame1.setLayout(new BorderLayout()); JPanel panel1 = new JPanel(); JPanel panel2 = new JPanel(); panel1.setLayout(new GridLayout(1,2)); panel1.add(label1); panel1.add(ipList); panel2.setLayout(new GridLayout(4,2)); panel2.add(label2); panel2.add(read1); panel2.add(label3); panel2.add(read2); panel2.add(label4); panel2.add(read3); panel2.add(label5); panel2.add(read4); frame1.add(panel1, BorderLayout.NORTH); frame1.add(panel2, BorderLayout.CENTER); ipList.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Object input1 =ipList.getSelectedItem(); URL yahoo = new URL("http://download.finance.yahoo.com/d/quotes.csv?s="+input1+"&f=sl1d1t1c1ohgv&e=.csv"); BufferedReader in = new BufferedReader(new InputStreamReader(yahoo.openStream())); Scanner src = new Scanner(in).useDelimiter(",");; read1.setText(src.next()); read2.setText(src.next()); read3.setText(src.next()); read3.setText(src.next()); read3.setText(src.next()); read4.setText(src.next()); read4.setText(src.next()); read4.setText(src.next()); read4.setText(src.next()); in.close(); } catch (IOException ex) { ex.printStackTrace(); } } }); frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame1.setVisible(true); } public static void main(String[] args) { new fyp6(); } }Last edited by the reporter; 06-03-2010 at 07:26 AM.
- 06-03-2010, 06:46 AM #2
Senior Member
- Join Date
- Mar 2010
- Location
- Manila, Philippines
- Posts
- 257
- Rep Power
- 4
Double posted thread.
Every project, package, class, method, variable, syntax, algorithm, etc.
are registered in my memory bank. Thanks to this thread.
- 06-03-2010, 07:26 AM #3
Member
- Join Date
- Jun 2010
- Posts
- 17
- Rep Power
- 0
can anyone help?
- 06-03-2010, 07:42 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 06-03-2010, 04:10 PM #5
Senior Member
- Join Date
- Mar 2010
- Location
- Manila, Philippines
- Posts
- 257
- Rep Power
- 4
Similar Threads
-
Need a Main for a Stock Managing program !!
By Sary in forum New To JavaReplies: 3Last Post: 05-30-2010, 07:57 PM -
Stock exchange program
By askinne2 in forum New To JavaReplies: 2Last Post: 05-02-2010, 11:25 PM -
String, quotes and args
By mac in forum New To JavaReplies: 8Last Post: 02-04-2010, 04:24 PM -
unbalanced quotes in -
By fresh83 in forum New To JavaReplies: 2Last Post: 12-19-2009, 01:10 AM -
Stock Quotes
By BartDR in forum Advanced JavaReplies: 0Last Post: 09-15-2009, 09:15 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks