Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 612
  • Last Modified:

Adding an image into the japplet ...

Hi,
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
akshay
0
akshay_n_s
Asked:
akshay_n_s
1 Solution
 
Andrew BeersTechnology LeadCommented:
Here ya go!
http://www.rgagnon.com/javadetails/java-0233.html

OR Contents here:
****************************
Program
****************************
import java.applet.Applet;
import java.net.*;

//  TILE BACKGROUND
//     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);
      tracker.waitForAll();
      }
   catch (Exception e) {
      e.printStackTrace();
      }
   setLayout(new FlowLayout());
   add(new Button("Ok"));
   add(new TextField(10));
        }

  public void update( Graphics g) {
   paint(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);
            x=x+bgImage.getWidth(null);
            }
         y=y+bgImage.getHeight(null);
         }
      }
   else {
      g.clearRect(0, 0, size().width, size().height);
      }
    }
  }


*************************
HTML APPLET CODE
*************************
  <HTML>
  <TABLE><TR><TD>
  <APPLET CODE=tile.class WIDTH=150 HEIGHT=150>
    <PARAM NAME="bgImage"  VALUE="images/jht.gif">
  </APPLET>
 
</HMTL>
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now