Solved

Drawing a background image on an applet

Posted on 1997-05-15
1
372 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
Ted Hopp earned 50 total points
ID: 1220467
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

630 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