-
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.
-
sorry didnt know how to add code so i just copy and pasted lol.
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks