Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Background

 
joe smiths
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to get my applet to have the same background as my web page. My web page's background is stars.jpg. Can someone tell what is the best way to get this to work? This is a small code snippet that won't compile:
public void init() {
stars=getImage(getCodeBase(), "stars.jpg");
setBackground(stars);
long lasttime;
p1 = new point(MAX, MAXV);
p2 = new point(MAX, MAXV);
p1.rand(); p2.ran(); //Randomize points
resize(MAX,MAX+20); //Set window size
}
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you check out the Java API docs you can see that setBackground() takes an object of type Color, not an image.
You need to override paint(), and the first thing you do is draw that image to the Graphics.
Check out Graphics.drawImage()
Rob
[ January 09, 2002: Message edited by: Rob Ross ]
 
Tim Holloway
Saloon Keeper
Posts: 18367
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, I think you can specify a transparent canvas. Do a search in this forum. Not long ago someone was asking for help on the exact opposite problem!
 
Douglas Wolfinger
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I posted that same question in Beginners, but I can't find it. I understand that Swing has a really neat way of dealing with this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic