Share on Google+Share on Google+

2 Answer(s)      8 years ago
Posted in : Java Beginners


View Answers

June 3, 2008 at 6:43 PM

Hi manju

import java.awt.*;
import java.applet.*;

public class AppletThread extends Applet {
private Image[] images;
private String[] text;

private Label captions;
private volatile int curFrame;
private Thread timerThread;
private volatile boolean noStopRequested;
private boolean paused;
private final Object pauseLock = new Object();

private void printThreadName(String prefix) {
String name = Thread.currentThread().getName();
System.out.println(prefix + name);

public void init() {
images = new Image[2];
text = new String[2];
captions = new Label();
setLayout(new BorderLayout());
add(BorderLayout.SOUTH, captions);

Label name = new Label("Display the image by Claude Monet");
add(BorderLayout.EAST, name);

URL image = null;
try {
image = new URL("/home/vinod/amarexamples:9090/" + "amarexamples/Threads/applet/");
catch ( ex) {
System.out.println("URL not found");

images[0] = getImage(image, "rose-one.jpg");
images[1] = getImage(image, "rose.gif");
text[0] = "Display cat image";
text[1] = "Display rose image in a west";
printThreadName("init is ");

private void startThread() {
paused = true;
noStopRequested = true;
Runnable r = new Runnable() {
public void run() {
timerThread = new Thread(r, "Timer");
printThreadName("startThread is ");

private void stopThread() {
noStopRequested = false;
printThreadName("stopThread is ");
private void runWork() { // note that this is private
printThreadName("run is ");
curFrame = 0;

try {
curFrame = (curFrame + 1) % images.length;
} catch ( InterruptedException x ) {
System.out.println("interrupt and return from run");

private void setPaused(boolean newPauseState) {
synchronized (pauseLock) {
if (paused != newPauseState) {
paused = newPauseState;

private void waitWhilePaused() throws InterruptedException {
synchronized (pauseLock) {
while (paused) {

public void paint(Graphics g) {
printThreadName("paint is ");

public void update(Graphics g) {
g.drawImage(images[curFrame], 0, 0, this);
printThreadName("update is ");

public void start(){
printThreadName("start is ");

public void stop() {
printThreadName("stop is ");

public void destroy() {

for (int i = 0; i < images.length; i++) {
images[i] = null;
text[i] = null;

images = null;
text = null;
printThreadName("destroy is ");

June 3, 2008 at 6:45 PM

<div align = "center">
<APPLET CODE = "AppletThread.class" WIDTH = "500" HEIGHT = "400"></APPLET>


Read for more information.



Related Tutorials/Questions & Answers:
threads  what are threads? what is the use in progarmming
threads and events
threads and events  Can you explain threads and events in java for me. Thank you.   Java Event Handling Java Thread Examples
threads in java
threads in java  how to read a file in java , split it and write into two different files using threads such that thread is running twice
Java threads
Java threads  What are the two basic ways in which classes that can be run as threads may be defined
disadvantage of threads
is the disadvantage of threads?   hello, The Main disadvantage of in threads... disadvantage of Threads. Let?s discuss the disadvantages of threads. The global..., the other threads using the same memory location will be killed automatically
Sync Threads
Sync Threads  "If two threads wants to execute a synchronized method in a class, and both threads are using the same instance of the class to invoke the method then only one thread can execute the method at a time." This is what
threads in java
threads in java  iam getting that the local variable is never read in eclipse in main classas:: class Synex4{ public static void main(String args[]){ Test1 ob1=new Test1(); //local variable never read
Threads in realtime projects
Threads in realtime projects  Explain where we use threads in realtime projects with example
Synchronized Threads
Synchronized Threads       In Java, the threads are executed independently to each other. These types of threads are called as asynchronous threads. But there are two problems may
Coding for life cycle in threads
Coding for life cycle in threads  program for life cycle in threads
Explain about threads:how to start program in threads?
Explain about threads:how to start program in threads?  import...; Learn Threads   Thread is a path of execution of a program... more than one thread. Every program has at least one thread. Threads are used
Examples on threads and mulithreading.....
Examples on threads and mulithreading.....  Is any good examples on threads and Mulithreading...   Hi Friend, Please visit the following link: Thread Tutorial Thanks
java threads - Java Beginners
java threads  What are the two basic ways in which classes that can be run as threads may be defined
Synchronized Threads
Synchronized Threads       In Java, the threads are executed independently to each other. These types of threads are called as asynchronous threads. But there are two problems may
Synchronized Threads
Synchronized Threads       In Java, the threads are executed independently to each other. These types of threads are called as asynchronous threads. But there are two problems may
Java Threads - Java Beginners
allows the threads to wait for resources to become available and also notify the thread that makes resource available to notify other threads
threads in java - Java Beginners
threads in java  what is the difference between preemptive scheduling and time slicing?   hi friend, In Preemptive scheduling, a thread... or the priority of one of the waiting threads is increased. While in Time Slicing
Daemon Threads
Daemon Threads       In Java, any thread can be a Daemon thread. Daemon threads are like a service providers for other threads or objects running in the same process as the daemon
threads & autorelease pool
threads & autorelease pool  How to set autorelease pool for NSThread method in Objective C?   [NSThread detachNewThreadSelector:@selector(yourMethod) toTarget:self withObject:nil]; - (void)yourMethod
Threads,Servlets - Java Beginners
Threads,Servlets  1)Is two Start mathods exist in one Thread Class? like create an object ThreadClass a= new ThreadClass; a.start(); a.start(); 2)How can u refresh a Servlet when new record is added to D.Base
multi threads - Java Beginners
using three threads. I want to declare variables which will be available to all the threads to access. Is there a way to declare the variables as global variables which will be available to all the threads. If so please send me the code
threads - Java Interview Questions
that will work even if many Threads are executing it simultaneously. Writing it is a black... interactions between Threads. You have to do it by logic. In a computer, something
THE COMPLETE CONEPTS OF INTERFACES,EXCEPTIONS,THREADS   Interface...: Exception Handling in Java   Threads A thread is a lightweight process which exist within a program and executed to perform a special task. Several threads
Execution of Multiple Threads in Java
Execution of Multiple Threads in Java  Can anyone tell me how multiple threads get executed in java??I mean to say that after having called the start method,the run is also invoked, right??Now in my main method if I want
Threads - Java Interview Questions
. If you want to create threads, please visit the following link: http
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code


Advertisement null