Background picture to famous "ImageTest" applet - Is it supid Question?

I would like to see what Pholser will say about this. :)
Is this a dumest question or what ?
Thanks in advance
basisdba
------------------ Repeated----------------------------------------
Hi to all,
I am not sure if you could help on this one or not, but
will be happy to see any responding on this :))
This is the example that I have worked on:
http://java.sun.com/applets/other/ImageTest/index.html
I am trying to add a sold background to this, is this possible?
Thanks in advance
Regards,

Hi Sam and all of you,
Sorry for the delay I am very bussy daily as SAP adminstrator,
if you know what I mean :)
You both are right but with some minor corrections.
You guys are all great after all...
I attached ImageTest.java demo sample with this modification to the
background only...I am trying to add extra code into it to allow
NOT only BLUE/RED swap color but also some more colors, how can I do
that? How can I add black, green, yellow and so on...(stupid nah :) )
Why in the hell "Java Tech.." make the color defining so hard? :)
Or it would be nice to have a 16 color table to choose from...
Thanks again to all of you and I also rewarded your points based
on the most recent "white house" logic! :)))))
Regards,
------------------------------- Start of the code
/*Modified only ImageTest.java Demo
import java.lang.Math.*; // for Spray
import java.awt.*; // note to self - imports CURSOR class
import javax.swing.*; // for ui
import java.awt.image.*; // for images
import java.applet.*; // for sounds
import java.awt.event.*; // for events
import java.net.*; // URL
import java.net.URL;
import java.util.Vector;
import java.awt.geom.*; // for Line2D
import java.util.*; // used for the Vector in the flood fill method
import java.util.StringTokenizer;
public class ImageTest extends Applet {
//Init
public void init()
// Image bg0 = applet.getImage(applet.getDocumentBase(),"images/bg0.gif");
setLayout(new BorderLayout());
add("Center", new ImagePanel(this));
add("North", new ImageHelp());
setVisible(true);
public String getAppletInfo()
return "A simple image manipulation tool.";
class ImageHelp extends Panel {
public ImageHelp() {
setLayout(new GridLayout(6, 1)); //Grid 5 Row and 1 column
//m
// add(new Button("Move"));
//m
add(new Label("test",
Label.CENTER));
add(new Label("Image Move: < > ^ v, or with [L]eft/[R]ight/p/[D]own",
Label.CENTER));
add(new Label("Image Resize: +/-",
Label.CENTER));
add(new Label("Color Filter: T key",
Label.CENTER));
add(new Label("Change Alpha: (Shift)+/-",
Label.CENTER));
add(new Label("Rotate Image: (Shift)<> or (Shift)[L]eft/[R]ight",
Label.CENTER));
System.out.println("");
class ImagePanel extends Panel
Applet applet;
public ImagePanel(Applet app) {
applet = app;
setLayout(new BorderLayout());
Panel grid = new Panel();
grid.setLayout(new GridLayout(1, 1)); //first(row), second (column)
add("Center", grid);
     Image bg0 = applet.getImage(applet.getDocumentBase(),"images/bg0.gif");
     Image fg0 = applet.getImage(applet.getDocumentBase(),"images/ff001.gif");
     grid.add(new ImageCanvas(applet, fg0, bg0, 1.0));
     setBounds(0, 0, 20, 20);
class ImageCanvas
extends Canvas
implements ImageObserver, KeyListener, MouseListener,
MouseMotionListener, FocusListener {
double hmult = 0;
int xadd = 0;
int yadd = 0;
int xprev = 0;
int yprev = 0;
int imgw = -1;
int imgh = -1;
int xoff = 0;
int yoff = 0;
int scalew = -1;
int scaleh = -1;
boolean focus = false;
boolean usefilter = false;
static final int numalphas = 9;
int alpha = numalphas - 1;
static final int numrotations = 8;
int rotation = 0;
ImageFilter colorfilter;
ImageFilter alphafilters[] = new ImageFilter[numalphas];
RotateFilter rotfilters[] = new RotateFilter[numrotations];
Image origimage;
Image curimage, backimage;
Applet applet;
     public BufferedImage currentImage, oldImage, tempImage, storedImage;
Image bg0, bg1, bg2, bgImage;
     public URL URL_STRING;
private int picNo = 0;
public void init()
try {
     bg0 = new ImageIcon(new URL(URL_STRING +"images/bg0.gif")).getImage();
     bg1 = new ImageIcon(new URL(URL_STRING +"images/bg1.gif")).getImage();
     catch (Exception exc)
     {//imgLoad = "Image failed to load";
public ImageCanvas(Applet app, Image img,Image bg0,double mult) {
applet = app;
origimage = img;
backimage = bg0;
hmult = mult;
pickImage();
setBounds(0, 0, 100, 100);
addMouseListener(this);
addMouseMotionListener(this);
addKeyListener(this);
addFocusListener(this);
//1.1 event handling
public void focusGained(FocusEvent e) {
focus = true;
repaint();
public void focusLost(FocusEvent e) {
focus = false;
repaint();
public void keyPressed(KeyEvent e) {
public void keyTyped(KeyEvent e) {
char key = e.getKeyChar();
switch(key)
case 't':
case 'T':
usefilter = !usefilter;
pickImage();
repaint();
e.consume();
break;
case '^':
case '6':
case 'u':
case 'U':
yadd -= 5;
repaint();
e.consume();
break;
case 'v':
case 'V':
case 'd':
case 'D':
yadd += 5;
repaint();
e.consume();
break;
case '>':
case 'R':
rotation--;
if (rotation < 0) {
rotation = numrotations - 1;
pickImage();
scalew = scaleh = -1;
repaint();
e.consume();
break;
case '.':
case 'r':
xadd += 5;
repaint();
e.consume();
break;
case '<':
case 'L':
rotation++;
if (rotation >= numrotations) {
rotation = 0;
pickImage();
scalew = scaleh = -1;
repaint();
e.consume();
break;
case ',':
case 'l':
xadd -= 5;
repaint();
e.consume();
break;
case '+':
if (++alpha > numalphas - 1) {
alpha = numalphas - 1;
pickImage();
repaint();
e.consume();
break;
case '=':
hmult *= 1.2;
scalew = scaleh = -1;
repaint();
e.consume();
break;
case '-':
hmult /= 1.2;
scalew = scaleh = -1;
repaint();
e.consume();
break;
case '_':
if (--alpha < 0) {
alpha = 0;
pickImage();
repaint();
e.consume();
break;
public void keyReleased(KeyEvent e) {
public void mouseClicked(MouseEvent e) {
public void mousePressed(MouseEvent e) {
xprev = e.getX();
yprev = e.getY();
e.consume();
public void mouseReleased(MouseEvent e) {
e.consume();
public void mouseEntered(MouseEvent e) {
requestFocus();
e.consume();
public void mouseExited(MouseEvent e) {
public void mouseDragged(MouseEvent e) {
int x = e.getX();
int y = e.getY();
xadd += x - xprev;
yadd += y - yprev;
xprev = x;
yprev = y;
repaint();
e.consume();
public void mouseMoved(MouseEvent e) {
     //method selects a random image for the child to draw on or colour in
     public void backGroundImage(){
public void paint(Graphics g) {
g.drawImage(backimage, 0, 0, this);
Rectangle r = getBounds();
int hlines = r.height / 10;
int vlines = r.width / 10;
if (imgw < 0) {
imgw = curimage.getWidth(this);
imgh = curimage.getHeight(this);
if (imgw < 0 || imgh < 0) {
return;
if (scalew < 0) {
if (rotation == 0) {
scalew = imgw;
scaleh = imgh;
} else {
Rectangle rect = new Rectangle(0, 0, imgw, imgh);
rotfilters[rotation].transformBBox(rect);
xoff = rect.x;
yoff = rect.y;
scalew = rect.width;
scaleh = rect.height;
scalew = (int) (scalew * hmult);
scaleh = (int) (scaleh * hmult);
xoff = (imgw - scalew) / 2;
yoff = (imgh - scaleh) / 2;
if (imgw != scalew || imgh != scaleh) {
g.drawImage(curimage, xadd + xoff, yadd + yoff,
scalew, scaleh, this);
} else {
g.drawImage(curimage, xadd + xoff, yadd + yoff, this);
static final long updateRate = 100;
public synchronized boolean imageUpdate(Image img, Image bg0,int infoflags,
int x, int y, int w, int h) {
if (img != curimage) {
return false;
boolean ret = true;
boolean dopaint = false;
long updatetime = 0;
if ((infoflags & WIDTH) != 0) {
imgw = w;
dopaint = true;
if ((infoflags & HEIGHT) != 0) {
imgh = h;
dopaint = true;
if ((infoflags & (FRAMEBITS | ALLBITS)) != 0) {
dopaint = true;
ret = false;
} else if ((infoflags & SOMEBITS) != 0) {
dopaint = true;
updatetime = updateRate;
if ((infoflags & ERROR) != 0) {
ret = false;
if (dopaint) {
repaint(updatetime);
return ret;
public synchronized Image pickImage() {
ImageProducer src = origimage.getSource();
if (alpha != numalphas - 1) {
ImageFilter imgf = alphafilters[alpha];
if (imgf == null) {
int alphaval = (alpha * 255) / (numalphas - 1);
imgf = new AlphaFilter(alphaval);
alphafilters[alpha] = imgf;
src = new FilteredImageSource(src, imgf);
if (rotation != 0) {
RotateFilter imgf = rotfilters[rotation];
if (imgf == null) {
double angle = (2 * Math.PI * rotation) / numrotations;
imgf = new RotateFilter(angle);
rotfilters[rotation] = imgf;
src = new FilteredImageSource(src, imgf);
if (usefilter) {
if (colorfilter == null) {
colorfilter = new RedBlueSwapFilter();
src = new FilteredImageSource(src, colorfilter);
Image choice;
if (src == origimage.getSource()) {
choice = origimage;
} else {
choice = applet.createImage(src);
if (curimage != choice) {
if (curimage != null && curimage != origimage) {
curimage.flush();
curimage = choice;
return choice;
class RedBlueSwapFilter extends RGBImageFilter {
public RedBlueSwapFilter() {
canFilterIndexColorModel = true;
public void setColorModel(ColorModel model) {
if (model instanceof DirectColorModel) {
DirectColorModel dcm = (DirectColorModel) model;
int rm = dcm.getRedMask();
int gm = dcm.getGreenMask();
int bm = dcm.getBlueMask();
int am = dcm.getAlphaMask();
int bits = dcm.getPixelSize();
dcm = new DirectColorModel(bits, bm, gm, rm, am);
substituteColorModel(model, dcm);
consumer.setColorModel(dcm);
} else {
super.setColorModel(model);
public int filterRGB(int x, int y, int rgb)
return ((rgb & 0xFF000000)) | ((rgb & 0xff00ff00)|((rgb & 0xff0000) >> 16)| ((rgb & 0xff) << 16)); //
//return ((rgb & 0xff00ff00)|((rgb & 0xff0000) >> 16)| ((rgb & 0xff) << 16)); //
class AlphaFilter extends RGBImageFilter {
ColorModel origmodel;
ColorModel newmodel;
int alphaval;
public AlphaFilter(int alpha) {
alphaval = alpha;
canFilterIndexColorModel = true;
public int filterRGB(int x, int y, int rgb) {
int alpha = (rgb >> 24) & 0xff;
alpha = alpha * alphaval / 255;
return ((rgb & 0x00ffffff) | (alpha << 24));
//------------------------------- End of the code

Similar Messages

  • Is it possible to add a background picture to famous "ImageTest" applet?

    Hi to all,
    I am not sure if you could help on this one or not, but
    will be happy to see any responding on this :))
    This is the example that I have worked on:
    http://java.sun.com/applets/other/ImageTest/index.html
    I am trying to add a sold background to this, is this possible?
    Thanks in advance
    Regards,

    check the SwingSet2 demo which comes with the jsdk documentation..

  • Inserting background picture

    Hi! Is there any way I can insert a background picture in an applet
    instead of using just plain colors.. If there is how can I do it?
    Your help is appreciatted.
    thanx

    You can paint an image right on the background, and than any other things.
    That image can be semitransparent for a better look.
    you might need to override
    public void paintComponent(Graphics)
    for doing this

  • Background pictures do not show up on Singsnap when I open a song to listen to.

    When I click on a song to listen to on the site "Singsnap" some of the users have put pretty background pictures on their site but all I see is plain white, the background does not show up....It also does not show up on IE but it shows up beautifully on Google Chrome......Is there some setting I have disabled or what......The HTML is enabled...

    See:
    * [[Website colors are wrong]]
    * [[Websites look wrong]]
    * [[Images or animations do not show]]
    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]
    * [[Troubleshooting plugins]]

  • I am trying to connect my mac book pro to the tv via a mini display port and a hdmi cable, the only picture that is on the tv screen is the background picture on my computer, any suggestions?

    I am trying to connect my mac book pro to the tv via a mini displayport to a hdmi cable, the only picture on the tv screen is the background picture of my mbp, does anyone know what I need to connect to my samsung tv ?

    Hi there. I also bought an iWires mini Display port to HDMI cable and have an LG LED/LCD TV. I plugged it in to my MB Pro and followed the very small writing that came in the package and got both audio and video going. You need to change the audio settings from within System Preferences on your Mac to select your TV as the audio output.
    My concern is the data latency - do you experience a delay between moving your mouse on the MBPro and the TV displaying the movement? It is only a fraction of a second, but certainly enough to be annoying, especially in a cable as expensive as the iWire.

  • I have an iphone 4s why does it have a black screen instead of my background picture when I get a text message?

    I have an iphone 4S why does it have a black screen instead of my background picture when I get a text message?

    When you see the old number come up in the suggested choices look for a blue arrow to the right of the Contact. Tap the blue arrow and then tap Remove from Recents.

  • How to stop the auto change of the desktop background picture ?

    How to stop the auto change of the desktop background picture ?

    Well . . thanks, but I already have done that and I still have the problem. The background changes to the standard picture galaxy not to one of the options. Sorry my question wasn't clear enough.
    Thanks. 

  • How do I change the background picture that is shown when i start my Mac?

    On the iMacs in my school they have a different name for everyone of the after for example the band Queen and then there is a picture on the inlogg screen with queen on it. So then you log in and there is another background picture after that. I Have a macbook pro and I would like to change that "start-picture".
    Right now it´s kind of boring and grey. Can you change it somehow?

    It sounds like you're using Adobe Send for Outlook.  Correct?
    Unfortunately, there is no way to change the default text that is inserted into your message. You'll have to change it each time.
    I will pass along your request to the Adobe Send team.

  • After turning on iMAC the sign in page comes up and accept my password. It then goes to a page with a background pictures but nothing else. If I leave it there it eventually fades and shows the clock.  How to I get it to open from there?

    After turning on iMAC the sign in page comes up and accept my password. It then goes to a page with a background pictures but nothing else. If I leave it there it eventually fades and shows the clock.  How to I get it to open from there?

    Hello,
    See if it'll Safe Boot from the HD, (holding Shift key down at bootup).

  • Edit will not display content only background picture

    I have five pages linked - three work fine when I go to edit. the other two only display the background picture (two different pictures) but no content. I have tried all I know to fix it. Any ideas out there?  contribute CS4 Ver. 5

    Hi,
         Can you provide links to the web pages with which you are having problem?

  • Stationary/Background pictures question.

    Hello, I just had a quick question. I am a new Mac user, I have always used a PC before, and I just bought a mac which I have had for about a week. Anyways, my question is... is there any way to put stationary/background pictures on the e-mail? I can't find any anywhere on my computer, and I just want to know if I am overlooking it or not, and if there isn't any stationary, is there a way to get some? Thanks.
    As for the computer that I have, it is a Mac OS X Version 10.4.9, and the Processor is 2 GHz Intel Core 2 Duo.

    I don't believe this is possible within Mac OS X Mail in Tiger but it will be in Leopard. You should check out some of Apple's iCards for now.

  • TS3899 Getting a "background picture of angry birds" in back of my e mail messages...any ideas how to get rid of this?  Thanks for your help

    All of a sudden I am getting a background picture of angry birds in my e mail.  I can view the mail but it is annoying.
    I have cleard the history an still it appears.   Any ideas on how to get rid of this garbage?  Thanks for your help.

    Bettina:
    Do you see the color in Designer, or only Acrobat. If it's only in Acrobat, try changing the menu item Forms >> Highlight Fields. This toggles entry field highlights on and off.
    Mark
    You can shut off or change the highlight with this
    app.runtimeHighlightColor = color.red;
    if (app.runtimeHighlight)
    app.runtimeHighlight = false;

  • Background picture in a Mail message ?

    How can we insert a picture to be used as the background of a message, with the usual options (single, wallpaper,...) ?

    Hello,
           Since we can have a Static Background Picture assigned to the PAGE, it will not be possible to make it Conditional and assign a Background Picture at Run Time.
    Thanks and Regards,
    Venkat Phani Prasad Konduri

  • Background Pictures in Disc Images

    I've been trying to create a disc image using Disc Utility that displays a background image when you open it, similar to the kind used by many shareware apps distributed these days (ie. a picture that says "To install, drag this folder to your hard disk").
    The problem is that I can't seem to get the background picture to "stick", as it were. I've set up a folder with a bg pic and dragged it onto Disc Utility to create a compressed disc image, but the background disappears when I open the finished product. I've tried altering the disc image once it's finished instead, but as soon as I eject it and re-load the image, it's lost its background picture.
    I sort of managed to get this to work by creating an uncompressed read/write disc image with Disc Utility instead and then altering the contents with my background picture, but when I transfer it to another computer my settings have vanished. This isn't really an ideal solution anyway, though, as I would rather used a compressed image for internet distribution.
    I've tried doing a search on this forum for similar queries, but most of them seem to concentrate on how to make the background picture a hidden file, which I'm not terribly concerned about. That, and I'm not all that keen on too much fiddling about in the Terminal...
    So, can anyone help me here? How do those shareware developers make their custom disc images? Any help would be greatly appreciated. Thanks in advance!
    - Greg
    iMac G5 20 ALS   Mac OS X (10.4.7)  

    Sorry, wrong forum!

  • Why does the screen background picture get reset to default when switching user

    iMac with OS X 10.6.8
    I have several user accounts on this iMac, each with a different wallpaper chosen from a common folder (library/desktop/nature) in the top level of the hard drive. (Which exists – can always reset background picture from this folder)
    When I switch from one user account to another, the wallpaper picture, set on the previous login,  appears for a moment and then is  immediately replaced by the default blue.
    This happens when switching from any user to another. I tried restarting the system but the problem is still there.
    This problem just suddenly started and there have been no upgrades or changes to OS X.
    Ideas appreciated!!

    I've found the answer.
    Today, the problem suddenly appeared on my other Mac, which made me look at recent apps..
    I installed Team Viewer a month ago, (which is a great app apart from this) so quit it and removed it from the dock. Problem solved!!
    The odd thing is that the problem appeared only after I had been using Team Viewer for some weeks.

Maybe you are looking for