Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package avanzareader;
- import java.io.IOException;
- import java.net.MalformedURLException;
- import java.net.PasswordAuthentication;
- import java.net.URL;
- import java.util.Properties;
- import java.util.Scanner;
- import javax.mail.Message;
- import javax.mail.MessagingException;
- import javax.mail.Session;
- import javax.mail.Transport;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeMessage;
- /**
- *
- * @author Adil
- */
- public class AvanzaReaderJFrame extends javax.swing.JFrame {
- public static boolean watchRunning = true;
- public void startWatch() {
- //Check if we already started the watch
- if(watchRunning) {
- return;
- }
- //We've started the watch!
- watchRunning = true;
- //Start the watch..
- Runnable task = new Runnable() {
- @Override
- public void run() {
- int x = 0;
- boolean increase = true;
- while(watchRunning){
- jProgressBar1.setValue(x); //Visuellt effekt för att kolla
- //om programmet körs
- if(x >= 100){
- increase = false;
- }
- if(x <= 0){
- increase = true;
- }
- if(increase == true){
- x += 2;
- }else{
- x -= 2;
- }
- try {
- Thread.sleep(100);
- } catch (InterruptedException ex) {
- System.out.println("Could not sleep in thread.");
- TextArea.append("Could not sleep in thread. \n");
- }
- }
- }
- };
- new Thread(task).start();
- }
- public AvanzaReaderJFrame() {
- initComponents();
- TextArea.append("Program initiated \n");
- }
- public void init(){
- }
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- LinkField1 = new javax.swing.JTextField();
- LinkField2 = new javax.swing.JTextField();
- LinkField3 = new javax.swing.JTextField();
- LinkField4 = new javax.swing.JTextField();
- LinkField5 = new javax.swing.JTextField();
- Active1 = new javax.swing.JCheckBox();
- Active2 = new javax.swing.JCheckBox();
- Active3 = new javax.swing.JCheckBox();
- Active4 = new javax.swing.JCheckBox();
- Active5 = new javax.swing.JCheckBox();
- ActiveLabel = new javax.swing.JLabel();
- LinkLabel = new javax.swing.JLabel();
- NameField1 = new javax.swing.JTextField();
- NameField2 = new javax.swing.JTextField();
- NameField3 = new javax.swing.JTextField();
- NameField4 = new javax.swing.JTextField();
- NameField5 = new javax.swing.JTextField();
- NameLabel = new javax.swing.JLabel();
- CurrentPriceField1 = new javax.swing.JTextField();
- CurrentPriceField2 = new javax.swing.JTextField();
- CurrentPriceField4 = new javax.swing.JTextField();
- CurrentPriceField3 = new javax.swing.JTextField();
- CurrentPriceField5 = new javax.swing.JTextField();
- CurrentPriceLabel = new javax.swing.JLabel();
- HighestPriceField1 = new javax.swing.JTextField();
- HighestPriceField2 = new javax.swing.JTextField();
- HighestPriceField4 = new javax.swing.JTextField();
- HighestPriceField3 = new javax.swing.JTextField();
- HighestPriceField5 = new javax.swing.JTextField();
- HighestPriceLabel = new javax.swing.JLabel();
- jScrollPane1 = new javax.swing.JScrollPane();
- TextArea = new javax.swing.JTextArea();
- GetNamesButton = new javax.swing.JButton();
- GetPriceButton = new javax.swing.JButton();
- StartWatchButton = new javax.swing.JButton();
- jProgressBar1 = new javax.swing.JProgressBar();
- StopWatchButton = new javax.swing.JButton();
- jButton1 = new javax.swing.JButton();
- jLabel1 = new javax.swing.JLabel();
- jTextField1 = new javax.swing.JTextField();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- Active1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- Active1ActionPerformed(evt);
- }
- });
- ActiveLabel.setText("Active");
- LinkLabel.setText("Link");
- NameField1.setEditable(false);
- NameField1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- NameField1ActionPerformed(evt);
- }
- });
- NameField2.setEditable(false);
- NameField3.setEditable(false);
- NameField4.setEditable(false);
- NameField5.setEditable(false);
- NameField5.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- NameField5ActionPerformed(evt);
- }
- });
- NameLabel.setText("Name");
- CurrentPriceField1.setEditable(false);
- CurrentPriceField2.setEditable(false);
- CurrentPriceField4.setEditable(false);
- CurrentPriceField3.setEditable(false);
- CurrentPriceField5.setEditable(false);
- CurrentPriceLabel.setText("Current price");
- HighestPriceField1.setEditable(false);
- HighestPriceField1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- HighestPriceField1ActionPerformed(evt);
- }
- });
- HighestPriceField2.setEditable(false);
- HighestPriceField2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- HighestPriceField2ActionPerformed(evt);
- }
- });
- HighestPriceField4.setEditable(false);
- HighestPriceField4.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- HighestPriceField4ActionPerformed(evt);
- }
- });
- HighestPriceField3.setEditable(false);
- HighestPriceField3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- HighestPriceField3ActionPerformed(evt);
- }
- });
- HighestPriceField5.setEditable(false);
- HighestPriceField5.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- HighestPriceField5ActionPerformed(evt);
- }
- });
- HighestPriceLabel.setText("Highest Price");
- TextArea.setColumns(20);
- TextArea.setRows(5);
- jScrollPane1.setViewportView(TextArea);
- GetNamesButton.setText("Get names");
- GetNamesButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- GetNamesButtonActionPerformed(evt);
- }
- });
- GetPriceButton.setText("Get price");
- StartWatchButton.setText("Start watch");
- StartWatchButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- StartWatchButtonActionPerformed(evt);
- }
- });
- StopWatchButton.setText("Stop watch");
- StopWatchButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- StopWatchButtonActionPerformed(evt);
- }
- });
- jButton1.setText("Test send email");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jLabel1.setText("Recipient email");
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jTextField1))
- .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addComponent(Active1)
- .addGap(18, 18, 18)
- .addComponent(LinkField1))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addComponent(Active2)
- .addGap(18, 18, 18)
- .addComponent(LinkField2))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addComponent(Active3)
- .addGap(18, 18, 18)
- .addComponent(LinkField3))
- .addGroup(layout.createSequentialGroup()
- .addComponent(ActiveLabel)
- .addGap(130, 130, 130)
- .addComponent(LinkLabel)
- .addGap(0, 298, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(Active4)
- .addGap(18, 18, 18)
- .addComponent(LinkField4))
- .addGroup(layout.createSequentialGroup()
- .addComponent(Active5)
- .addGap(18, 18, 18)
- .addComponent(LinkField5)))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(NameField1)
- .addComponent(NameField2)
- .addComponent(NameField3)
- .addComponent(NameField4)
- .addGroup(layout.createSequentialGroup()
- .addGap(41, 41, 41)
- .addComponent(NameLabel)
- .addGap(42, 42, 42))
- .addComponent(NameField5)
- .addComponent(GetNamesButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGap(0, 0, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(StopWatchButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(StartWatchButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGap(18, 18, 18)))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(CurrentPriceLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(CurrentPriceField3)
- .addComponent(CurrentPriceField4)
- .addComponent(CurrentPriceField5)
- .addComponent(CurrentPriceField1)
- .addComponent(CurrentPriceField2, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(HighestPriceLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(HighestPriceField1)
- .addComponent(HighestPriceField2)
- .addComponent(HighestPriceField3)
- .addComponent(HighestPriceField4)
- .addComponent(HighestPriceField5, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addComponent(GetPriceButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addComponent(jButton1))
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(CurrentPriceLabel)
- .addComponent(HighestPriceLabel))
- .addComponent(NameLabel, javax.swing.GroupLayout.Alignment.TRAILING))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(NameField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(CurrentPriceField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(HighestPriceField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(NameField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(CurrentPriceField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(HighestPriceField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(NameField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(CurrentPriceField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(HighestPriceField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(NameField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(CurrentPriceField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(HighestPriceField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(NameField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(CurrentPriceField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(HighestPriceField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(GetNamesButton)
- .addComponent(GetPriceButton))
- .addGap(31, 31, 31)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(StartWatchButton, javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jProgressBar1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(StopWatchButton))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(LinkLabel)
- .addComponent(ActiveLabel))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(LinkField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(Active1))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(LinkField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(Active2))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(LinkField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(Active3))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(LinkField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(Active4))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(LinkField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(Active5))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton1))
- .addContainerGap(18, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void Active1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void NameField1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void NameField5ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void HighestPriceField1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void HighestPriceField2ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void HighestPriceField4ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void HighestPriceField3ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void HighestPriceField5ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void GetNamesButtonActionPerformed(java.awt.event.ActionEvent evt) {
- if(Active1.isSelected()){
- NameField1.setText(getName(LinkField1.getText()));
- };
- if(Active2.isSelected()){
- NameField2.setText(getName(LinkField2.getText()));
- };
- if(Active3.isSelected()){
- NameField3.setText(getName(LinkField3.getText()));
- };
- if(Active4.isSelected()){
- NameField4.setText(getName(LinkField4.getText()));
- };
- if(Active5.isSelected()){
- NameField5.setText(getName(LinkField5.getText()));
- };
- }
- private void StartWatchButtonActionPerformed(java.awt.event.ActionEvent evt) {
- TextArea.append("Starting watch \n");
- startWatch();
- }
- private void StopWatchButtonActionPerformed(java.awt.event.ActionEvent evt) {
- TextArea.append("Stopping watch \n");
- watchRunning = false;
- }
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- sendMail("@gmail.com","test","test1");
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(AvanzaReaderJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(AvanzaReaderJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(AvanzaReaderJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(AvanzaReaderJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new AvanzaReaderJFrame().setVisible(true);
- }
- });
- }
- public String getName(String TMP){ //Returns name of the company of the share
- if(TMP.isEmpty()){
- return TMP;
- }
- String name = null;
- Scanner scanner = null;
- URL url = null;
- try {
- url = new URL(TMP);
- } catch (MalformedURLException ex) {
- TextArea.append("Could not read url " + TMP);
- }
- try {
- scanner = new Scanner(url.openStream());
- } catch (IOException ex) {
- TextArea.append("Could not open url " + TMP);
- }
- while (scanner.hasNext()) {
- name = scanner.nextLine().trim();
- if (name.toLowerCase().contains("data-orderbook_name".toLowerCase())) {
- name = name.replace("data-orderbook_name=", "");
- name = name.replaceAll("\"", "");
- break;
- }
- }
- if(name.contains("</html>")){
- TextArea.append("Could not find name " + TMP);
- name = "null";
- }
- return name;
- }
- public void sendMail(String to, String title, String text) { //Sends email
- String username = "@gmail.com";
- String password = "password";
- Properties props = new Properties();
- props.put("mail.smtp.starttls.enable", "true");
- props.put("mail.smtp.auth", "true");
- props.put("mail.smtp.host", "smtp.gmail.com");
- props.put("mail.smtp.port", "587");
- Session session = Session.getInstance(props,
- new javax.mail.Authenticator(){
- @Override
- protected PasswordAuthentication getPasswordAuthentication(){
- return new PasswordAuthentication(username, password);
- }
- });
- try{
- Message message = new MimeMessage(session);
- message.setFrom(new InternetAddress("@gmail.com"));
- message.setRecipients(Message.RecipientType.TO,
- InternetAddress.parse(to));
- message.setSubject("Aktie notis:" + title);
- message.setText(text);
- Transport.send(message);
- TextArea.append("Mail sent! \n");
- System.out.println("Mail sent!");
- } catch (MessagingException e){
- TextArea.append("Email error. \n");
- System.out.println("Email error.");
- }
- }
- // Variables declaration - do not modify
- private javax.swing.JCheckBox Active1;
- private javax.swing.JCheckBox Active2;
- private javax.swing.JCheckBox Active3;
- private javax.swing.JCheckBox Active4;
- private javax.swing.JCheckBox Active5;
- private javax.swing.JLabel ActiveLabel;
- private javax.swing.JTextField CurrentPriceField1;
- private javax.swing.JTextField CurrentPriceField2;
- private javax.swing.JTextField CurrentPriceField3;
- private javax.swing.JTextField CurrentPriceField4;
- private javax.swing.JTextField CurrentPriceField5;
- private javax.swing.JLabel CurrentPriceLabel;
- private javax.swing.JButton GetNamesButton;
- private javax.swing.JButton GetPriceButton;
- private javax.swing.JTextField HighestPriceField1;
- private javax.swing.JTextField HighestPriceField2;
- private javax.swing.JTextField HighestPriceField3;
- private javax.swing.JTextField HighestPriceField4;
- private javax.swing.JTextField HighestPriceField5;
- private javax.swing.JLabel HighestPriceLabel;
- private javax.swing.JTextField LinkField1;
- private javax.swing.JTextField LinkField2;
- private javax.swing.JTextField LinkField3;
- private javax.swing.JTextField LinkField4;
- private javax.swing.JTextField LinkField5;
- private javax.swing.JLabel LinkLabel;
- private javax.swing.JTextField NameField1;
- private javax.swing.JTextField NameField2;
- private javax.swing.JTextField NameField3;
- private javax.swing.JTextField NameField4;
- private javax.swing.JTextField NameField5;
- private javax.swing.JLabel NameLabel;
- private javax.swing.JButton StartWatchButton;
- private javax.swing.JButton StopWatchButton;
- private javax.swing.JTextArea TextArea;
- private javax.swing.JButton jButton1;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JProgressBar jProgressBar1;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JTextField jTextField1;
- // End of variables declaration
- }
Add Comment
Please, Sign In to add comment