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?
Works great, but is there a way to do this without having it compile two class files? Thanks
Jimmy L Jones
Joined: Sep 15, 2012
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!
Joined: Jun 09, 2003
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.