blah45
- 65
- 0
I just used a for loop and added delay that way and it worked =D
Cathal Cronin said:Whe I put that in I get an erroe saying " unreported exception java.lang.InterruptedException ; must be caught or declared to be thrown
public static void sleep(long millis)
throws InterruptedException
try {
// Bunch of code
Thread.sleep(250);
// etc ...
} catch (InterruptedException e) {
// Handle the exception
e.printStackTrace();
}
public void tester() throws InterruptedException
{
Thread.sleep(250);
// ... etc ...
}
You're welcome. I know that both Grep and I enjoy being able to help out.Cathal Cronin said:I'll do some other testing and let you know Thanks for all the help, thanks so much, I really do appreciate it.
public class messageDriver
{
public static void main(String args[])
{
MessageList Inbox = new MessageList() ;
int i = 0;
Message msg1 = new Message("123456","Hi") ;
for(i = 0 ; i < 10000000 ; i++);
Message msg2 = new Message("123456","Hey, how are you") ;
for(i = 0 ; i < 10000000 ; i++);
Message msg3 = new Message("123456","grand, you?") ;
for(i = 0 ; i < 10000000 ; i++);
Message msg4 = new Message("123456","I'm okay,gotta go now, talk later!") ;
for(i = 0 ; i < 10000000 ; i++);
Message msg5 = new Message("123456","ok bye") ;
for(i = 0 ; i < 10000000 ; i++);
Message msg6 = new Message("123456","bye bye") ;
for(i = 0 ; i < 10000000 ; i++);
Inbox.addMsg(msg5) ;
Inbox.addMsg(msg1) ;
Inbox.addMsg(msg3) ;
Inbox.addMsg(msg6) ;
Inbox.addMsg(msg2) ;
Inbox.addMsg(msg4) ;
Inbox.display() ;
}
}
Cathal Cronin said:I'm back again, it works but just wondering do I have to do the Thread.sleep(n) thing or is this(i.e what I have at the moment) okay...
Cathal Cronin said:I was looking up the API for the thread but I don't exactly know how to use it in the driver, does it really matter apart from being "cheesy"?
public static void main(String args[])
{
MessageList inbox = new MessageList() ;
int numMessages = 6;
int testOrder[] = {4, 0, 2, 5, 1, 3};
Message messages[] = new Message[numMessages];
// Create the messages, making sure system clock changes before next message
for (int i = 0; i < numMessages; i++)
{
messages[i] = new Message(Integer.toString(i), "Message " + i);
long messageTime = messages[i].getTimePc();
while (System.nanoTime() == messageTime);
}
// Add messages to list in the order specified by the testOrder[] array
for (int i = 0; i < numMessages; i++)
{
inbox.add(messages[testOrder[i]]);
}
inbox.display();
}