• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Background

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
}
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Shiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic