Home | » | Java | » | Advance Java | » | » | MultiThreading | » | Writing Applets With Threads |
---|
You can create threads that can be implemented using applet. The following program code shows how to execute a moving banner based on applet using threads. The banner moves form right to left in a horizontal manner. Consider the code:
In the above example, the ThreadApplet class is created that extends the applet and implements the runnable interface to execute threads in an applet. In the above example, you create an object of the thread class with a Thread1. The init method is used to initialise the foreground colour and background colour of the applet. The applet start method is used to create and execute the first thread. The second thread method is required to repaint the applet screen each time the message string is scrolled horizontally from right to left. The stop method is used to stop the execution of the thread.
The above code will be stored in the file called ThreadApplet.java, which on compilation will crate a class file called ThreadApplet.class. Now compile this file using below commands in the DOS mode:
C:\>jdk1.4\bin>appletviewer ThreadApplet.java
|
||
Download Complete Program |
MultiThreading
Thread Life Cycle | Main Thread |
Creating A Thread | Thread Priority |
Extending The Thread Class | Writing Applets With Threads |
No comments:
Post a Comment