Adding an image into the japplet ...

Posted on 2005-04-06
Last Modified: 2012-06-27
I am working on one game project. I am using japplet for that. The problem that I have faced is that I can't add an image as a background within japplet. Applet should also contain panels, labels, buttons etc... So, plz tell me is there any method to add all this (background, labels, buttons) on a single japplet. Plz give me some sample code...
Thanking you
Question by:akshay_n_s
    1 Comment
    LVL 10

    Accepted Solution

    Here ya go!

    OR Contents here:
    import java.applet.Applet;

    //     in the HTML use :
    //       PARAM NAME="bgImage" VALUE="images/myImage.jpg"
    //     in the APPLET tag

    public class tile extends Applet {
      Image bgImage = null;

      public void init() {
       try {
          MediaTracker tracker = new MediaTracker (this);
          bgImage = getImage
            (new URL(getCodeBase(), getParameter("bgImage")));
          tracker.addImage (bgImage, 0);
       catch (Exception e) {
       setLayout(new FlowLayout());
       add(new Button("Ok"));
       add(new TextField(10));

      public void update( Graphics g) {

      public void paint(Graphics g) {
       if(bgImage != null) {
          int x = 0, y = 0;
          while(y < size().height) {
             x = 0;
             while(x< size().width) {
                g.drawImage(bgImage, x, y, this);
       else {
          g.clearRect(0, 0, size().width, size().height);

      <APPLET CODE=tile.class WIDTH=150 HEIGHT=150>
        <PARAM NAME="bgImage"  VALUE="images/jht.gif">

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
    As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now