applet images sleeping programme

applet images sleeping programme

View Answers

August 1, 2008 at 11:33 AM

Hi friend,


import java.util.*;
import java.awt.*;
import java.applet.Applet;
import java.util.Random;

public class AppletSleep extends Applet implements Runnable {
Thread thread = null;
final static int width = 400;
final static int height = 300;
Image image;
Graphics graphics;
// bouncing lines member variables
int[] x1;
int[] y1;
int[] x2;
int[] y2;
int dx1 = 2 + (int)( 3 * Math.random());
int dy1 = 2 + (int)( 3 * Math.random());
int dx2 = 2 + (int)( 3 * Math.random());
int dy2 = 2 + (int)( 3 * Math.random());
static int first = 0;
final static int LINES = 50;
public void init() {

// create arrays to hold the line coordinates
x1 = new int[LINES];
y1 = new int[LINES];
x2 = new int[LINES];
y2 = new int[LINES];

// initialise the first line
x1[0] = (int)( WIDTH * Math.random() );
y1[0] = (int)( HEIGHT * Math.random() );
x2[0] = (int)( WIDTH * Math.random() );
y2[0] = (int)( HEIGHT * Math.random() );

// initialise all the other lines
for ( int i = 1; i < LINES; i++ ) {
x1[i] = x1[0];
y1[i] = y1[0];
x2[i] = x2[0];
y2[i] = y2[0];
}
image = createImage(width, height);
graphics = image.getGraphics();
}
public void start(){

// user visits the page, create a new thread
if(thread == null){
thread = new Thread( this );
thread.start();
}
}
public void stop() {
// user leaves the page, stop the thread
if(thread != null && thread.isAlive())
thread.stop();
thread = null;
}
public void run() {
while (thread != null) {
repaint();
try {
Thread.sleep(20);
}
catch(InterruptedException e ){
System.out.println(e);
}
}
}
public void paint(Graphics g) {
update(g);
}

public void update(Graphics g) {
// clear the background to white
graphics.setColor( Color.white );
graphics.fillRect( 0, 0, width, height );

// draw the lines
graphics.setColor( Color.red );
int line = first;
for ( int i = 0; i < LINES; i++ ) {
graphics.drawLine( x1[line], y1[line], x2[line], y2[line] );
line++;
if ( line == LINES ) line = 0;
}
line = first;
first--;
if ( first < 0 ) first = LINES - 1;
x1[first] = x1[line];
y1[first] = y1[line];
x2[first] = x2[line];
y2[first] = y2[line];

// copy buffer to screen
g.drawImage( image, 0, 0, this );
}
}

August 1, 2008 at 11:35 AM

AppletSleep.html

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



--------------------------------------------------------

Read for more information.

http://www.roseindia.net/java/example/java/applet/


Thanks.









Related Tutorials/Questions & Answers:
applet images sleeping programme - Applet
applet images sleeping programme  Dear Sir,         I shall be much tankful to you, if u can kindly give me the programe for    In a Applet how... java.applet.Applet; import java.util.Random; public class AppletSleep extends Applet
Problem with display of images in applets - Applet
Problem with display of images in applets  Hi all, When I run... java.applet.*; public class image extends Applet { Image img; public... java.awt.*; public class ImageExample extends Applet{ Image
Advertisements
programme
programme  Using an ATM, customer can access their bank accounts in order to credit/debit cash and check their account balances.You have to write c programme to implement a simple ATM for 15 customers. Initially you have to store
how to drag top most images which is draw on applet.
how to drag top most images which is draw on applet.  Please help me, I have draw 83 images one by one from g.drawImages(,,,,); now I want to drag last image from 83 images and drop it suitable place, Now please help me , how can
java programme
java programme   1.....programme for reading 10 values for 10 variables using scanner class 2....declares all types of primitive data inside main method
Applet
Applet  Write an applet to display a string in an applet. String should be passed as a parameter to an applet
applet
applet  What is the immediate superclass of the Applet class
Applet
Applet  how to run an applet on a web browser
applet
applet  Explain different stages in the lifecycle of an applet with figure.   Stages of Applet: Life cycle of an Applet: init(): This method is called to initialized an applet start(): This method is called after
Applet
Applet  Give the class hierarchy of an Applet class
Applet
Applet  Write a ava applet that sets blue color foreground and yellow color background at the start of an applet
Applet
Applet  Explain the start() and stop() methods of applet life cycle.   Start and Start method of Applet Life Cycle Start () method: The start method of an applet is called after the initialization method init
Applet
Applet  Write a short note on applet life cycle
Applet
Applet  I have a java applet that has a button. On clicking the button it should disappear and another applet should appear. How to write this code???? Also in login applet after successful login it should display admin applet
java programme
java programme   i have to write a java programe that calculates the average of 10 students in Test 1 ,Test 2 and Test 3....Values of the marks in all the test for a student should be hardcore.Ialso have to tell the maixmum
Applet
Applet  Draw the class hierarchy of an Applet class. Also explain how to set background and forground colors in java
applet
applet  what is applet in java   An applet is a small program that can be sent along with a Web page to a user. Java applets can perform... the following link: Applet Tutorials
Applet
Applet  Write a Java applet that drwas a line between 2 points. The co-ordinates of 2 points should be passed as parametrs from html file. The color of the line should be red
applet
applet  applet to open new tab not working.here's my code import java.applet.*; import java.awt.*; import java.net.*; import java.awt.event.*; public class NewURL extends Applet implements ActionListener{ public void init
menu driven programme
menu driven programme   calculate the area of circle, square, rectangle in menu driven programme in java
applet - Applet
.  Hi Friend, Try the following code: 1)Create an applet... extends Applet{ public void paint(Graphics g){ g.drawString("Welcome in Java Applet.",40,20); } } 2) Call this applet with html code
Applet - Applet
Applet  what is the concept of applet? what is different between the applet concept and HTML? what is mean by swing?  Hi friend, Applet Applet is java program that can be embedded into HTML pages. Java applets
applet - Applet
*; import java.awt.*; public class CreateTextBox extends Applet implements.../applet/ Thanks
hotel management programme in c language?
hotel management programme in c language?  hotel management programme in c language
Applet - Applet
Applet   Namaste, I want to create a Menu, the menu name is "Display... java.awt.event.*; public class menu2frame extends Applet implements WindowListener...------------------------"); g.drawString("Demo of Java Applet Window Event Program"); g.drawString("Java
programme - Java Beginners
programme  java programme to implement stack operation?use stack to check whether a given string is polidrome or not  Hi Friend, Please visit the following link to get the stack implementation: http
data and analytics graduate programme
data and analytics graduate programme  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: data and analytics graduate programme Try to provide me good examples
Images in java
Images in java  how to handle images in java
compiling programme IJVM
compiling programme IJVM  I TRY AND COMPILE THE PROGRAMME BELOW BUT HAS ERROR APPEAR ALL THE TIME,,CAN ANYONE CORRECT THE CODE AND WRITE UP THE NEXT METHOD FOR POWER IN THE PROGRAME AS WELL...URGENT // Program to read two single
applet problem - Applet
applet problem  How can I create a file in client side by a java applet . Surely it will need a signed applet .But how can a signed applet create a file in the client side
Applet codebase
Applet codebase  What is codebase in applet
embedding class in an applet - Applet
embedding class in an applet  I have an applet that has a set... java.awt.event.*; public class tesURL extends Applet implements ActionListener... a remote controller). I have the applet code for the remote controller
unable to see the output of applet. - Applet
unable to see the output of applet.  Sir, I was going through the following tutorial http://www.roseindia.net/java/example/java/applet...://www.roseindia.net/java/example/java/applet/FirstApplet.html but the problem
Servlet and Applet - Applet
Invoke and run an Applet from Servlet  How can i invoke and run an applet from servlet. Can anyone provide me the sample code
java - Applet
java  what is applet
creating hyperlinks in applet - Applet
creating hyperlinks in applet  Dear sir, how can i move from one applet to another applet and how can i use previous applet input data in anotherapplet(just like session tracking) thanks
applet program code - Applet
applet program code  hello sir, i did't get the code for below problem... please help me... 1.An applet program to draw a line graph for y=2x+5.[for suitable values of x & y
Applet JSP communication - Applet
Applet JSP communication  Hi.. I've an application where i need to get the data from the applet to JSP... How can i do this..?? can anyone explain with a sample code
applet running but no display - Applet
applet running but no display  Hai, Thanks for the post. I have... from a client, the page appears with a blank applet part (just whitescreen..., it is showing that the "Applet as1 started". Please help me to solve this issue
applet Question
applet Question  Write a java applet to display a circle in a rectangle
applet question
applet question  Write a java applet to display a rectangle inside a circle
applet question
applet question  Write a java applet to display atriangle inside a circle
What is Applet? - Applet
What is Applet?  What is Applet?  Hi,Here is a little information about Applet.An applet is a little application. Prior to the World Wide... programming language, an applet is a small program that can be sent along with a Web
JAVA programme - Java Interview Questions
JAVA programme  Perpare a class "package_example" following the basic functionality of "string" type in JAVA.Use of dynamic character arrays for such class is encouraged.Following is expected from the programme: a.Use of 3
loading Java Applet - Applet
loading Java Applet  Hi, I use the archive tag to download my applet into the Browser It takes too long to load. Can I do it in several steps... control the loading within the applet? thanks
java applet - Applet
java applet  wants to creat address bar on my java applet.  Hi Applet don't provide a facility to create a address bar directly. You just create a text box. In this text box if you enter any http address
Applet query - Applet
Applet query  i want to knw d complete detail of why does applet... calls the applet methods at different points depending on the stage it reached... link: http://www.roseindia.net/java/example/java/applet/ Thanks
Applet database access - Applet
Applet database access  HI... I'm having an applet where we should display the database values in the applet... It works fine in the local system... but when its in the server, we r getting null values in the local system.. I
how to run applet - Applet
in applet program. this is executed successfully with appletviewer command >...://www.roseindia.net/java/example/java/applet/ http://www.roseindia.net/java/example/java/applet/FirstApplet.shtml Hope that it will be helpful for you.Even
applet security error - Applet
applet security error  HI, Thanks for your reply. In the sample plugin code, the URL(nspluginurl) you have specified is for netscape navigator. ------------ ----------- Can you please tell me the same for IE url

Ads