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