File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes Raytracer Applet will not start Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Raytracer Applet will not start" Watch "Raytracer Applet will not start" New topic
Author

Raytracer Applet will not start

Bigrich Legend
Greenhorn

Joined: Mar 20, 2013
Posts: 3
Hi all, I need help with this and would appreciate ANY help indeed: I was cleaning up my 1 Terabyte external hard drive and came across A Raytracer applet code I got from a friend (who has left the programming life for greener pastures in accounting). The applet compiles in all three IDE's I have used without any errors but does not display anything when it starts - I get

"Error: Main method not found in class raytracer.Raytracer, please define the main method as:
public static void main(String[] args)"

But this is an Applet and as far as I know does not need a main method.

Even though it was written in a previous version of java (1999 version) I was of the belief that just recompiling with java 1.1.0_17 would work. I have put the source code here. There are many more modules in this package but they all compile without errors. These two files are the ones that all the IDE's I have used on this project refer to as producing some sort of error.

// This file is Raytracer.java

package raytracer;


public class Raytracer extends TinyPTC {


public void started(int width, int height)
{

int pixels[] = new int[width * height];
update(pixels);
update(pixels);

Scene scene = new Scene();
//---------------Build Scene................

//create objects

Sphere sphere = new Sphere(new Vector(0.0f, 0.0f, 2.0f));
sphere.color(new Color(1, 0, 0));
sphere.lighting(true, true, 0.1f, 0.5f, 80);
scene.objects[1] = sphere;

sphere = new Sphere(new Vector(-1, 0, 2.7f));
sphere.color(new Color(1, 0, 0));
sphere.lighting(true, true, 0.1f, 0.5f, 80);
scene.objects[2] = sphere;

sphere = new Sphere(new Vector(1, 0, 2.7f));
sphere.color(new Color(0, 1, 0));
sphere.lighting(true, true, 0.1f, 0.5f, 80);
scene.objects[3] = sphere;

sphere = new Sphere(new Vector(0, 0, -1.5f));
sphere.color(new Color(1, 1, 1));
sphere.lighting(true, true, 0.1f, 0.5f, 80);
scene.objects[4] = sphere;

Plane plane = new Plane(new Vector(0, 1, 0), 1);
plane.color(new Color(0.5f, 0.5f, 0.5f));
plane.lighting(true, false, 0.5f, 0, 1);
scene.objects[5] = plane;

plane = new Plane(new Vector(0, -1, 0), 100);
plane.color(new Color(0.6f, 0.62f, 1.0f));
plane.lighting(false, false, 0.35f, 0, 0);
scene.objects[6] = plane;

//create lights

scene.lights = new Light[3];

scene.lights[0] = new Light(new Vector(16, 17, -18));
scene.lights[1] = new Light(new Vector(-20, 7, -8));
scene.lights[2] = new Light(new Vector(2, 1, 8));

//setup camera

scene.camera.setup(new Vector(0, 0, 0), new Vector(0, 0, 1), new Vector(0, 1, 0));
//setup scene parameter

scene.threshold = 0.5f;
}


}


//This file is TinyPTC.java


package raytracer;

import java.awt.*;
import java.awt.image.DirectColorModel;
import java.awt.image.ImageProducer;
import java.awt.image.ImageConsumer;
import java.util.Arrays;

public abstract class TinyPTC extends java.applet.Applet implements ImageProducer, Runnable {
public abstract void started(int width, int height);

public synchronized void update(Object pixels) {

//check consumer

if (_consumer != null) {

//copy integer pixel data to image consumer
_consumer.setPixels(0, 0, width, height, _model, (int[]) pixels, 0, width);
_consumer.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
}

//paint

paint();
}

public synchronized void update(Object pixels, int line) {

//check consumer

if (_consumer != null) {

//copy integer pixel data to image consumer

_consumer.setPixels(0, line, width, 1, _model, (int[]) pixels, width * line, width);

//get component graphics object

Graphics graphics = getGraphics();

//draw image line to graphics context

graphics.drawImage(_image, 0, line, width, line + 1, 0, line, width, line + 1, null);

}
}

public void flush() {
_image.flush();
}

public void start() {
//check thread

if (_thread == null) {
//create thread
_thread = new Thread(this);

_thread.start();
}
}

public void run() {
//get component size
Dimension size = size();
//setup data
int width = 700;//size.width;
int height = 600;//size.height;

//setup color model
_model = new DirectColorModel(32, 0x00FF0000, 0x000FF00, 0x000000FF, 0);

//create image object
_image = createImage(this);

//call user main
started(width, height);

}

public void stop() {
//check thread is valid and alive
//stop thread
if (_thread != null && _thread.isAlive()) _thread.stop();
//null thread
_thread = null;
}

protected synchronized void paint() {
//get component graphics object
Graphics graphics = getGraphics();
//draw image to graphics context
if (_image != null && graphics != null) {

graphics.drawImage(_image, 0, 0, width, height, null);
}
}

public synchronized void addConsumer(ImageConsumer ic) {
//register consumer
_consumer = ic;

//set image dimensions
_consumer.setDimensions(width, height);

//set image Consumer hints for speed
_consumer.setHints(ImageConsumer.TOPDOWNLEFTRIGHT | ImageConsumer.COMPLETESCANLINES | ImageConsumer.SINGLEPASS | ImageConsumer.SINGLEFRAME);
//set image color model
_consumer.setColorModel(_model);
}

public synchronized boolean isConsumer(ImageConsumer ic) {
return false;

}

public synchronized void removeConsumer(ImageConsumer ic) {

}

public void startProduction(ImageConsumer ic) {
//add Consumer

addConsumer(ic);
}

public void requestTopDownLeftRightResend(ImageConsumer ic) {
//ignore resend request
}


int width;
int height;
Image _image;
Thread _thread;
ImageConsumer _consumer;
DirectColorModel _model;
}

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41051
    
  43
How are you trying to start it? There should be an HTML page containing an APPLET tag somewhere.


Ping & DNS - my free Android networking tools app
Niraj Jha
Ranch Hand

Joined: Feb 20, 2013
Posts: 63

you can put <applet .............../> tag as a comment in TinyPTC source file and run the same using appletviewer.
Bigrich Legend
Greenhorn

Joined: Mar 20, 2013
Posts: 3
The IDE's I have used all provide a HTML file with which to run the program. For example JCreator Pro has this as the applet in an HTML file called raytracer.html

"
<html>
<applet code = raytracer.Raytracer.class width="500" height="400">

</applet>
</html>"
When you run this file nothing happens.
Bigrich Legend
Greenhorn

Joined: Mar 20, 2013
Posts: 3
When I run the Applet in Intellij IDEA 12 I get the following error. Sorry for being such a pain but....

"C:\Program Files\Java\jdk1.7.0_17\bin\java" "-Djava.security.policy=C:\Program Files\IntelliJ IDEA 12.0.4\bin\appletviewer.policy" -Didea.launcher.port=7532 "-Didea.launcher.bin.path=C:\Program Files\IntelliJ IDEA 12.0.4\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.7.0_17\lib\ant-javafx.jar;C:\Program Files\Java\jdk1.7.0_17\lib\dt.jar;C:\Program Files\Java\jdk1.7.0_17\lib\javafx-doclet.jar;C:\Program Files\Java\jdk1.7.0_17\lib\javafx-mx.jar;C:\Program Files\Java\jdk1.7.0_17\lib\jconsole.jar;C:\Program Files\Java\jdk1.7.0_17\lib\sa-jdi.jar;C:\Program Files\Java\jdk1.7.0_17\lib\tools.jar;C:\Users\Big Rich\IdeaProjects\TryRay\out\production\TryRay;C:\Program Files\IntelliJ IDEA 12.0.4\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain sun.applet.AppletViewer file:/C:/Users/BIGRIC~1/AppData/Local/Temp/AppletPage5753440749455782422.html

Exception in thread "Thread-3" java.lang.NullPointerException
at raytracer.Raytracer.started(Raytracer.java:29)

This is Raytracer.java and the offending line reproduced here

" Sphere sphere = new Sphere(new Vector(0.0f, 0.0f, 2.0f));
sphere.color(new Color(1.0f, 0.0f, 0.0f));
sphere.lighting(true, true, 0.1f, 0.5f, 80.0f);
scene.objects[0] = sphere;"--------> Offending line

at raytracer.TinyPTC.run(TinyPTC.java:77)

"//setup color model
_model = new DirectColorModel(32, 0x00FF0000, 0x000FF00, 0x000000FF, 0);

//create image object
_image = createImage(this);

//call user main
started(width,height);" --------> Offending line


at java.lang.Thread.run(Thread.java:722)
"@Override
public void run() {
if (target != null) {
target.run(); --------> Offending line
}
}
"




 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Raytracer Applet will not start
 
Similar Threads
how to update image in Frame
Images on Applet?
Show semi-transparent image on top of other JPEG
Error In the code
Error (compile time) for JAVAX package