Whenever I try to load a java applet from an html file, with the .class and .java files in the same directory, I load the html applet file and the only thing that gets displayed is NOT the applet, but the html code.....how do I enable java applets in my web browsers? I'm on a Mac, using Safari, Firefox, Opera, and Chrome, no browser displays the applet, only the html code!!

Recommended Answers

All 7 Replies

Sounds like a problem with your html. Let's see it.

Have you tried the appletviewer?

<HTML>
<APPLET CODE = "JDemoGraphics.class"
WIDTH = 420 HEIGHT = 300>
</APPLET>
</HTML>

And for some reason, the html code always ends up with a BLACK background color on the whole html file. Not important but weird.

//Date: 8/18/2010

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class JDemoGraphics extends JApplet
{
	String companyName = new String("Event Handlers Incorporated");
	
	public void paint(Graphics gr)
	{
		gr.drawString(companyName,10,100);
	}
	
}

I've tried appletviewer through the terminal and it loads, then quits, the applet never starts.

Here's the HTML code in FULL, at least when shown in Eclipse.


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="1038.32">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
</style>
</head>
<body>
<p class="p1">&lt;HTML&gt;</p>
<p class="p1">&lt;APPLET CODE = "bin/JDemoGraphics.class"</p>
<p class="p1">WIDTH = 420 HEIGHT = 300&gt;</p>
<p class="p1">&lt;/APPLET&gt;</p>
<p class="p1">&lt;/HTML&gt;</p>
</body>
</html>

Do your browser's have a Java console? Are there any error messages in the java console?

Why does the second html post show the bin folder when the first one did NOT?
CODE = "bin/JDemoGraphics.class"
vs
<APPLET CODE = "JDemoGraphics.class"

Which one are you using?

If that's your java code, it might be that it's just loading, painting that, and exiting.
How would you go about testing for that?

Sorry about the confusion with the bin/JDemoGraphics.class

I posted it and then noticed it. What I've done is copy all three files, .class, .java, and the html file onto the desktop so it doesn't get any folder confusions.

Ignore the bin/ that was a mistake.

I wouldn't know how to test something like that. It's never worked for me. I'm using Snow Leopard on the Mac. Even Firefox isn't working.

I tried looking for the java console but i can't seem to find it, or any errors.

The code works on my system (WinXP).
I wonder what html he's really using.
Why does the IDE show something different that his first post?

Keep looking for the Java console. The error messages will be there!!!

Mac OS X provides built-in support for Java applets. You don't have to do anything special to set this up--just run Netscape under OS X and you should be able to run the BioViews applets.

The best browser for running Java applets is Internet Explorer 5.1 or above. You can use Netscape 6.2, but it doesn't work as well.

Instructions
Java programs such as the BioViews map viewers run inside software called the "Java Virtual Machine," or JVM. All Java-capable browsers come with a JVM, but Internet Explorer is the only browser for the Mac that lets you pick the JVM that works best on your machine. The best JVM for pre-OS X Macs, buggy though it may be, is the Macintosh Java Runtime from Apple. (We have contacted Apple about the problems with the MRJ, and they are aware of the problems, but they do not consider it a priority to repair these problems.)

If you're running MacOS 8 or 9, we recommend you run our BioViews java tools using Apple's MRJ 2.1 teamed with Internet Explorer 4.5 or higher. Unfortunately, more recent versions of the MRJ are buggy and do not work properly with IE or Netscape. (Some users have gotten good results running GeneSeen with the latest MRJ version, but it does not work consistently.)

Downloading link
You should be able to download MRJ 2.1.4 from apple.com . In case that link stops working, we have saved local (untested!) copies of the MRJ 2.1.4 in two different formats:

* MRJ_2.1.4.smi.bin
* MRJ_2.1.4.smi.hqx

If you don't have Internet Explorer, get a copy of IE 4.0 or higher from http://www.microsoft.com/Mac/ie and install it on your machine. Internet Explorer will detect that you have installed the MRJ, and will automatically use it.

If you already have IE 4.0 or 4.5 installed, you should make sure that it is using the MRJ instead of the built-in Java interpreter. To do this, pick "Preferences" from the "Edit" menu. Go to the Java section of the preferences screen. Make sure that "enable Java" is clicked, and make sure that "Apple MRJ" is the selected Java virtual machine.

Configration:
After you install both Internet Explorer 4.5 and Apple's MRJ 2.1.4, you need to tell Internet Explorer to use Apple's MRJ.

To do this, double-click the Internet Explorer icon. Next, click the "preferences" icon at the top left - it looks like a folder. Under "Web Browser," select the option labeled "Java." Under "Java Options," chose "Apple MRJ" from the menu labeled "Java virtual machine."

Restart your browser. The next time you visit our Web site using Internet Explorer 4.5 or higher, you should be able to run our Java applets.

I hope this may help you solve your problem running applet on mac

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.