Guest User

Untitled

a guest
Feb 16th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.76 KB | None | 0 0
  1. package avanzareader;
  2.  
  3. import java.io.IOException;
  4. import java.net.MalformedURLException;
  5. import java.net.PasswordAuthentication;
  6. import java.net.URL;
  7. import java.util.Properties;
  8. import java.util.Scanner;
  9.  
  10. import javax.mail.Message;
  11. import javax.mail.MessagingException;
  12. import javax.mail.Session;
  13. import javax.mail.Transport;
  14. import javax.mail.internet.InternetAddress;
  15. import javax.mail.internet.MimeMessage;
  16.  
  17. /**
  18. *
  19. * @author Adil
  20. */
  21. public class AvanzaReaderJFrame extends javax.swing.JFrame {
  22.  
  23. public static boolean watchRunning = true;
  24.  
  25. public void startWatch() {
  26.  
  27. //Check if we already started the watch
  28. if(watchRunning) {
  29. return;
  30. }
  31.  
  32. //We've started the watch!
  33. watchRunning = true;
  34.  
  35. //Start the watch..
  36. Runnable task = new Runnable() {
  37. @Override
  38. public void run() {
  39. int x = 0;
  40. boolean increase = true;
  41. while(watchRunning){
  42.  
  43. jProgressBar1.setValue(x); //Visuellt effekt för att kolla
  44. //om programmet körs
  45. if(x >= 100){
  46. increase = false;
  47. }
  48. if(x <= 0){
  49. increase = true;
  50. }
  51. if(increase == true){
  52. x += 2;
  53. }else{
  54. x -= 2;
  55. }
  56. try {
  57. Thread.sleep(100);
  58. } catch (InterruptedException ex) {
  59. System.out.println("Could not sleep in thread.");
  60. TextArea.append("Could not sleep in thread. \n");
  61. }
  62. }
  63. }
  64. };
  65. new Thread(task).start();
  66. }
  67.  
  68. public AvanzaReaderJFrame() {
  69. initComponents();
  70. TextArea.append("Program initiated \n");
  71. }
  72.  
  73. public void init(){
  74.  
  75. }
  76.  
  77. @SuppressWarnings("unchecked")
  78. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  79. private void initComponents() {
  80.  
  81. LinkField1 = new javax.swing.JTextField();
  82. LinkField2 = new javax.swing.JTextField();
  83. LinkField3 = new javax.swing.JTextField();
  84. LinkField4 = new javax.swing.JTextField();
  85. LinkField5 = new javax.swing.JTextField();
  86. Active1 = new javax.swing.JCheckBox();
  87. Active2 = new javax.swing.JCheckBox();
  88. Active3 = new javax.swing.JCheckBox();
  89. Active4 = new javax.swing.JCheckBox();
  90. Active5 = new javax.swing.JCheckBox();
  91. ActiveLabel = new javax.swing.JLabel();
  92. LinkLabel = new javax.swing.JLabel();
  93. NameField1 = new javax.swing.JTextField();
  94. NameField2 = new javax.swing.JTextField();
  95. NameField3 = new javax.swing.JTextField();
  96. NameField4 = new javax.swing.JTextField();
  97. NameField5 = new javax.swing.JTextField();
  98. NameLabel = new javax.swing.JLabel();
  99. CurrentPriceField1 = new javax.swing.JTextField();
  100. CurrentPriceField2 = new javax.swing.JTextField();
  101. CurrentPriceField4 = new javax.swing.JTextField();
  102. CurrentPriceField3 = new javax.swing.JTextField();
  103. CurrentPriceField5 = new javax.swing.JTextField();
  104. CurrentPriceLabel = new javax.swing.JLabel();
  105. HighestPriceField1 = new javax.swing.JTextField();
  106. HighestPriceField2 = new javax.swing.JTextField();
  107. HighestPriceField4 = new javax.swing.JTextField();
  108. HighestPriceField3 = new javax.swing.JTextField();
  109. HighestPriceField5 = new javax.swing.JTextField();
  110. HighestPriceLabel = new javax.swing.JLabel();
  111. jScrollPane1 = new javax.swing.JScrollPane();
  112. TextArea = new javax.swing.JTextArea();
  113. GetNamesButton = new javax.swing.JButton();
  114. GetPriceButton = new javax.swing.JButton();
  115. StartWatchButton = new javax.swing.JButton();
  116. jProgressBar1 = new javax.swing.JProgressBar();
  117. StopWatchButton = new javax.swing.JButton();
  118. jButton1 = new javax.swing.JButton();
  119. jLabel1 = new javax.swing.JLabel();
  120. jTextField1 = new javax.swing.JTextField();
  121.  
  122. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  123.  
  124. Active1.addActionListener(new java.awt.event.ActionListener() {
  125. public void actionPerformed(java.awt.event.ActionEvent evt) {
  126. Active1ActionPerformed(evt);
  127. }
  128. });
  129.  
  130. ActiveLabel.setText("Active");
  131.  
  132. LinkLabel.setText("Link");
  133.  
  134. NameField1.setEditable(false);
  135. NameField1.addActionListener(new java.awt.event.ActionListener() {
  136. public void actionPerformed(java.awt.event.ActionEvent evt) {
  137. NameField1ActionPerformed(evt);
  138. }
  139. });
  140.  
  141. NameField2.setEditable(false);
  142.  
  143. NameField3.setEditable(false);
  144.  
  145. NameField4.setEditable(false);
  146.  
  147. NameField5.setEditable(false);
  148. NameField5.addActionListener(new java.awt.event.ActionListener() {
  149. public void actionPerformed(java.awt.event.ActionEvent evt) {
  150. NameField5ActionPerformed(evt);
  151. }
  152. });
  153.  
  154. NameLabel.setText("Name");
  155.  
  156. CurrentPriceField1.setEditable(false);
  157.  
  158. CurrentPriceField2.setEditable(false);
  159.  
  160. CurrentPriceField4.setEditable(false);
  161.  
  162. CurrentPriceField3.setEditable(false);
  163.  
  164. CurrentPriceField5.setEditable(false);
  165.  
  166. CurrentPriceLabel.setText("Current price");
  167.  
  168. HighestPriceField1.setEditable(false);
  169. HighestPriceField1.addActionListener(new java.awt.event.ActionListener() {
  170. public void actionPerformed(java.awt.event.ActionEvent evt) {
  171. HighestPriceField1ActionPerformed(evt);
  172. }
  173. });
  174.  
  175. HighestPriceField2.setEditable(false);
  176. HighestPriceField2.addActionListener(new java.awt.event.ActionListener() {
  177. public void actionPerformed(java.awt.event.ActionEvent evt) {
  178. HighestPriceField2ActionPerformed(evt);
  179. }
  180. });
  181.  
  182. HighestPriceField4.setEditable(false);
  183. HighestPriceField4.addActionListener(new java.awt.event.ActionListener() {
  184. public void actionPerformed(java.awt.event.ActionEvent evt) {
  185. HighestPriceField4ActionPerformed(evt);
  186. }
  187. });
  188.  
  189. HighestPriceField3.setEditable(false);
  190. HighestPriceField3.addActionListener(new java.awt.event.ActionListener() {
  191. public void actionPerformed(java.awt.event.ActionEvent evt) {
  192. HighestPriceField3ActionPerformed(evt);
  193. }
  194. });
  195.  
  196. HighestPriceField5.setEditable(false);
  197. HighestPriceField5.addActionListener(new java.awt.event.ActionListener() {
  198. public void actionPerformed(java.awt.event.ActionEvent evt) {
  199. HighestPriceField5ActionPerformed(evt);
  200. }
  201. });
  202.  
  203. HighestPriceLabel.setText("Highest Price");
  204.  
  205. TextArea.setColumns(20);
  206. TextArea.setRows(5);
  207. jScrollPane1.setViewportView(TextArea);
  208.  
  209. GetNamesButton.setText("Get names");
  210. GetNamesButton.addActionListener(new java.awt.event.ActionListener() {
  211. public void actionPerformed(java.awt.event.ActionEvent evt) {
  212. GetNamesButtonActionPerformed(evt);
  213. }
  214. });
  215.  
  216. GetPriceButton.setText("Get price");
  217.  
  218. StartWatchButton.setText("Start watch");
  219. StartWatchButton.addActionListener(new java.awt.event.ActionListener() {
  220. public void actionPerformed(java.awt.event.ActionEvent evt) {
  221. StartWatchButtonActionPerformed(evt);
  222. }
  223. });
  224.  
  225. StopWatchButton.setText("Stop watch");
  226. StopWatchButton.addActionListener(new java.awt.event.ActionListener() {
  227. public void actionPerformed(java.awt.event.ActionEvent evt) {
  228. StopWatchButtonActionPerformed(evt);
  229. }
  230. });
  231.  
  232. jButton1.setText("Test send email");
  233. jButton1.addActionListener(new java.awt.event.ActionListener() {
  234. public void actionPerformed(java.awt.event.ActionEvent evt) {
  235. jButton1ActionPerformed(evt);
  236. }
  237. });
  238.  
  239. jLabel1.setText("Recipient email");
  240.  
  241. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  242. getContentPane().setLayout(layout);
  243. layout.setHorizontalGroup(
  244. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  245. .addGroup(layout.createSequentialGroup()
  246. .addContainerGap()
  247. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  248. .addGroup(layout.createSequentialGroup()
  249. .addComponent(jLabel1)
  250. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  251. .addComponent(jTextField1))
  252. .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
  253. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  254. .addComponent(Active1)
  255. .addGap(18, 18, 18)
  256. .addComponent(LinkField1))
  257. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  258. .addComponent(Active2)
  259. .addGap(18, 18, 18)
  260. .addComponent(LinkField2))
  261. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  262. .addComponent(Active3)
  263. .addGap(18, 18, 18)
  264. .addComponent(LinkField3))
  265. .addGroup(layout.createSequentialGroup()
  266. .addComponent(ActiveLabel)
  267. .addGap(130, 130, 130)
  268. .addComponent(LinkLabel)
  269. .addGap(0, 298, Short.MAX_VALUE))
  270. .addGroup(layout.createSequentialGroup()
  271. .addComponent(Active4)
  272. .addGap(18, 18, 18)
  273. .addComponent(LinkField4))
  274. .addGroup(layout.createSequentialGroup()
  275. .addComponent(Active5)
  276. .addGap(18, 18, 18)
  277. .addComponent(LinkField5)))
  278. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  279. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  280. .addGroup(layout.createSequentialGroup()
  281. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  282. .addComponent(NameField1)
  283. .addComponent(NameField2)
  284. .addComponent(NameField3)
  285. .addComponent(NameField4)
  286. .addGroup(layout.createSequentialGroup()
  287. .addGap(41, 41, 41)
  288. .addComponent(NameLabel)
  289. .addGap(42, 42, 42))
  290. .addComponent(NameField5)
  291. .addComponent(GetNamesButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  292. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  293. .addGap(0, 0, Short.MAX_VALUE)
  294. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  295. .addComponent(StopWatchButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  296. .addComponent(StartWatchButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  297. .addGap(18, 18, 18)))
  298. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  299. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  300. .addGroup(layout.createSequentialGroup()
  301. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  302. .addComponent(CurrentPriceLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  303. .addComponent(CurrentPriceField3)
  304. .addComponent(CurrentPriceField4)
  305. .addComponent(CurrentPriceField5)
  306. .addComponent(CurrentPriceField1)
  307. .addComponent(CurrentPriceField2, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
  308. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  309. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  310. .addComponent(HighestPriceLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  311. .addComponent(HighestPriceField1)
  312. .addComponent(HighestPriceField2)
  313. .addComponent(HighestPriceField3)
  314. .addComponent(HighestPriceField4)
  315. .addComponent(HighestPriceField5, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)))
  316. .addComponent(GetPriceButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  317. .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)))
  318. .addComponent(jButton1))
  319. .addContainerGap())
  320. );
  321. layout.setVerticalGroup(
  322. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  323. .addGroup(layout.createSequentialGroup()
  324. .addContainerGap()
  325. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  326. .addGroup(layout.createSequentialGroup()
  327. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  328. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  329. .addComponent(CurrentPriceLabel)
  330. .addComponent(HighestPriceLabel))
  331. .addComponent(NameLabel, javax.swing.GroupLayout.Alignment.TRAILING))
  332. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  333. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  334. .addComponent(NameField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  335. .addComponent(CurrentPriceField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  336. .addComponent(HighestPriceField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  337. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  338. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  339. .addComponent(NameField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  340. .addComponent(CurrentPriceField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  341. .addComponent(HighestPriceField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  342. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  343. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  344. .addComponent(NameField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  345. .addComponent(CurrentPriceField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  346. .addComponent(HighestPriceField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  347. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  348. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  349. .addComponent(NameField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  350. .addComponent(CurrentPriceField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  351. .addComponent(HighestPriceField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  352. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  353. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  354. .addComponent(NameField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  355. .addComponent(CurrentPriceField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  356. .addComponent(HighestPriceField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  357. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  358. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  359. .addComponent(GetNamesButton)
  360. .addComponent(GetPriceButton))
  361. .addGap(31, 31, 31)
  362. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  363. .addComponent(StartWatchButton, javax.swing.GroupLayout.Alignment.TRAILING)
  364. .addComponent(jProgressBar1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  365. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  366. .addComponent(StopWatchButton))
  367. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  368. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  369. .addComponent(LinkLabel)
  370. .addComponent(ActiveLabel))
  371. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  372. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  373. .addGroup(layout.createSequentialGroup()
  374. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  375. .addComponent(LinkField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  376. .addComponent(Active1))
  377. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  378. .addComponent(LinkField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  379. .addComponent(Active2))
  380. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  381. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  382. .addComponent(LinkField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  383. .addComponent(Active3))
  384. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  385. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  386. .addComponent(LinkField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  387. .addComponent(Active4))
  388. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  389. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  390. .addComponent(LinkField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  391. .addComponent(Active5))
  392. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  393. .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)))
  394. .addGap(18, 18, 18)
  395. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  396. .addComponent(jLabel1)
  397. .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  398. .addComponent(jButton1))
  399. .addContainerGap(18, Short.MAX_VALUE))
  400. );
  401.  
  402. pack();
  403. }// </editor-fold>
  404.  
  405. private void Active1ActionPerformed(java.awt.event.ActionEvent evt) {
  406. // TODO add your handling code here:
  407. }
  408.  
  409. private void NameField1ActionPerformed(java.awt.event.ActionEvent evt) {
  410. // TODO add your handling code here:
  411. }
  412.  
  413. private void NameField5ActionPerformed(java.awt.event.ActionEvent evt) {
  414. // TODO add your handling code here:
  415. }
  416.  
  417. private void HighestPriceField1ActionPerformed(java.awt.event.ActionEvent evt) {
  418. // TODO add your handling code here:
  419. }
  420.  
  421. private void HighestPriceField2ActionPerformed(java.awt.event.ActionEvent evt) {
  422. // TODO add your handling code here:
  423. }
  424.  
  425. private void HighestPriceField4ActionPerformed(java.awt.event.ActionEvent evt) {
  426. // TODO add your handling code here:
  427. }
  428.  
  429. private void HighestPriceField3ActionPerformed(java.awt.event.ActionEvent evt) {
  430. // TODO add your handling code here:
  431. }
  432.  
  433. private void HighestPriceField5ActionPerformed(java.awt.event.ActionEvent evt) {
  434. // TODO add your handling code here:
  435. }
  436.  
  437. private void GetNamesButtonActionPerformed(java.awt.event.ActionEvent evt) {
  438. if(Active1.isSelected()){
  439. NameField1.setText(getName(LinkField1.getText()));
  440. };
  441. if(Active2.isSelected()){
  442. NameField2.setText(getName(LinkField2.getText()));
  443. };
  444. if(Active3.isSelected()){
  445. NameField3.setText(getName(LinkField3.getText()));
  446. };
  447. if(Active4.isSelected()){
  448. NameField4.setText(getName(LinkField4.getText()));
  449. };
  450. if(Active5.isSelected()){
  451. NameField5.setText(getName(LinkField5.getText()));
  452. };
  453. }
  454.  
  455. private void StartWatchButtonActionPerformed(java.awt.event.ActionEvent evt) {
  456. TextArea.append("Starting watch \n");
  457. startWatch();
  458.  
  459. }
  460.  
  461. private void StopWatchButtonActionPerformed(java.awt.event.ActionEvent evt) {
  462. TextArea.append("Stopping watch \n");
  463. watchRunning = false;
  464. }
  465.  
  466. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  467.  
  468. sendMail("@gmail.com","test","test1");
  469. }
  470.  
  471. /**
  472. * @param args the command line arguments
  473. */
  474. public static void main(String args[]) {
  475.  
  476.  
  477.  
  478. /* Set the Nimbus look and feel */
  479. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  480. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  481. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  482. */
  483. try {
  484. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  485. if ("Nimbus".equals(info.getName())) {
  486. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  487. break;
  488. }
  489. }
  490. } catch (ClassNotFoundException ex) {
  491. java.util.logging.Logger.getLogger(AvanzaReaderJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  492. } catch (InstantiationException ex) {
  493. java.util.logging.Logger.getLogger(AvanzaReaderJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  494. } catch (IllegalAccessException ex) {
  495. java.util.logging.Logger.getLogger(AvanzaReaderJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  496. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  497. java.util.logging.Logger.getLogger(AvanzaReaderJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  498. }
  499. //</editor-fold>
  500.  
  501. /* Create and display the form */
  502. java.awt.EventQueue.invokeLater(new Runnable() {
  503. public void run() {
  504.  
  505. new AvanzaReaderJFrame().setVisible(true);
  506. }
  507.  
  508. });
  509. }
  510.  
  511. public String getName(String TMP){ //Returns name of the company of the share
  512. if(TMP.isEmpty()){
  513. return TMP;
  514. }
  515. String name = null;
  516. Scanner scanner = null;
  517. URL url = null;
  518.  
  519. try {
  520. url = new URL(TMP);
  521. } catch (MalformedURLException ex) {
  522. TextArea.append("Could not read url " + TMP);
  523. }
  524.  
  525. try {
  526. scanner = new Scanner(url.openStream());
  527. } catch (IOException ex) {
  528. TextArea.append("Could not open url " + TMP);
  529. }
  530.  
  531. while (scanner.hasNext()) {
  532. name = scanner.nextLine().trim();
  533. if (name.toLowerCase().contains("data-orderbook_name".toLowerCase())) {
  534. name = name.replace("data-orderbook_name=", "");
  535. name = name.replaceAll("\"", "");
  536. break;
  537. }
  538. }
  539. if(name.contains("</html>")){
  540. TextArea.append("Could not find name " + TMP);
  541. name = "null";
  542. }
  543. return name;
  544. }
  545.  
  546. public void sendMail(String to, String title, String text) { //Sends email
  547. String username = "@gmail.com";
  548. String password = "password";
  549.  
  550. Properties props = new Properties();
  551. props.put("mail.smtp.starttls.enable", "true");
  552. props.put("mail.smtp.auth", "true");
  553. props.put("mail.smtp.host", "smtp.gmail.com");
  554. props.put("mail.smtp.port", "587");
  555.  
  556.  
  557. Session session = Session.getInstance(props,
  558. new javax.mail.Authenticator(){
  559. @Override
  560. protected PasswordAuthentication getPasswordAuthentication(){
  561. return new PasswordAuthentication(username, password);
  562. }
  563. });
  564. try{
  565. Message message = new MimeMessage(session);
  566. message.setFrom(new InternetAddress("@gmail.com"));
  567. message.setRecipients(Message.RecipientType.TO,
  568. InternetAddress.parse(to));
  569. message.setSubject("Aktie notis:" + title);
  570. message.setText(text);
  571. Transport.send(message);
  572. TextArea.append("Mail sent! \n");
  573. System.out.println("Mail sent!");
  574.  
  575. } catch (MessagingException e){
  576. TextArea.append("Email error. \n");
  577. System.out.println("Email error.");
  578. }
  579. }
  580.  
  581. // Variables declaration - do not modify
  582. private javax.swing.JCheckBox Active1;
  583. private javax.swing.JCheckBox Active2;
  584. private javax.swing.JCheckBox Active3;
  585. private javax.swing.JCheckBox Active4;
  586. private javax.swing.JCheckBox Active5;
  587. private javax.swing.JLabel ActiveLabel;
  588. private javax.swing.JTextField CurrentPriceField1;
  589. private javax.swing.JTextField CurrentPriceField2;
  590. private javax.swing.JTextField CurrentPriceField3;
  591. private javax.swing.JTextField CurrentPriceField4;
  592. private javax.swing.JTextField CurrentPriceField5;
  593. private javax.swing.JLabel CurrentPriceLabel;
  594. private javax.swing.JButton GetNamesButton;
  595. private javax.swing.JButton GetPriceButton;
  596. private javax.swing.JTextField HighestPriceField1;
  597. private javax.swing.JTextField HighestPriceField2;
  598. private javax.swing.JTextField HighestPriceField3;
  599. private javax.swing.JTextField HighestPriceField4;
  600. private javax.swing.JTextField HighestPriceField5;
  601. private javax.swing.JLabel HighestPriceLabel;
  602. private javax.swing.JTextField LinkField1;
  603. private javax.swing.JTextField LinkField2;
  604. private javax.swing.JTextField LinkField3;
  605. private javax.swing.JTextField LinkField4;
  606. private javax.swing.JTextField LinkField5;
  607. private javax.swing.JLabel LinkLabel;
  608. private javax.swing.JTextField NameField1;
  609. private javax.swing.JTextField NameField2;
  610. private javax.swing.JTextField NameField3;
  611. private javax.swing.JTextField NameField4;
  612. private javax.swing.JTextField NameField5;
  613. private javax.swing.JLabel NameLabel;
  614. private javax.swing.JButton StartWatchButton;
  615. private javax.swing.JButton StopWatchButton;
  616. private javax.swing.JTextArea TextArea;
  617. private javax.swing.JButton jButton1;
  618. private javax.swing.JLabel jLabel1;
  619. private javax.swing.JProgressBar jProgressBar1;
  620. private javax.swing.JScrollPane jScrollPane1;
  621. private javax.swing.JTextField jTextField1;
  622. // End of variables declaration
  623. }
Add Comment
Please, Sign In to add comment