Page 1 of 1
question
Posted: Thu Nov 21, 2002 3:53 pm
by adeelmahmood1
hi
can someone tell me how to put an image in the backgorund of a swing applet ...
Re:question
Posted: Thu Nov 21, 2002 5:20 pm
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);
}
Re:question
Posted: Thu Nov 21, 2002 8:20 pm
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?
Re:question
Posted: Fri Nov 22, 2002 5:48 am
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
Re:question
Posted: Sun Nov 24, 2002 12:28 pm
by smartguy240
WELL? DID IT HELP YOU?!?!?!?
Re:question
Posted: Sun Nov 24, 2002 2:46 pm
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
Re:question
Posted: Sun Nov 24, 2002 4:53 pm
by smartguy240
Tom...that is how to put an image in the backgorund of a swing applet ...
ughhh
Re:question
Posted: Sun Nov 24, 2002 5:39 pm
by grey wolf
Tom, it's a Java question and you posted arcane C code.
Re:question
Posted: Sun Nov 24, 2002 6:28 pm
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
Re:question
Posted: Sun Nov 24, 2002 7:19 pm
by smartguy240
Oh WOW i didnt know THAT is what you wnated to do...sheesh....i have no idea sorry :-\