Mobile background image

  Abstract: Mobile background image 

  </ Td> </ tr> <tr> <td width="389" height="35" valign="top" class="ArticleTeitle"> 
  / / A moving background images of animation 
  Import java.awt .*; 
  Import java.applet.Applet; 
  Public class Pan extends Applet implements Runnable ( 
  Thread runner; 
  Image back and fore, workspace; 
  Graphics offscreen; 
  String text; 
  String fontName; 
  Int fontSize = 24; 
  Int x1 = 0; 
  Int x2; 

  Public void init () ( 
  CreateImage workspace = (size (). Width, size (). Height); 
  Workspace.getGraphics offscreen = (); 

  String imageBack = getParameter ( "background"); 
  If (imageBack! = Null) 
  Back = getImage (getDocumentBase (), imageBack); 

  String imageFore = getParameter ( "foreground"); 
  If (imageFore! = Null) 
  Back = getImage (getDocumentBase (), imageFore); 
  X2 = size (). Width; 
  Text = getParameter ( "text"); 
  FontName = getParameter ( "font"); 
  If (fontName == null) 
  FontName = "Arial"; 
  String param = getParameter ( "fontsize"); 
  If (param! = Null) 
  FontSize = Integer.parseInt ( "0" + param); 
  ) 

  Public void start () ( 
  If (runner == null) ( 
  Runner = new Thread (this); 
  Runner.start (); 
  ) 
  ) 

  Public void stop () ( 
  If (runner! = Null) ( 
  Runner = null; 
  ) 
  ) 

  Public void run () ( 
  Thread thisThread = Thread.currentThread (); 
  While (runner == thisThread) ( 
  Repaint (); 
  Try (Thread.sleep (200);) 
  Catch (InterruptedException e) () 
  X1 = x1-5; 
  X2 = x2-5; 
  If (x1 <= (size (). Width * (-1))) 
  X1 = size (). Width; 
  If (x2 <= (size (). Width * (-1))) 
  X2 = size (). Width; 
  ) 
  ) 

  Public void paint (Graphics g) ( 
  Offscreen.drawImage (back, x1, 0, null); 
  Offscreen.drawImage (back, x2, 0, null); 
  If (fore! = Null) 
  Offscreen.drawImage (fore, 0,0, null); 
  If (text! = Null) ( 
  Offscreen.setColor (Color.black); 
  Font f = new Font (fontName, Font.BOLD, fontSize); 
  FontMetrics fm = g.getFontMetrics (); 
  Offscreen.setFont (f); 
  Int xStart size = () .width/2-fm.stringWidth (text) / 2-100; 
  Int yStart = size (). Height / 2 + fm.getHeight () / 2; 
  Offscreen.drawString (text, xStart, yStart); 
  Offscreen.setColor (Color.white); 
  Offscreen.drawString (text, xStart-2, yStart-2); 
  ) 
  G.drawImage (workspace, 0, 0, this); 
  ) 

  Public void update (Graphics g) ( 
  Paint (g); 
  ) 
  ) 

  </ Td> <td width="295" valign="top" class="ArticleTeitle"> 
  </ Td> </ tr> <tr> <td height="25" colspan="2" valign="top" class="ArticleTeitle"> 

  ↑ Back 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags:

Releated Java Articles

Comments

Leave a Reply