Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can't even display image

Status
Not open for further replies.

Lupine

Programmer
Aug 3, 2000
53
US
just a tiny square comes up where the top left of teh .gif should
be
can someone please tell me what the corresponding .html
of the following code should look like?
I think thts whare the problem is
________________________________________________________________
import java.awt.*;
import java.applet.*;
import java.net.*;
public class TrivialApplet extends Applet
{
Image snake;
public void init()
{
URL codeBase = getCodeBase();
snake = getImage(codeBase, "snake.gif");
resize(250, 250);
}
public void paint(Graphics g)
{
int width = snake.getWidth(this);
int height = snake.getHeight(this);
g.drawRect(52, 52, width+10, height+10);
g.drawImage(snake, 57, 57, width, height, this);
}
}

Lupine
RobertCorrina@patownsend.com

 
> resize(250, 250);


You can't resize the applet from within. It's size is determined by the browser, i.e., the 'height and width' attributes of the <applet> tag.

Hope this helps
-pete
 
Robert,

This is very simplistic - but here it is.

<APPLET code=&quot;TrivialApplet.class&quot; width=&quot;400&quot; height=&quot;400&quot;>
</APPLET>

Stick this in an html file and launch it.

As Pete said - the size is controlled by the APPLET tag.

HTH
Tim
 
I will try removing the resize command from the code

and see if that changes the output!

Many Thanks

Lupine
RobertCorrina@patownsend.com

 
good sugestions I am learning alot!

I kind of need to know exactly why it dosent work
so I can become ninja.

thank you to everyone for your insights,

I have rewritten the program.
(I was actually following a certain tutorial which will remain nameless)
-----------------------------------------------------------------
import java.applet.*;
import java.awt.*;

public class Applet1 extends Applet
{

private Font ONEfont;
public void init()
{
Image lion;
lion= getImage(getCodeBase(),&quot;DB1001.gif&quot;);
ONEfont=new Font(&quot;Courier&quot;,Font.BOLD,48);
setFont(ONEfont);
setBackground(Color.blue);

}
public void paint (Graphics g)
{

g.drawString(&quot;Hello World!&quot;, 50, 40);
//g.drawImage(lion, 50, 70,this);
//getting a variable not defined message
}
}
-----------------------------------------------------------------

as you can see getting lion=not defined
if I copy the:

Image lion;
lion= getImage(getCodeBase(),&quot;DB1001.gif&quot;);

down into the paint method it eliminates the error
and the program runs... without displaying the .gif
which is the same as the problem with the original
program, interesting, yes?
so, I'm keeping the program as above, I'd rather have
a known error then some ghost .gif
(btw I changed the .gif on the off chance there might be a problem there)


Lupine
RobertCorrina@patownsend.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top