Solved

Drawing a background image on an applet

Posted on 1997-05-15
1
360 Views
Last Modified: 2008-03-10
I have an applet that just has a few textfields and two buttons on it.  The html page that this applet runs on has
a background image called altgry02.jpg.  How can I draw this background image on the applet also so that the applet appears to blend in with the html page.  This is the code for my applet:

/*
    A basic extension of the java.applet.Applet class
 */

import java.awt.*;
import java.applet.*;

public class TestApplet extends Applet {

      public void init() {
            super.init();

            // Take out this line if you don't use symantec.itools.net.RelativeURL
        //symantec.itools.lang.Context.setDocumentBase(getDocumentBase());

            //{{INIT_CONTROLS
            setLayout(null);
            addNotify();
            resize(350,229);
            textField1 = new java.awt.TextField();
            textField1.reshape(96,61,150,28);
            add(textField1);
            textField2 = new java.awt.TextField();
            textField2.reshape(97,101,150,28);
            add(textField2);
            button1 = new java.awt.Button("button");
            button1.reshape(96,146,60,23);
            add(button1);
            button2 = new java.awt.Button("button");
            button2.reshape(177,146,59,23);
            add(button2);
            label1 = new java.awt.Label("This is my applet");
            label1.reshape(41,21,262,25);
            add(label1);
            //}}
      }

      public boolean handleEvent(Event event) {
            return super.handleEvent(event);
      }

      //{{DECLARE_CONTROLS
      java.awt.TextField textField1;
      java.awt.TextField textField2;
      java.awt.Button button1;
      java.awt.Button button2;
      java.awt.Label label1;
      //}}
}

What do I need to add to get the background image altgry02.jpg to be drawn on this applet and then have
the components on the applet drawn over this image?
Thanks in advance.
0
Comment
Question by:Yoda
1 Comment
 

Accepted Solution

by:
Ted Hopp earned 50 total points
Comment Utility
You can draw a background for your applet by writing a paint() method for the applet that draws the image. (Retrieve the image using the applet's getImage(URL) routine.)

Unfortunately, there is no way to ensure that the applet's background image lines up seamlessly with the background for the page. The problem is that browsers do not start wallpapering the background for a page at the top left pixel! That is, the background image is shifted some number of pixels horizontally, vertically, or both as it is painted. What's worse, this effect varies wildly across browsers.

The gory details can be found in an article, "Browser Offset is Not Your Friend" (http://www.dsiegel.com/tips/wonk14/) by David Siegel.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

728 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

8 Experts available now in Live!

Get 1:1 Help Now