5 Replies - 100 Views - Last Post: 04 February 2012 - 09:35 PM Rate Topic: -----

Topic Sponsor:

#1 Dankwansere  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 103
  • Joined: 09-November 09

Applet is working fine in Eclipse but not in a web browser

Posted 04 February 2012 - 07:49 PM

Hey guys, I'm learning Java applets in my course now. I've written a simple applet to test out how applet works. I've wrote a basic applet with a JLabel inside which says "Welcome to Java" but for some odd reason when I run the applet in Eclipse it runs fine with the JLabel showing. But when I try to run it from a web browser I see a blank applet screen with no JLabel showing :s, and also when I use the applet viewer in the terminal to run the applet, I still see a blank screen with no JLabel :s here's my code...

Applet code
import java.applet.*;  
import java.awt.*;
import javax.swing.*;
public class applet extends JApplet
{
	private JButton B1 = new JButton("Gege");
	//private JLabel L1 = new JLabel("welcome to Java");
	
	public void init()
	{
		//add(B1);
		add(new JLabel("Welcome to java", JLabel.CENTER));
		
	}
	
	

}



HTML Code
<html> 
	<head>
		<title>Java applet</title>
	</head>
	
	<body>
		<applet
		
		code = "applet.class"
		width = 350
		height = 200>
		
		</applet>
	
	</body>

</html>


This post has been edited by Dankwansere: 04 February 2012 - 08:07 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Applet is working fine in Eclipse but not in a web browser

#2 Dankwansere  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 103
  • Joined: 09-November 09

Re: Applet is working fine in Eclipse but not in a web browser

Posted 04 February 2012 - 08:45 PM

I'm sorry for the duplicate post in my other post. I thought that this post never got posted :)
Was This Post Helpful? 0
  • +
  • -

#3 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1644
  • View blog
  • Posts: 4,126
  • Joined: 14-March 10

Re: Applet is working fine in Eclipse but not in a web browser

Posted 04 February 2012 - 08:46 PM

Which browser are you using? Does have all required plugin? I tested it in IE8 and FireFox9.0.1 and is working fine!!!
Also is your browser script /ActiveX enabled?

This post has been edited by smohd: 04 February 2012 - 08:55 PM

Was This Post Helpful? 1
  • +
  • -

#4 Dankwansere  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 103
  • Joined: 09-November 09

Re: Applet is working fine in Eclipse but not in a web browser

Posted 04 February 2012 - 08:48 PM

I'm using firefox and google chrome on Ubuntu Linux. But you know what i'm gonna try running this code on windows and see if it'll work
Was This Post Helpful? 0
  • +
  • -

#5 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1644
  • View blog
  • Posts: 4,126
  • Joined: 14-March 10

Re: Applet is working fine in Eclipse but not in a web browser

Posted 04 February 2012 - 08:55 PM

Also use a good practice to quote you attribute values:
width = "350"
 height = "200">
for modern browsers supporting XHTML

This post has been edited by smohd: 04 February 2012 - 08:58 PM

Was This Post Helpful? 0
  • +
  • -

#6 Dankwansere  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 103
  • Joined: 09-November 09

Re: Applet is working fine in Eclipse but not in a web browser

Posted 04 February 2012 - 09:35 PM

View Postsmohd, on 04 February 2012 - 10:46 PM, said:

Which browser are you using? Does have all required plugin? I tested it in IE8 and FireFox9.0.1 and is working fine!!!
Also is your browser script /ActiveX enabled?


Thnx finally got it to work! the problem was that my applet code had the following code "package samples;" because since I created the code in Eclipse I had it put in the package called samples, so each time I tried to run it from a browser the browser could not interpret that line of code :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1