Guest User

Untitled

a guest
Oct 20th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.19 KB | None | 0 0
  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Frame;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.io.BufferedReader;
  7. import java.io.FileNotFoundException;
  8. import java.io.FileReader;
  9. import java.io.IOException;
  10.  
  11. import javax.swing.JApplet;
  12. import javax.swing.JButton;
  13. import javax.swing.JLabel;
  14. import javax.swing.JList;
  15. import javax.swing.JTextField;
  16. import javax.swing.event.AncestorListener;
  17.  
  18.  
  19.  
  20.  
  21. public class StartActivity extends Applet implements ActionListener{
  22. /**
  23. *
  24. */
  25. private static final long serialVersionUID = -1470898831456146593L;
  26. private JTextField textField;
  27. public JTextField[] textStock = new JTextField[190];
  28. public tags[] tags = new tags[90];
  29. public String[] tg = new String[90];
  30. public JList set = new JList();
  31.  
  32. public StartActivity(){
  33.  
  34. }
  35. public void init() {
  36.  
  37. setSize(1800, 950); // create an instance
  38. setBackground(Color.gray);
  39. setFocusable(true);
  40. setLayout(null);
  41.  
  42. FileReader file = null; // get the tags and their name
  43. FileReader file2 = null;
  44. try {
  45. file = new FileReader("resource/tagsName.txt");
  46. } catch (FileNotFoundException e1) {
  47. // TODO Auto-generated catch block
  48. e1.printStackTrace();
  49. }
  50. BufferedReader br = new BufferedReader(file);
  51. try {
  52. file2 = new FileReader("resource/ref.txt");
  53. } catch (FileNotFoundException e1) {
  54. // TODO Auto-generated catch block
  55. e1.printStackTrace();
  56. }
  57. BufferedReader br2 = new BufferedReader(file2);
  58.  
  59.  
  60.  
  61. // textField = new JTextField();
  62. // textField.setBounds(35, 136, 86, 20);
  63. // add(textField);
  64. // textField.setColumns(10);
  65. int x = 35;
  66. int y= 136;
  67.  
  68. for (int i=0 ; i < 190 ; i++){ // add the text field to enter the quote
  69. textStock[i] = new JTextField("");
  70. textStock[i].setBounds(x,y,86,20);
  71. add(textStock[i]);
  72. textStock[i].setColumns(10);
  73. y = y + 25;
  74. if (y > 900){
  75. y = 136;
  76. x = x + 91;
  77. }
  78. }
  79.  
  80. JLabel label1 = new JLabel("Enter Stock Symbols");
  81. label1.setBounds((x-35)/2, 100, 200, 20);
  82. add(label1);
  83.  
  84. //addKeyListener(this);
  85.  
  86.  
  87. String tg = "";
  88. String rf = "";
  89. x = x + 200;
  90. y= 136;
  91. int i = 0;
  92. int z = x;
  93. try { //
  94. while((tg = br.readLine()) != null){ // add textfields to enter their tags
  95. rf =br2.readLine();
  96. tags[i] = new tags(tg, rf); // tags are a separte method that has their own info
  97. tags[i].setBounds(x, y, 200, 23); // tags are declared as buttons
  98. add(tags[i]);
  99. y = y + 28;
  100. if (y > 900){
  101. y = 136;
  102. x = x + 205;
  103. }
  104. tg = "";
  105. i = i +1;
  106. }
  107. } catch (IOException e2) {
  108. // TODO Auto-generated catch block
  109. e2.printStackTrace();
  110. }
  111. try {
  112. br.close();
  113. } catch (IOException e1) {
  114. // TODO Auto-generated catch block
  115. e1.printStackTrace();
  116. }
  117. JLabel label2 = new JLabel("Choose stock tags Retrival");
  118. label2.setBounds((x+z)/2, 100, 200, 20);
  119. add(label2);
  120.  
  121. //set = new JList();
  122.  
  123. JButton list1= new JButton("List 1");
  124. list1.setBounds(35, 100, 89, 23);
  125. list1.addActionListener(this);
  126. add(list1);
  127.  
  128. JButton run = new JButton("Run");
  129. run.setBounds(getWidth()/2, 32, 89, 23);
  130. run.addActionListener(this);
  131. add(run);
  132.  
  133. JButton analyse = new JButton("Analyse");
  134. analyse.setBounds(getWidth()/2 - 200, 32, 89, 23);
  135. analyse.addActionListener(this);
  136. add(analyse);
  137.  
  138. Frame frame = (Frame) this.getParent().getParent();
  139. frame.setTitle(" Financial Analysis");
  140. try {
  141.  
  142. } catch (Exception e) {
  143. // TODO: handle exception
  144. }
  145.  
  146.  
  147. }
  148.  
  149.  
  150.  
  151.  
  152. public void actionPerformed(ActionEvent arg0) {
  153. // TODO Auto-generated method stub
  154. /**
  155. * call method depending on their button
  156. */
  157.  
  158. System.out.println(arg0.getActionCommand());
  159. if (arg0.getActionCommand()== "Run"){
  160. stockdata();
  161. }
  162. //System.out.println("true");
  163. if (arg0.getActionCommand()== "List 1"){
  164. listSet(1);
  165. }
  166. if (arg0.getActionCommand()== "Analyse"){
  167. choose();
  168. System.out.println(arg0.getActionCommand());
  169. }
  170. }
  171.  
  172. private void choose() {
  173. /*
  174. * analyse quotes with parameters that I choose
  175. */
  176. int m =0;
  177. String[] quotes = new String[200];
  178. int s =0;
  179. String[] tq = new String[20];
  180. String qurl = "http://finance.yahoo.com/d/quotes.csv?s=";
  181. for (int i=0 ; i < 60 ; i++){
  182. String stock =textStock[i].getText();
  183. if (m == 0 && stock != ""){
  184. qurl = qurl + stock ;
  185. m =1 ;
  186. quotes[s] = stock;
  187. s=s+1;
  188. }
  189. else if(stock != ""){
  190. qurl = qurl +"+"+ stock ;
  191. quotes[s] = stock;
  192. s=s+1;
  193. }
  194. }
  195. qurl = qurl + "&f=l1vhgd1rp6";
  196.  
  197. System.out.println(qurl);
  198. Analysis tab = new Analysis(qurl, quotes); // param are declared in another method
  199. tab.setVisible(true);
  200. }
  201.  
  202. private void stockdata() {
  203.  
  204. /*
  205. * retrieves stock data
  206. */
  207. int m =0;
  208. String[] tq = new String[20];
  209. String[] quotes = new String[200];
  210. int s =0;
  211. String qurl = "http://finance.yahoo.com/d/quotes.csv?s=";
  212. for (int i=0 ; i < 60 ; i++){
  213. String stock =textStock[i].getText();
  214. if (m == 0 && stock != ""){
  215. qurl = qurl + stock ;
  216. quotes[s] = stock;
  217. s=s+1;
  218. m =1 ;
  219. }
  220. else if(stock != ""){
  221. qurl = qurl +"+"+ stock ;
  222. quotes[s] = stock;
  223. //System.out.println(quotes[s]);
  224. s=s+1;
  225. }
  226. }
  227. qurl = qurl + "&f=";
  228. int z =0;
  229. for (int i=0 ; i < 60 ; i++){
  230. if(tags[i].getStatus()){
  231. qurl = qurl + tags[i].getReference();
  232. tq[z]= tags[i].getName();
  233. z =z+1;
  234. }
  235.  
  236. }
  237.  
  238. System.out.println(qurl);
  239. // this method retrives data and creates a table to show them
  240. StockData tab = new StockData(qurl, tq, quotes);
  241. tab.setVisible(true);
  242. }
  243. private void listSet(int fileNumber){
  244. // this method populates a set of stocks
  245. FileReader file = null;
  246.  
  247. try {
  248. file = new FileReader("resource/set"+fileNumber + ".txt");
  249. } catch (FileNotFoundException e1) {
  250. // TODO Auto-generated catch block
  251. e1.printStackTrace();
  252. }
  253. BufferedReader br = new BufferedReader(file);
  254. String tg;
  255. int i = 0;
  256. try {
  257. while((tg = br.readLine()) != null){
  258. if (i<190){
  259. textStock[i].setText(tg);
  260. i = i +1;
  261.  
  262. }}
  263. } catch (IOException e) {
  264. // TODO Auto-generated catch block
  265. e.printStackTrace();
  266. }
  267. }
  268.  
  269. public static void main( String args[] )
  270. {
  271. // Create an instance of the test application
  272.  
  273. }
  274.  
  275. }
  276.  
  277. public class StartActivity extends JFrame implements ActionListener{
  278. /**
  279. *
  280. */
  281. private static final long serialVersionUID = -1470898831456146593L;
  282. private JTextField textField;
  283. public JTextField[] textStock = new JTextField[190];
  284. public tags[] tags = new tags[90];
  285. public String[] tg = new String[90];
  286. public JList set = new JList();
  287.  
  288. public StartActivity(){
  289.  
  290. setSize(1800, 950); // create an instance
  291. setBackground(Color.gray);
  292.  
  293.  
  294. FileReader file = null; // get the tags and their name
  295. FileReader file2 = null;
  296. try {
  297.  
  298. file = new FileReader("src/resource/tagsName.txt");
  299. } catch (FileNotFoundException e1) {
  300. // TODO Auto-generated catch block
  301. e1.printStackTrace();
  302. }
  303. BufferedReader br = new BufferedReader(file);
  304. try {
  305. file2 = new FileReader("src/resource/ref.txt");
  306. } catch (FileNotFoundException e1) {
  307. // TODO Auto-generated catch block
  308. e1.printStackTrace();
  309. }
  310. BufferedReader br2 = new BufferedReader(file2);
  311.  
  312.  
  313.  
  314. // textField = new JTextField();
  315. // textField.setBounds(35, 136, 86, 20);
  316. // add(textField);
  317. // textField.setColumns(10);
  318. int x = 35;
  319. int y= 136;
  320.  
  321. for (int i=0 ; i < 190 ; i++){ // add the text field to enter the quote
  322. textStock[i] = new JTextField("");
  323. textStock[i].setBounds(x,y,86,20);
  324. add(textStock[i]);
  325. textStock[i].setColumns(10);
  326. y = y + 25;
  327. if (y > 900){
  328. y = 136;
  329. x = x + 91;
  330. }
  331. }
  332.  
  333. JLabel label1 = new JLabel("Enter Stock Symbols");
  334. label1.setBounds((x-35)/2, 100, 200, 20);
  335. add(label1);
  336.  
  337. //addKeyListener(this);
  338.  
  339.  
  340. String tg = "";
  341. String rf = "";
  342. x = x + 200;
  343. y= 136;
  344. int i = 0;
  345. int z = x;
  346. try { //
  347. while((tg = br.readLine()) != null){ // add textfields to enter their tags
  348. rf =br2.readLine();
  349. tags[i] = new tags(tg, rf); // tags are a separte method that has
  350. tags[i].setBounds(x, y, 200, 23); // tags are declared as buttons
  351. add(tags[i]);
  352. y = y + 28;
  353. if (y > 900){
  354. y = 136;
  355. x = x + 205;
  356. }
  357. tg = "";
  358. i = i +1;
  359. }
  360. } catch (IOException e2) {
  361. // TODO Auto-generated catch block
  362. e2.printStackTrace();
  363. }
  364. try {
  365. br.close();
  366. } catch (IOException e1) {
  367. // TODO Auto-generated catch block
  368. e1.printStackTrace();
  369. }
  370. JLabel label2 = new JLabel("Choose stock tags Retrival");
  371. label2.setBounds((x+z)/2, 100, 200, 20);
  372. add(label2);
  373.  
  374. //set = new JList();
  375.  
  376. JButton list1= new JButton("List 1");
  377. list1.setBounds(35, 100, 89, 23);
  378. list1.addActionListener(this);
  379. add(list1);
  380.  
  381. JButton run = new JButton("Run");
  382. run.setBounds(getWidth()/2, 32, 89, 23);
  383. run.addActionListener(this);
  384. add(run);
  385.  
  386. JButton analyse = new JButton("Analyse");
  387. analyse.setBounds(getWidth()/2 - 200, 32, 89, 23);
  388. analyse.addActionListener(this);
  389. add(analyse);
  390.  
  391. //Frame frame = (Frame) this.getParent().getParent();
  392. //frame.setTitle(" Financial Analysis");
  393. try {
  394.  
  395. } catch (Exception e) {
  396. // TODO: handle exception
  397. }
  398.  
  399.  
  400. }
  401.  
  402.  
  403.  
  404.  
  405. public void actionPerformed(ActionEvent arg0) {
  406. // TODO Auto-generated method stub
  407. /**
  408. * call method depending on their button
  409. */
  410.  
  411. System.out.println(arg0.getActionCommand());
  412. if (arg0.getActionCommand()== "Run"){
  413. stockdata();
  414. }
  415. //System.out.println("true");
  416. if (arg0.getActionCommand()== "List 1"){
  417. listSet(1);
  418. }
  419. if (arg0.getActionCommand()== "Analyse"){
  420. choose();
  421. System.out.println(arg0.getActionCommand());
  422. }
  423. }
  424.  
  425. private void choose() {
  426. /*
  427. * analyse quotes with parameters that I choose
  428. */
  429. int m =0;
  430. String[] quotes = new String[200];
  431. int s =0;
  432. String[] tq = new String[20];
  433. String qurl = "http://finance.yahoo.com/d/quotes.csv?s=";
  434. for (int i=0 ; i < 60 ; i++){
  435. String stock =textStock[i].getText();
  436. if (m == 0 && stock != ""){
  437. qurl = qurl + stock ;
  438. m =1 ;
  439. quotes[s] = stock;
  440. s=s+1;
  441. }
  442. else if(stock != ""){
  443. qurl = qurl +"+"+ stock ;
  444. quotes[s] = stock;
  445. s=s+1;
  446. }
  447. }
  448. qurl = qurl + "&f=l1vhgd1rp6";
  449.  
  450. System.out.println(qurl);
  451. Analysis tab = new Analysis(qurl, quotes); // param are declared in another
  452. tab.setVisible(true);
  453. }
  454.  
  455. private void stockdata() {
  456.  
  457. /*
  458. * retrieves stock data
  459. */
  460. int m =0;
  461. String[] tq = new String[20];
  462. String[] quotes = new String[200];
  463. int s =0;
  464. String qurl = "http://finance.yahoo.com/d/quotes.csv?s=";
  465. for (int i=0 ; i < 60 ; i++){
  466. String stock =textStock[i].getText();
  467. if (m == 0 && stock != ""){
  468. qurl = qurl + stock ;
  469. quotes[s] = stock;
  470. s=s+1;
  471. m =1 ;
  472. }
  473. else if(stock != ""){
  474. qurl = qurl +"+"+ stock ;
  475. quotes[s] = stock;
  476. //System.out.println(quotes[s]);
  477. s=s+1;
  478. }
  479. }
  480. qurl = qurl + "&f=";
  481. int z =0;
  482. for (int i=0 ; i < 60 ; i++){
  483. if(tags[i].getStatus()){
  484. qurl = qurl + tags[i].getReference();
  485. tq[z]= tags[i].getName();
  486. z =z+1;
  487. }
  488.  
  489. }
  490.  
  491. System.out.println(qurl);
  492. // this method retrives data and creates a table to show them
  493. StockData tab = new StockData(qurl, tq, quotes);
  494. tab.setVisible(true);
  495. }
  496. private void listSet(int fileNumber){
  497. // this method populates a set of stocks
  498. FileReader file = null;
  499.  
  500. try {
  501. file = new FileReader("src/resource/set"+fileNumber + ".txt");
  502. } catch (FileNotFoundException e1) {
  503. // TODO Auto-generated catch block
  504. e1.printStackTrace();
  505. }
  506. BufferedReader br = new BufferedReader(file);
  507. String tg;
  508. int i = 0;
  509. try {
  510. while((tg = br.readLine()) != null){
  511. if (i<190){
  512. textStock[i].setText(tg);
  513. i = i +1;
  514.  
  515. }}
  516. } catch (IOException e) {
  517. // TODO Auto-generated catch block
  518. e.printStackTrace();
  519. }
  520. }
  521.  
  522. public static void main( String args[] )
  523. {
  524. StartActivity mainFrame = new StartActivity();
  525. mainFrame.setVisible( true );
  526.  
  527. }
  528.  
  529. }
Add Comment
Please, Sign In to add comment