Hi all,
I have a simple application that check the INBOX folder and if there are some e-mails that aren't seen I save them in a table on my database.
I would optimize this code with a listener and I sow the monitor.java demo.
Now my application have 3 major classes:
main.java;
downloader.java;
and store.java.
I think that I I can ignore the first class (because it containes only the methods' calls).
The downloader contains the method that check the INBOX folder and select some information for the unread messages.
The store class receives the informations selected on downloader and store them on db.
This application works well so the problem isn't on other parts.
Well, if it is all clear, sorry for my not perfect english, now I will try to explain what I tried and you will tell my where are my errors.
On monitor.java I find these rows:
....
folder.addMessageCountListener(new MessageCountAdapter() {
public void messagesAdded(MessageCountEvent ev) {
Message[] msgs = ev.getMessages();
....
i never use a inner class so the first trial failed because I cant use any variable create in a inner class and it is impossible modify a variable create before the inner class.
When I understood these things I tried to implement the MessageCountListener class on downloader class and my code was this:
public class Downloader implements MessageCountListener{
Message[] messageList = null;
...
folder.addMessageCountListener(this);
Message[] message = messageList;
...
public void messagesAdded(MessageCountEvent ev) {
messageList = ev.getMessages();
}
public void messagesRemoved(MessageCountEvent ev) {
messageList = ev.getMessages();
}
}
the last thing, for this trial, is that the main's class containes a loop like: for( ; ; ) (another thing that I never used before) that contains all methods' calls of this application and end with a Thread.sleep(60000).
Now, if I understand well, the problem in this trial is that all times that I recall the downloader class it reset the listener so it is all times empty right?
The last trial that I tried is that I extract the code that I written before and insert it directly on the main class but it doesn't work because I can't recall this class because the main class must be declared static!
Can you hel me?.
Thank you in advance for your help.