Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Graphics 2D Applet not working in browser

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have recently written a small applet that uses the Graphics2D API. I have worked out all the bugs and it runs great using Sun's Appletviewer. For some silly reason however, it will not open the applet in the most recent version of Iexplore or Netscape. I have struggled with this for a month, and any hints anyone could give me would be greatly appreciated.
What even wierder is that I downloaded a Graf2D enabled applet from Sun's site (One that runs fine on my browser when I am viewing it on Sun's site, then posted the .class file on my site, and viewed it in Iexplore (and Netscape) and again, it crashes without loading.
What am I missing?
Thanx!!
M
 
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using Swing components in your applet? If so, that's probably the problem. The browsers don't support this yet, although i think from version 1.2 of the jdk, the appletviewer will. You can either use HotJava browser, I think, or there is a plugin for IE or netscape that you can download from sun. The reason sun's sample works even though you don't have the plugin, MAYBE, is because I think there is some way you can run some program on your HTML file and then it points to a plugin that is residing on the server-side or something like that. This may not be the right answer, but I know it has tripped up a LOT of people. IE and Netscape just do not support Swing components right now.

 
Mark Ott
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know squat about Swing, so no I didn't put any in. It is a very simple program that only calls a GeneralPath, thats the only call... Is ANY graf2D ref considered Swing? I didn't think so, but I could be wrong (not a huge surprise.. )
thanx! -M
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Graphics2D is in the awt package and not swing so... There is sumething else going on here. What error message are you getting in the Java Console of your browser?
In netscape it's under Communicator - Tools - Java Console.
In IE it's under View - Java Console.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That you were able to run a G2D applet from Sun's site but not after you downloaded it suggests you may be having problems moving the class files. Did you use binary ftp?
Did you move your applet across computers or networks?
I'd also view the source of Sun's page with the applet you used. Look at the applet tag to see if it also specified a jar archive. Not downloading that would also cause the downloaded applet not to work.
Would you be willing to post the URL for your applet so the rest of us could take a look at its behavior in our browsers? And look at the java console error messages?
 
Mark Ott
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I went back to the file finally and have posted it at http://www.wwcc.cc.wy.us/pmott/java/lightningballwith2d.htm
I have also posted what the non-2D version looks like (so you can see my intent)at http://www.wwcc.cc.wy.us/pmott/java/lightningball.htm
After posting it and looking at the java console, I see I am getting the following error:
java.lang.ClassNotFoundException: java.awt.Paint
Again, this applet runs fine on my local appletviewer. If you want, here is the .class file http://www.wwcc.cc.wy.us/pmott/java/lightning.class
If you load it on your machine (you will have to make an html file that makes an applet window about 400x400
What seems to be the problem? Again, Thank you all very much!!
-M
The complete sourcefile is at http://www.wwcc.cc.wy.us/pmott/java/lightsource.htm
Here is the jist of the source code....
/** Class Lightning 1/6/01
* This program is an applet that has 2 circles. A lightning strike
* starts from a central circle and moves randomly out to the outer edge, It
* flops around there for a bit then restarts another one.
* The first strike is called the parent strike, and the subsequent strikes
* with the same start and end points are daughter strikes.
* @author Doc Ott
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.awt.geom.*;
public class Lightning extends Applet
{
public void paint (Graphics graf)
{
while (parentCount<numberOfParentStrikes)>
{
parentCount++;
getStartCoords ();
numberOfSteps = createStrikeArray (true); // I am a parent
Graphics2D graf2 = (Graphics2D) graf; // graf2 is the magic
place to write
graf2.setPaint(bg);
// outside circle
graf2.fillOval(lightningCenterX-outsideCircleRadius+1,
lightningCenterY-outsideCircleRadius+1,
2*outsideCircleRadius-2,2*outsideCircleRadius-2);
graf2.setPaint(red);
// inside circle
graf2.fillOval(lightningCenterX-insideCircleRadius,
lightningCenterY-insideCircleRadius,
(2*insideCircleRadius),(2*insideCircleRadius));
graf2.setPaint(red);
GeneralPath lightningStrike = new GeneralPath(GeneralPath.WIND_EVEN_ODD,numberOfSteps);
lightningStrike.moveTo (xArray[1]+lightningCenterX,
yArray[1]+lightningCenterY);
for (int i=2; i< (numberOfSteps-1); i++) {
lightningStrike.lineTo(xArray[i]+lightningCenterX,
yArray[i]+ lightningCenterY);
} // for loop
graf2.draw(lightningStrike); //once its figured out, draw it.
} // while still parent Strikes
} // paint
} //Lightning Class
    Bookmark Topic Watch Topic
  • New Topic