adding an image to an applet


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: adding an image to an applet

  1. #1
    Join Date
    Feb 2005
    Posts
    6

    adding an image to an applet

    I am sitting in class writing an applet code which i finished was boring. Anyways I was wanting to add an image to my applet to you know spice things up. Any help on how to import an image to the applet would be greatly appreciated. Oh and this is my code.

    /*
    A simple banner applet
    This applet creates a thread that scrolls
    the message contained in msg right to left
    across the applet's window.
    */
    import java.awt.*;
    import java.applet.*;
    /*
    <applet code="Banner" width=200 height=50>
    </applet>
    */
    /*
    <param name=image value="C:\\homestar.jpg">
    */

    public class Banner extends Applet implements Runnable{
    String msg = " Homestar Runner ";
    Thread t;
    boolean stopFlag;

    //Initialize t to null.
    public void init(){
    t = null;
    }

    //Start thread
    public void start(){
    t = new Thread(this);
    stopFlag = false;
    t.start();
    }

    //Entry point for the thread that runs the banner.
    public void run(){
    char ch;

    //Display banner
    for( ; ; ){
    try{
    repaint();
    Thread.sleep(150);
    ch = msg.charAt(0);
    msg = msg.substring(1, msg.length());
    msg += ch;
    if(stopFlag)
    break;
    }catch(InterruptedException exc){}
    }
    }

    //Pause the banner.
    public void stop(){
    stopFlag = true;
    t = null;
    }

    //Display the banner.
    public void paint(Graphics g){
    g.drawString(msg, 50, 30);
    getParameter("image");

    }
    }
    Last edited by kronic; 04-05-2005 at 02:57 PM.

  2. #2
    Join Date
    Feb 2005
    Posts
    6
    sorry didnt know how to add code so i just copy and pasted lol.

  3. #3
    Join Date
    Sep 2004
    Posts
    223
    A kram a day keeps the doctor......guessing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center