Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Graphics2D problem

Status
Not open for further replies.

wduty

Programmer
Jun 24, 2000
271
US
I have been repeatedly unsuccessful in getting the Graphics2D class to work in an applet. Everything I've tried compiles OK but I don't get any graphics when run in a browser. The same applets do work in appletviewer, but that doesn't do much good.

I'm using jdk1.2.2. Every other class in the jdk works including all my applets using the regular awt.Graphics class. I even downloaded some Graphics2D examples from sun's tutorial and tried compiling them. They compile successfully but they still don't work and I end up with the PC "gray block". Also, sun's examples work in appletviewer but not a browser.

The java console says it can't find the Graphics2D class.

java.lang.ClassNotFoundException: java.awt.Graphics2D
at com/ms/vm/loader/URLClassLoader.loadClass (URLClassLoader.java)
at java/lang/ClassLoader.loadClassInternal (ClassLoader.java)
etc.

I tried downloading jdk1.3 and installing that on my computer and I still have the same problem. I don't see how everything else could work except Graphics2D. I'm not even trying to do anything complicated. Even something like this doesn't work though it compiles fine:

[red]import java.applet.*;
import java.awt.*;

public class simple extends Applet
{
public void paint(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.blue);
g2.drawString("hello",9,9);
}
}
[/red]

If the VM can't find the Graphics2D class then I don't see how it would run in appletviewer but not a browser. Also, in Netscape I get a security exception in the status bar. Any suggestions or insights appreciated.

 
Do you have a java plugin installed? [sig][/sig]
 
I don't think so. Do I need one? I thought 2D was part of the standard API. If I do need a plug-in, which one do I need? Also, I see applets at sun and elsewhere which use Graphics2D and which run on my computer. Why do they run if I don't have the plug-in? [sig]<p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br> [/sig]
 
OK, probably you have the plugin installed. Maybe the following helps you (found at )


The SwingApplet.html file does not invoke the Plug-in. It displays the applet in browsers that support Java1.2 natively (eg: appletviewer).

You must replace the <applet> tag with the appropriate plug-in tag; <object> under IE, <embed> under Netscape. Here is a valid HTML file for IE. Put this file in the same directory as SwingApplet.html.

<html>
<head><title>Swing Applet</title></head>
<body>

<OBJECT classid=&quot;clsid:8AD9C840-044E-11D1-B3E9-00805F499D93&quot;
width=&quot;500&quot;
height=&quot;300&quot;
codebase=&quot;<param name=&quot;code&quot; value=&quot;SwingApplet.class&quot;>
<param name=&quot;archive&quot; value=&quot;SwingApplet.jar&quot;>
<param name=&quot;type&quot; value=&quot;application/x-java-applet;version=1.2&quot;>
</OBJECT>

<!--
<applet code=SwingApplet archive=SwingApplet.jar width=500 height=300>
</applet>
-->

</body>
</html>

[sig][/sig]
 
P.S. The 2D Api (like Swing) is not directly supported by most browsers. [sig][/sig]
 
But it's not a swing applet... (or so I thought). I was just trying to get Graphics2D to work. Does that somehow implicitly require swing functionality?

--Will Duty
wduty@radicalfringe.com

 
I put a faq on how to use the plugin in the FAQ section in the Java(sun) forum, the main part where all the questions are listed, just look at the top and click on FAQ...

good luck



ackka
tmoses@iname.com
&quot;Do No Harm, Leave No Tracks&quot;

ICMP Summer 2000, 2600 Article
 
Thanks guys. I read the FAQ and will give the 2D thing a shot again as soon as I have time.

--Will Duty
wduty@radicalfringe.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top