Javascript  
 
  ScriptJava  
 
  Perl  
 
  PHP  
 
  ROR  
 
  ask us  
 

 

Applications
  1. Getting started
  2. Definitions
  3. First program
  4. Characters and Strings
  5. Object and methods
  6. Arrays and Circles
  7. Exceptions
  8. The main method
  9. Reading
  10. Writing file
  11. Vectors
  12. Stacks
  13. Map The Dictionary
  14. Lists
  15. Linked lists
  16. Collection
  17. Interfaces
  18. Scanner
  19. StringTokenizer
  20. Generics
  21. JDBC
  22. DataBase Queries
  23. JSP, The main step

Graphics

Applets
  1. Regards
  2. One Picture
  3. Calculator
  4. Random pictures
  5. Bouncing picture

Swings
  1. Buttons listeners
  2. TextFields
  3. Swing Example

JavaBeans
  1. The first step
  2. Example

Search a word:
   



© The scientific sentence. 2010

Bouncing Ball
Bouncing picture applet


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

public class SwingPictures extends Applet implements Runnable
{

private static final long serialVersionUID = 1L;
//int width, height;
Thread runner;
private Image Buffer;
private Graphics gBuffer;
int x, x1, x2=100;
Image pic1;
// Image pic2, pic3, pic4, pic5;

public void init()
{
pic1=getImage(getCodeBase(),"Images/Jupiter.jpg");
//pic2=getImage(getCodeBase(),"Images/Earth.jpg");
//pic3=getImage(getCodeBase(),"Images/Saturn.jpg");




//create graphics buffer, the size of the applet
Buffer=createImage(getSize().width,getSize().height);
gBuffer=Buffer.getGraphics();
}
//moveRight is boolean variable used  to keep 
//track of the direction.
boolean moveRight=true;

public void start()
{
if (runner == null)
{
runner = new Thread (this);
runner.start();
}
}

public void stop()
{
if (runner != null)
{
//runner.stop();
runner = null;
}
}

public void run()
{
while(true)
{
try {runner.sleep(10);}
//Thread sleeps for 10 milliseconds.
catch (Exception e) { }

gBuffer.setColor(Color.black);
//paint background black
gBuffer.fillRect(0,0,getSize().width,getSize().height);

if(moveRight==true)
{
if(x2<getSize().width-150)
x2+=2;
else
moveRight=false;
}

//if flag "moveRight" is false, the pictures move left
//until they touche left border, then switch direction
if(moveRight==false)
{
if(x2>0)
x2-=2;
else
moveRight=true;
}

gBuffer.drawImage(pic1,x2,50,150,130,this);
// gBuffer.drawImage(pic2,x2-200,100,180,130,this);
// gBuffer.drawImage(pic3,x2-400,250,180,130,this);

repaint();
}
}

//is needed to avoid erasing the background by Java
public void update(Graphics g)
{
paint(g);
}

public void paint(Graphics g)
{
g.drawImage (Buffer,0,0, this);
}
}

/*


Font


*/

  
Google
Web
ScientificSentence
 




chimie labs
|
scientific sentence
|
java
|
php
|
green cat
|
contact
|


© Scientificsentence 2009. All rights reserved.