4 Replies - 886 Views - Last Post: 17 December 2009 - 05:37 AM Rate Topic: -----

#1 yasar83  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-December 09

Java Applet Problem

Posted 15 December 2009 - 03:12 AM

hi there,

I m working on a project presenting 3d models in a web page. I ve developed an applet to load vrml files. when I compile it, it works. but when I deploy it in a web page. It failesand gives the exception below:

java.lang.NullPointerException
at javax.media.j3d.Locale.addBranchGraph(Locale.java:162)
at com.sun.j3d.utils.universe.SimpleUniverse.addBranchGraph(SimpleUniverse.java:388)
at SimpleVrmlViewer$VRMLPanel.<init>(SimpleVrmlViewer.java:156)
at SimpleVrmlViewer.init(SimpleVrmlViewer.java:82)
at SimpleVrmlViewer.main(SimpleVrmlViewer.java:315)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)


how can I cope with the poblem?


thnx

This post has been edited by yasar83: 15 December 2009 - 03:15 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Java Applet Problem

#2 333OnlyHalfEvil  Icon User is offline

  • D.I.C Addict

Reputation: 24
  • View blog
  • Posts: 664
  • Joined: 20-March 09

Re: Java Applet Problem

Posted 15 December 2009 - 04:48 AM

Can we see your code? It's going to be hard to find the problem without it :)
Was This Post Helpful? 0
  • +
  • -

#3 yasar83  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-December 09

Re: Java Applet Problem

Posted 15 December 2009 - 05:03 AM

here they r, thnx

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#4 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,140
  • Joined: 14-September 07

Re: Java Applet Problem

Posted 15 December 2009 - 07:47 AM

No one is going to download and run an unknown file, post it here.
Was This Post Helpful? 0
  • +
  • -

#5 yasar83  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-December 09

Re: Java Applet Problem

Posted 17 December 2009 - 05:37 AM

//
// Import I/O libraries.
//
import java.io.*;
import java.util.StringTokenizer;

//
// Import the basic Applet/Application libraries.
//
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.awt.font.TextLayout;
import java.awt.image.BufferedImage;
import java.awt.Cursor;

//
// Import the SWING libraries to make buttons, etc.
//
import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.JFileChooser;
import javax.swing.filechooser.*;

//
// Import the 3D API libraries for viewing 3D environments.
//
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.behaviors.mouse.*;
import javax.media.j3d.*;
import javax.vecmath.*;


import org.jdesktop.j3d.loaders.vrml97.*; // j3d-vrml97.jar



public class SimpleVrmlViewer extends JApplet {
public static boolean IsApplet = true; //can be access by class name
private VRMLPanel rpanel;
private static String vrmlfilename;
//public Frame f;

public void init(String filename){
rpanel = new VRMLPanel();
getContentPane().add("Center",rpanel);
}

public void setAppType(boolean newtype) {
IsApplet = newtype;
}


public class VRMLPanel extends JPanel {
private TransformGroup objgrp = new TransformGroup();
private Transform3D tscale;


public VRMLPanel() {

setLayout(new BorderLayout());
Canvas3D canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
add("Center", canvas3D);

BranchGroup scene = createSceneGraph();

SimpleUniverse simpuniv = new SimpleUniverse(canvas3D);

simpuniv.getViewingPlatform().setNominalViewingTransform();
simpuniv.getViewer().getView().setBackClipDistance( 1000.0 );
simpuniv.getViewer().getView().setFrontClipDistance( 0.0001 );

simpuniv.addBranchGraph(scene);
}

public BranchGroup createSceneGraph() {

BranchGroup objRoot = createBranchEnvironment();

tscale = new Transform3D();
tscale.setScale(1.0);


objgrp = new TransformGroup(tscale);
objgrp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objgrp.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
objRoot.addChild(objgrp);

BoundingSphere bounds =
new BoundingSphere(new Point3d(0.0,0.0,0.0), 1000.0);

MouseRotate mouseBeh1 = new MouseRotate(objgrp);
objgrp.addChild(mouseBeh1);
mouseBeh1.setSchedulingBounds(bounds);

MouseZoom mouseBeh2 = new MouseZoom(objgrp);
objgrp.addChild(mouseBeh2);
mouseBeh2.setSchedulingBounds(bounds);

MouseTranslate mouseBeh3 = new MouseTranslate(objgrp);
objgrp.addChild(mouseBeh3);
mouseBeh3.setSchedulingBounds(bounds);

VrmlLoader newvrml = new VrmlLoader();
BranchGroup _newBG;
try {
_newBG = newvrml.load(vrmlfilename).getSceneGroup();
} catch ( java.io.FileNotFoundException e ) {
JOptionPane.showMessageDialog(this,"No file found");
return null;
}

_newBG.setCapability( BranchGroup.ALLOW_BOUNDS_READ );

BoundingSphere curBounds = new BoundingSphere(_newBG.getBounds());

double scalefactor = (500.0/curBounds.getRadius()) * 0.0005;

Transform3D scaleTrans = new Transform3D();
scaleTrans.setScale(scalefactor);

TransformGroup _newTG = new TransformGroup();
_newTG.addChild(_newBG);
_newTG.setTransform(scaleTrans);

objgrp.addChild(_newTG);

return objRoot;
}

BranchGroup createBranchEnvironment(){

BranchGroup branchRoot = new BranchGroup();

BoundingSphere bounds =
new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);

Color3f bgColor = new Color3f(1.0f, 1.0f, 1.0f);
Background bgNode = new Background(bgColor);
bgNode.setApplicationBounds(bounds);
branchRoot.addChild(bgNode);

Color3f ambientColor = new Color3f(0.9f, 0.9f, 0.9f);
AmbientLight ambientLightNode = new AmbientLight(ambientColor);
ambientLightNode.setInfluencingBounds(bounds);
branchRoot.addChild(ambientLightNode);

Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
Color3f light2Color = new Color3f(0.3f, 0.3f, 0.4f);
Vector3f light2Direction = new Vector3f(-6.0f, -2.0f, -1.0f);

DirectionalLight light1
= new DirectionalLight(light1Color, light1Direction);
light1.setInfluencingBounds(bounds);
branchRoot.addChild(light1); // add light to branch group

DirectionalLight light2
= new DirectionalLight(light2Color, light2Direction);
light2.setInfluencingBounds(bounds);
branchRoot.addChild(light2); // add light to branch group

return branchRoot;
} // end of "createBranchEnvironment" function


}

public static void main(String[] args) {
vrmlfilename = "c:\\c.wrl"; // u can find it at http://ysazak.atwebpages.com/C.wrl

final SimpleVrmlViewer sepy = new SimpleVrmlViewer();

sepy.init(vrmlfilename);
sepy.setAppType(true); // set application type whether applet or standalone

Frame f = new Frame();
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);} });

f.setTitle("Test VRML tool");
f.add(sepy);
f.pack();
f.setSize(300,300);
f.show();
} // end of main

} // end of class


=============================================

I cant run this applet in a web page.

and I have one more problem. I dont know how to put a jar file for library(such as j3d-vrml97.jar in this example) in my projet jar file and let the program import it automatically.

thnx
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1