Results 1 to 5 of 5
Thread: JApplet doesn't load in browser?
- 06-25-2012, 08:53 PM #1
Member
- Join Date
- May 2012
- Posts
- 18
- Rep Power
- 0
JApplet doesn't load in browser?
Hello, I'm trying to load an applet in a browser. I have done this many times using the applet tag. But this time, I'm getting an error.
The error reads
Application error
RuntimeException
java.lang.reflect.InvocationTargetException
I've used Eclipse, readytoprogram and NetBeans to run it and none of them showed me that there is anything wrong with my code. Yet, I'm unable to load it with a browser.
I have done research but for now, I'll post the codes that I believe is related to it.
So a bit of playing around with the codes and research made me conclude the problem occurred when I added the ImageIcon variable. I believe that I'm supposed to have this code:Java Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Example extends JApplet{ ImageIcon BG = new ImageIcon("BG.png"); //adding the Image I want into an ImageIcon JLabel LBG; //JLabel so I can put the ImageIcon into it later private JLayeredPane lpane = new JLayeredPane(); //The Layeredpane so I can add images on top of each other public void init()//Initialize { super.setSize(760,530); super.getContentPane().setLayout(new BorderLayout()); super.getContentPane().add(lpane); //I will Store the imageIcon into the JLabel while changing the size of the Image LBG = new JLabel(BG){ public void paintComponent (Graphics g) { if (BG != null) { g.drawImage (BG.getImage(), 0, 0, 760, 530, this); } } }; LBG.setBounds(0, 0, 760, 530); LBG.setOpaque(false); lpane.add(LBG, new Integer(0), 0); } }
But the problem is that I'm unable to do that where the code is. And I can't move it into init() because then there will be errors.Java Code:try{ ImageIcon BG = new ImageIcon("BG.png"); } catch(Exception e){}
Well anyways, if my conclusion is correct, I don't know what to do.
and if it is wrong... I'll still need help. X.x
Thanks in advance.
-
Re: JApplet doesn't load in browser?
You're again asking volunteers to put in the effort to help you and yet you've not put in the effort to post well-formatted code. As before, please correct your code's formatting. I can't speak for others, but I plan to wait for easy to read code before addressing any of your code issues.
- 06-26-2012, 12:10 AM #3
Member
- Join Date
- May 2012
- Posts
- 18
- Rep Power
- 0
Re: JApplet doesn't load in browser?
I'm sorry for not satisfying you with an easy to read code. I was sure that it was better than the formatted code yesterday. And yes, I have added effort. Anyways, I'll try again.
I hope this is better.Java Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Example extends JApplet { ImageIcon BG = new ImageIcon ("BG.png"); //adding the Image I want into an ImageIcon JLabel LBG; //JLabel so I can put the ImageIcon into it later JLayeredPane lpane = new JLayeredPane (); //The Layeredpane so I can add images on top of each other public void init () //Initialize { super.setSize (760, 530); super.getContentPane ().setLayout (new BorderLayout ()); super.getContentPane ().add (lpane); //I will Store the imageIcon into the JLabel while changing the size of the Image LBG = new JLabel (BG) { public void paintComponent (Graphics g) { if (BG != null) { g.drawImage (BG.getImage (), 0, 0, 760, 530, this); } } }; LBG.setBounds (0, 0, 760, 530); LBG.setOpaque (false); lpane.add (LBG, new Integer (0), 0); } }
-
Re: JApplet doesn't load in browser?
When you load the applet, do you use the .class file or a .jar file? Can you show the HTML code you use to display the applet? You seem to be double-drawing your ImageIcon still, I'm curious why you're doing this?
- 06-26-2012, 12:52 AM #5
Member
- Join Date
- May 2012
- Posts
- 18
- Rep Power
- 0
Re: JApplet doesn't load in browser?
When I load my applet, I use the .class file...
This is the HTML code I used.
Java Code:<html> <body> <applet width="760" height="530" code="Test.class"> </applet> </body> </html>
And I seem to be double drawing again? I thought I fixed that problem. Well now that I added System.out.println(), it does seem that it goes through the paintComponent twice. But it only paints once.
I kinda played around with the code again and it seems that it goes through the paintComponent once but does nothing, then goes through it again and paints what I want.
Similar Threads
-
Converting JFrame to JApplet is not showing on browser.
By ganesh.gothi@gmail.com in forum Java AppletsReplies: 4Last Post: 06-12-2012, 05:05 PM -
Applet doesn't load in browser with certain class variables
By PoundCake in forum Java AppletsReplies: 5Last Post: 03-11-2012, 02:13 PM -
JApplet connecting to the database in browser
By pinxrick in forum Java AppletsReplies: 3Last Post: 03-22-2011, 04:12 AM -
japplet - jtable - browser
By jasonnuigi in forum Java AppletsReplies: 2Last Post: 12-31-2010, 02:16 PM -
JApplet.getGraphics() draws but JFrame doesn't
By ChazZeromus in forum New To JavaReplies: 5Last Post: 07-27-2009, 10:02 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks