i am to link an application that i have made to a user interface
the application works fine ok on prompt
but  when i link the results to an JTable i get event despaching errors
does some one have any idea
(i am including a demo tesst programme )
you have to change the servers ana passwor fields

Tia

-- 
Billy Kantartzis 
3rd year computer science,
Isaac Rebow House Flat 3,
University of Essex,
co4 3sq 
Colchester,
Essex,
phone:(+44) 0120653-6483
Mob: 07968151304
 
 import javax.swing.*;
 import java.awt.event.*;

 public class TestPane extends JFrame 
 { 
  

  public TestPane ()
  {
    super ("testing the table ");
   }

 public static void main (String[] args)
 {
   TestPane app = new TestPane();
   MessageListPane m = new MessageListPane("vkanta","bk123qaz");
   app.setSize(600,600);
   app.getContentPane().add (m);
   app.setVisible(true);
 }
 } 
/********************************************************
 *  File: MailReceiver.java
 *  Author:Billy Kantartzis 
 *  E-mail:[EMAIL PROTECTED]
 *  Date:09 jan 2001
 *  Description: 
 *  this is the Receive mail component of the TW GPa application 
 *  it is based on the java mail API.
 *   Purpose:
 * 
 *   Handles the main communication with the mail server and contains
 *   utility methods returning information conserning the mail sysytem
 *   and messages in a way that are easily presented on a  GUI
 ***************************************************************/ 

import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class MailReceiver 
{
/* Connection and user settinggs */

 private String protocol; 
 private static String host;
 private static int  messageNo;
 private  String user;
 private String password;
 private String mbox;
 private Properties props; 
 private Session session; 
 private Store store ;
 private Folder folder;
 private UIDFolder uidFolder;
 private Part part;

/* message info */
 private Message[] mesg;
 private int messages=0 , newMesg=0;
 private long uid=-1;    // no messages are read
/************************
 * constructor         *
 ***********************/
 
public  MailReceiver( String user, String pass)
  {
/* this constructor builds a connection tothe remote system
 * and then acesses a folder*/


    messageNo=0;
    this.protocol="imap";
    this.host="sh622.essex.ac.uk";
    this.user=user;
    password=pass;
    mbox="INBOX";        // default folder name
    props=System.getProperties();
    session=Session.getDefaultInstance(props,null);
    this.connect();
    this.process();    

  } // end constructor 





/************************
 * connect         *
 ***********************/
  void connect ()
  {
  /**
    connect handles the connection to the server and setup mail folder 
    information*/
    try 
    {
    System.out.println ("trying to login to "+ host);
     store =session.getStore (protocol);
     store.connect(host,user,password);
    }catch (MessagingException e0)
    {
     System.out.println ("invalid user/pass");
      System.out.println (user +  " " + password);
     e0.printStackTrace();
    }// end catch 

  }// end connect 

/************************
 * Process              *
 ************************/  
  void process ()

  {
   /** 
     - set up the default folder where we read messages from.
     - set up the fetch profile for the messages  
  */
    /* try to open the the folder where messages are 
       held*/
      try 
     {
     // open the default folder
     folder=store.getFolder(mbox); //get the message folder
     folder.open(Folder.READ_WRITE);   // we are trying to open the folder r/w

    }catch (MessagingException e1)
    {
     System.out.println ("unanble to open folder");
     e1.printStackTrace();
    }// end catch 

  /* get the number of messages and set the fetch profile
  */ 
   try
    {
     messages=folder.getMessageCount(); // read the total number of messages
     newMesg=folder.getNewMessageCount();// read how many new messages we have
      prepMsgGet();   // prepaere to receive messages    

    }
    catch (MessagingException e1)
     {
       e1.printStackTrace();
     }
  }// end process

  /***********************
   * getMessages        * 
   **********************/
    public int getMessages() 
    {
     /**
       this method returns the number the number of messages
       in a folder 
    */
       return (messages);
    }

  /***********************
   * getNewMessages        * 
   **********************/

    public int getNewMessages() 
    {
     /**
       Returns the number of  new messages
       on a system
     */ 
       return (newMesg);
    }
      

  /***********************
   * adrToStr* 
   **********************/

   public String adrToStr(Address[] adrs) throws MessagingException
   {
  /**
     convert internet address into String
     so that can be easily displayed on a text component 
     (i.e textArea textFields)
  */
    int i ;
    StringBuffer b = new StringBuffer();
    for ( i =0; i< adrs.length-1; i++);
    {
      b.append(adrs[i].toString());
    }
      return (b.toString());
   }// end adrToStr

 
  /***********************
   * getFrom* 
   **********************/

    public String getFrom(int i) throws MessagingException
   {
  /**
     Returns the From: field of a specified message i, in a string fromat using
     the utility fanctions adrsToStr 
  */

   Message m = mesg[i-1];
   Address[] a;
    if ( (a= m.getFrom()) != null)
    {
      return (adrToStr(a));
    }
   
    return (null);   
  }// end getFRom 


  /***********************
   * getTo* 
   **********************/
  public String getTo (int i) throws MessagingException
  {

  /**
     Returns the To: field of a specified message i, in a string fromat using
     the utility fanctions adrsToStr 
  */
    Message m = mesg[i-1];
    Address[] a;

    /* if there is an adress on to */
   
     if ((a=m.getRecipients(Message.RecipientType.TO)) != null)
     {
      
      return (adrToStr(a));
     }
     return null;     
  } // end get To

  /***********************
   * getCc* 
   **********************/

  public String getCc (int i) throws MessagingException
  {

  /**
     Returns the Cc: field of a specified message i, in a string fromat using
     the utility fanctions adrsToStr 
  */
    Message m = mesg[i-1];
    Address[] a;

    /* if there is an adress on to */
   
     if ((a=m.getRecipients(Message.RecipientType.CC)) != null)
     {
      
      return (adrToStr(a));
     }
     return null;     
  } // end get cc 


  /***********************
   * getBcc* 
   **********************/
  public String getBcc (int i) throws MessagingException
  {

  /**
     Returns the Bcc: field of a specified message i, in a string fromat using
     the utility fanctions adrsToStr 
  */
    Message m = mesg[i-1];
    Address[] a;

    /* if there is an adress on to */
   
     if ((a=m.getRecipients(Message.RecipientType.BCC)) != null)
     {
      
      return (adrToStr(a));
     }
     return null;     
  } // end get Bcc 


  /***********************
   * getSubject* 
   **********************/
  public String getSubject (int i) throws MessagingException
  {

  /**
     Returns the subject informaation of a specified message i, as a String  
  */
    Message m = mesg[i-1];
      
      return (m.getSubject());
  } // end get subject 


  /***********************
   * isAnswerd* 
   **********************/
  public boolean  isAnswered(int message) throws MessagingException
  {

  /**
     Returns the message flags of a specified message i, as a String 
     flags indicate if a message has benn read answered, marked for 
     deletion, is a draft or is been read. 
  */
    Message m = mesg[message-1]; // ofset for message is n-1
      
                                 // message array
   Flags flags=m.getFlags();
   Flags.Flag[]  sf= flags.getSystemFlags(); // get the system flags
   // go thru the flags to check the one we want 
    for (int i =0 ; i< sf.length ; i++)
    {
      
      Flags.Flag    f =sf[i];
      if (f==Flags.Flag.ANSWERED) /*if we found the flag we want */
      {
          return (true);
      }
   }// end for 
   
   // else if the flag is not set  

     return (false);    
   }// end isAnswered

/* methods for checking message flages 

  
  /***********************
   * is recent* 
   **********************/
   public boolean isRecent(int message) throws MessagingException
   {
   /** 
   This method scans thru the flags in a message and reports if a 
   message is Recent (new) message 
   */
    Message m = mesg[message-1]; // the actual message ofset ison the  n-1
                                 // message array
   Flags flags=m.getFlags();
   Flags.Flag[]  sf= flags.getSystemFlags(); // get the system flags
   // go thru the flags to check the one we want 
    for (int i =0 ; i< sf.length ; i++)
    {
      
      Flags.Flag    f =sf[i];
      if (f==Flags.Flag.RECENT) /*ifwe found the flag we want */
      {
          return (true);
      }
   }// end for 
   
   // else if the flag is not set  

     return (false);    
   }// end isRecent


  /***********************
   * is seen* 
   **********************/


   public boolean isSeen(int message) throws MessagingException
   {
   /** 
   This method scans thru the flags in a message and reports if a 
   message has been read before (it's not a new message) 
   */
    Message m = mesg[message-1]; // the actual message ofset ison the  n-1
                                 // message array
   Flags flags=m.getFlags();
   Flags.Flag[]  sf= flags.getSystemFlags(); // get the system flags
   // go thru the flags to check the one we want 
    for (int i =0 ; i< sf.length ; i++)
    {
      
      Flags.Flag    f =sf[i];
      if (f==Flags.Flag.SEEN) /*ifwe found the flag we want */
      {
          return (true);
      }
   }// end for 
   // else if the flag is not set  

     return (false);    
   }// end isSeen

  /***********************
   * isFlaged* 
   **********************/

   public boolean isFlagged(int message) throws MessagingException
   {
   /** 
   This method scans thru the flags in a message and reports if the 
   the message as flags set  
   
   */
    Message m = mesg[message-1]; // the actual message ofset ison the  n-1
                                 // message array
   Flags flags=m.getFlags();
   Flags.Flag[]  sf= flags.getSystemFlags(); // get the system flags
   // go thru the flags to check the one we want 
    for (int i =0 ; i< sf.length ; i++)
    {
      
      Flags.Flag    f =sf[i];
      if (f==Flags.Flag.FLAGGED) /*ifwe found the flag we want */
      {
          return (true);
      }
   }// end for 
   // else if the flag is not set  

     return (false);    
   }// end isFlagged


  /***********************
   * isFlaged* 
   **********************/
   public boolean isDraft(int message) throws MessagingException
   {
   /** 
   This method scans thru the flags in a message and reports if a 
   message is marked as a draft message
   */
    Message m = mesg[message-1]; // the actual message ofset ison the  n-1
                                 // message array
   Flags flags=m.getFlags();
   Flags.Flag[]  sf= flags.getSystemFlags(); // get the system flags
   // go thru the flags to check the one we want 
    for (int i =0 ; i< sf.length ; i++)
    {
      
      Flags.Flag    f =sf[i];
      if (f==Flags.Flag.DRAFT) /*if we found the flag we want */
      {
          return (true);
      }
   }// end for 
   // else if the flag is not set  

     return (false);    
   }// end isDraft


  /***********************
   * isDeleted* 
   **********************/
   public boolean isDeleted (int message) throws MessagingException
   {
   /** 
   This method scans thru the flags in a message and reports if a 
   message is marked for deletion 
   */
    Message m = mesg[message-1]; // the actual message ofset ison the  n-1
                                 // message array
   Flags flags=m.getFlags();
   Flags.Flag[]  sf= flags.getSystemFlags(); // get the system flags
   // go thru the flags to check the one we want 
    for (int i =0 ; i< sf.length ; i++)
    {
      
      Flags.Flag    f =sf[i];
      if (f==Flags.Flag.DELETED) /*if we found the flag we want */
      {
          return (true);
      }
   }// end for 
   // else if the flag is not set  

     return (false);    
   }// end isDeleted


  /***********************
   * isUser* 
   **********************/
   public boolean isUser(int message) throws MessagingException
   {
   /** 
   This method scans thru the flags in a message and reports if a 
   message is user defind flag  
   */
    Message m = mesg[message-1]; // the actual message ofset ison the  n-1
                                 // message array
   Flags flags=m.getFlags();
   Flags.Flag[]  sf= flags.getSystemFlags(); // get the system flags
   // go thru the flags to check the one we want 
    for (int i =0 ; i< sf.length ; i++)
    {
      
      Flags.Flag    f =sf[i];
      if (f==Flags.Flag.USER) /*if we found the flag we want */
      {
          return (true);
      }
   }// end for 
   // else if the flag is not set  

     return (false);    
   }// end isDeleted


  /***********************
   * getDate* 
   **********************/
   public Date getDate(int message) throws MessagingException
   {
   /** 
   This method scans thru the flags in a message and reports if a 
   message is user defind flag  
   */
    Message m = mesg[message-1]; // the actual message in the array has ofset 
                                 // n-1 
                               
    Date sendDate=m.getSentDate();   // get the date 

     return (sendDate);    
   }//getDate 


/***********************
 * getFolders
 ***********************/
  public Folder[]  getFolders() throws MessagingException
  {
    /**
      returns of Folder objects.  
      the pop3 provider supoorts nly one folder "INBOX" 
      if we are using imap we have to look what theire names are 
      and if there are any subfolders 
     Bag Report: i atempted to store the names oth the folders in an array 
                 of Strings but there wasno muvh so i had toreutn the Folders 
    /*
    
  */
    Folder [] sub = store.getDefaultFolder().list();
   
    return (sub); 
  }// end get folders


  /**************************
   * prepMsgGet()
   *************************/
   
   public void prepMsgGet () throws MessagingException
   {
   
/* -  identifyes what folde system we can use  
 *  - prepera a fech prfile  
 *  - gets the messages and theireatributes 
 *     in a message array ready to access 

 *     we check if the pop  server supports iud message retreval
 *     from README.txt pop3 provider by sun microsystems
 */ 
     if (folder instanceof com.sun.mail.pop3.POP3Folder)
        {
          /* this is a pop with  uid supporta
           *  set a uid folder from the defaukt folder
           */
          com.sun.mail.pop3.POP3Folder uidFolder=
          (com.sun.mail.pop3.POP3Folder) folder;
        }
 /* if we are on an imap server we check if this server 
  * supports uid retreval 
  * (see java mail API 1.2  examples uidmessageshow.java)
  */
    if (folder instanceof UIDFolder)
    {
      UIDFolder uidFolder= (UIDFolder) folder;
    }  
  /* set a profile,
   * a fetch profile gets some attrubutes for a range of Messages
   * the mailer that created the message the date and the like 
   */
     if (uid==-1)
        mesg=folder.getMessages(); 
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.ENVELOPE);
    fp.add(FetchProfile.Item.FLAGS);
    fp.add("x-mailer");
    folder.fetch(mesg,fp);
        
}//prepMegGet 


 public String getBody (int i ) throws MessagingException, IOException
 {
   Message m = mesg[i-1];
  if (m==null)
  {
   return null;
   }
  //else

 /* check the mimeType of the message to find out if it is plain
  * text or a multipart
  */

/* if it is a multipart body 
 */
    if (m.isMimeType  ("multipart/*"))
       {
         /* separate the text from the attachement
          * acroding to javamail api Gide
          */
           StringBuffer sb = new StringBuffer();
           Multipart multipart= (Multipart) m.getContent();
           for (i=0 ; i< multipart.getCount(); i++)
           {
             /* inspect every part to see what it is
              */

             Part p= multipart.getBodyPart(i);
             if (p.isMimeType("text/plain"))
             {
                  String s =(String)p.getContent();
                  if (s!=null)
                       sb.append(p);
             } 
             else 
             { 
                   String s=p.getFileName();
                   if (s!=null)
                   {
                    sb.append ("File:");
                    sb.append (s);
                   } // end nested if
             }//else
           }//end for  
          /* after gettog the infor returbnn the data
          */
            return (sb.toString());   
        }//endif 

/* if it is plain text rtuurn it
 */    
     return ((String)m.getContent());
  }// end get Body
//***********************/
// class ends here 
}// end class
/*Author Billy kantartzis 
 E-mail:[EMAIL PROTECTED]
 Date: 15/01/2001
 Disclaymer 
  this software is distributed as is. You may use it freelly
  for educational and evaluation purposes 
   without modifying any of the source code. 
Teamwaere mail,  teamwaere server and the TeamWare logos aere trade marks
 registered by  TeamWare/Futjitsu group.
/************************************************************************** 
*this class is a gui interface for displaying message information on jTable 
 *such as the subjwct date and sender.
 *  as son as a message is selected it.s content is displayed.
 */

import javax.swing.*;
import javax.mail.*;
import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.table.*;
public class MessageListPane extends JPanel
{
   private MailReceiver receiver ;    
   private JTable table;
   private TableModel model; 
   private final int COL= 3;
   private Store store;
   private String user,pass;
  /***********************
   * Defalult constractor*
   ***********************/


   public MessageListPane (String user, String pass)
                           
   {   this.user=user;
       this.pass=pass;
       this.setupDisplay();                  // setup the GUI
   }// end constructor

   void setupDisplay() 
   {
    receiver =new MailReceiver  (user,pass);
     model = new TableModel();
     table= new JTable (model);              // get an instance of the table;
    this.add(new JScrollPane(table),"center"); 
   }// end setupDisplay

/**
 * this is a private class implementing the abstract  model 
 * The model is actually responsible for filling calculate 
 * and fill in values in the table as well as set yup it's format
 * 
 * Methods 
 * we need to suply are methods to return the row and column count as well 
 * as the values in the table cells
 */

/*************** 
  class TableModel 
 *****************/

/**
 * this is a  class implementing the abstract  model 
 * The model is actually responsible for filling calculate 
 * and fill in values in the table as well as set yup it's format
 * 
 * Methods 
 * we need to suply are methods to return the row and column count as well 
 * as the values in the table cells
 */
private class TableModel extends AbstractTableModel
{
  public int getRowCount()
  {
     /**
      * the number of messages in the store is equal to the 
      * number of rows in the table 
      */
    int rows=receiver.getMessages();
    return (rows);
  }// end row count
  
 public  int getColumnCount ()
  {
    return COL;
  }

  public Object  getValueAt(int row, int col) 
  {
   String subject, from, date;
   subject=from=date=null;
    try 
    {   int i=0;
       //for (int i =0;  i< receiver.getMessages(); i++) 
       //{
         from= receiver.getFrom(i);
         subject=receiver.getSubject(i);
         date = receiver.getDate(i).toString();
     //} // end for 
   }catch (MessagingException e0)
    {
       e0.printStackTrace();
    }// end catch

      String[] obj={from,subject,date};
      return (obj);
  }// end getValueAt
}//end Table Model  class 


/*************** 
  class ends here 
 *****************/
}// end class

Reply via email to