This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Applets and the fly likes Applet background image help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet background image help" Watch "Applet background image help" New topic
Author

Applet background image help

Jimmy L Jones
Greenhorn

Joined: Sep 15, 2012
Posts: 4
I'm totally new to java, and trying to complete a project for school. The problem I have is that I'm trying to set an image as a background image in an applet, but it's showing up on top and covering the other elements.
The "calc.gif" image is the same size as the applet on the html file. It doesn't matter where I put the "getImage()" command within "init()", it still shows up on top of everything else. What can I do?


My code is as follows:

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
few changes, should work OK now

Jimmy L Jones
Greenhorn

Joined: Sep 15, 2012
Posts: 4
Works great, but is there a way to do this without having it compile two class files? Thanks
Jimmy L Jones
Greenhorn

Joined: Sep 15, 2012
Posts: 4
I just realized I need to add icons to the buttons too. I'm using the following code, but it's producing an error when viewed on the html page with a browser. The applet compiles with no errors, although it makes 2 class files (one with $ in the name). I'd like to have it only compile 1 class file if possible, and I'm not sure where to add the code for the button icons to make it work (what I have here isn't working)! Any help in getting this working is GREATLY appreciated!

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
try this for your icons

//Icon button1icon = new ImageIcon("button1.gif");
//Icon button2icon = new ImageIcon("button2.gif");
Icon button1icon = new ImageIcon(this.getClass().getResource("button1.gif"));
Icon button2icon = new ImageIcon(this.getClass().getResource("button2.gif"));

> I'd like to have it only compile 1 class file if possible

couple of things to try
1) use awt components only - might address the heavyweight/lightweight painting issue
2) instead of a JPanel with overridden paintComponent (the $class), use a JPanel set as an OverlayLayout.
this would hold 2 panels - first one set as a BorderLayout and to contain a JLabel with your image. Second panel,
on top, containing your components (this panel would need to be transparent so the image underneath shows through)

don't know why you only want a single class, you'll most likely have to .jar it anyway, because of the image files.
Jimmy L Jones
Greenhorn

Joined: Sep 15, 2012
Posts: 4
Thank you for the help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Applet background image help
 
Similar Threads
parallel array and applets
JCheckBoxMenuItem
another .ttf question
how to solve the error?
How to solve the Error