question

Programming, for all ages and all languages.
Post Reply
adeelmahmood1

question

Post by adeelmahmood1 »

hi
can someone tell me how to put an image in the backgorund of a swing applet ...
smartguy240

Re:question

Post by smartguy240 »

This might be what you are asking....


public void paint(Graphics g)
{
// lay out the background image if any
if (withBGImage)
{
for (int y = 0; y < height - 1; y += hh)
for (int x = 0; x < width - 1; x += ww)
g.drawImage(image, x, y, this);
}

int w1 = (g.getFontMetrics()).stringWidth(title);
int h1 = (g.getFontMetrics()).getHeight();
int d1 = (g.getFontMetrics()).getDescent();

// draw the bounding box
g.setColor(white2);
g.drawRect(5, h1 / 2 + 1, width - 10, height - h1 - d1 - 5);
g.setColor(black2);
g.drawRect(4, h1 / 2, width - 10, height - h1 - d1 - 5);

// erase the extra lines
g.setColor(getBackground());
g.drawLine(12, h1 / 2, 12 + w1 + 3, h1 / 2);
g.drawLine(12, h1 / 2 + 1, 12 + w1 + 3, h1 / 2 + 1);

// draw the title string
g.setColor(white2);
g.drawString(title, 16, h1);
g.setColor(black2);
g.drawString(title, 15, h1 - 1);
}
adeelmahmood1

Re:question

Post by adeelmahmood1 »

well i have not tested ur code yet but i was just wondering that after putting this code in the background will i be able to put some more stuff on it by the usual way or not?
e.g
now if i add a jbutton .. is it gonna appear on the image or behind the image?
smartguy240

Re:question

Post by smartguy240 »

It SHOULD appear on top of the image...depending on which way you set the coodinates to be...On top of on bottom of image...but i may be wrong...notlikely though
smartguy240

Re:question

Post by smartguy240 »

WELL? DID IT HELP YOU?!?!?!?
Tom

Re:question

Post by Tom »

Well...what kind of code is that smartguy240?

Here is old DOS FritzOS code that does all the box painting code.:

#include <go32.h>
#include <sys/farptr.h>

// INIT GRAPHICS
// YOU should DO this in your BOOTSECTOR, like this
// BUT without the C comments:
// mov ax, 13h
// int 10h

// Now, put a pixel on the screen:
void putpixel_13h(int x, int y, int color)
{
_farpokeb(_dos_ds, 0xA0000+y*320+x, color);
}

// Call This to draw boxes:
void Box( int clr, int start_x, int start_y, int end_x, int end_y )
{
int i, y;
for ( i = start_x; i < end_x; i++ )
for ( y = start_y; y < end_y; y++ )
// NOTE: THIS IS SERVERLY NOT OPTIMIZED
putpixel_13h( i, y, clr )


void start()
{
// Test PutPixel, put a red pixel in the top
putpixel_13h( 12, 12, 4 );

// test box drawing: make a blue box
Box( 1, 90, 90, 199, 199 );
}

#ifndef __DJGPP__
#error I NEED DJGPP!
#endif
// THIS HAS BEEN MODIFIED FOR DGJPP
smartguy240

Re:question

Post by smartguy240 »

Tom...that is how to put an image in the backgorund of a swing applet ...

ughhh
grey wolf

Re:question

Post by grey wolf »

Tom, it's a Java question and you posted arcane C code. :)
adeelmahmood1

Re:question

Post by adeelmahmood1 »

NOP
this code doesnt works the way i want

i just want to put an image in the backgorund of this swing applet and then do the rest of the work normally in the init() method so that everything i make .. just appears on the image like the way it appears on the normal backgorund of the applet ..

this code doesnt puts the image nowhere?

what i was thinking that there might be a predefined method or class which just takes the image and put it in the backgorund of the applet ..

so wat do u think guys . plz help me out
smartguy240

Re:question

Post by smartguy240 »

Oh WOW i didnt know THAT is what you wnated to do...sheesh....i have no idea sorry :-\
Post Reply