一些code延伸的小程序 [英] some code which extends applet
本文介绍了一些code延伸的小程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
喜
这是我的code(抱歉把这个)我真的需要你的帮助,你会帮我,我怎么才能从这里(init方法)删除小程序,我不喜欢使用小程序还我初学我做了什么但它并不能使它确定。谢谢
公共类RedGreenGriffin扩展的Applet { 保护Canvas3D C1 =新的Canvas3D(SimpleUniverse.get preferredConfiguration());
//私人Canvas3D C2 =新的Canvas3D(SimpleUniverse.get preferredConfiguration());
私有静态大型机MF;
保护SimpleUniverse实例U = NULL;
保护BranchGroup场景= NULL;
保护字符串URLString =http://www.java3d.org/saurus.obj;
保护浮球eyeOffset = 0.03F;
受保护的静态INT大小= 600;
公共无效的init(){
的setLayout(新的FlowLayout());
GraphicsConfiguration的配置=
SimpleUniverse.get preferredConfiguration();
串V =的getParameter(URL);
如果(ⅴ!= NULL){URLString = v的}
c1.setSize(尺寸,大小);
加(C1);
现场= createSceneGraph(0);
U =新SimpleUniverse实例(C1);
//这将移动ViewPlatform回位使
//场景中的对象可以被观看。
//u.getViewingPlatform()setNominalViewingTransform()。
u.addBranchGraph(场景); }
公共BranchGroup createSceneGraph(int i)以{
的System.out.println(创建情景:+ URLString);
//创建分支图的根
BranchGroup objRoot =新BranchGroup();
尝试{
的Transform3D myTransform3D =新的Transform3D();
myTransform3D.setTranslation(新Vector3f(+ 0.0,-0.15f,-3.6f));
的TransformGroup objTrans =新的TransformGroup(myTransform3D);
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
的Transform3D T =新的Transform3D();
TG的TransformGroup =新的TransformGroup(T);
tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objTrans.addChild(TG);
网址URL =新的URL(URLString);
ObjectFile F =新ObjectFile();
f.setFlags(ObjectFile.RESIZE | ObjectFile.TRIANGULATE | ObjectFile.STRIPIFY);
的System.out.println(关于加载); 场景S = f.load(URL);
的Transform3D myTrans =新的Transform3D();
myTrans.setTranslation(新Vector3f(eyeOffset,-eyeOffset,0F));
的TransformGroup mytg =新的TransformGroup(myTrans);
//mytg.addChild(s.getSceneGroup());
tg.addChild(mytg);
的Transform3D myTrans2 =新的Transform3D();
myTrans2.setTranslation(新Vector3f(-eyeOffset,+ eyeOffset,0F));
的TransformGroup mytg2 =新的TransformGroup(myTrans2);
//mytg2.addChild(s.getSceneGroup());
哈希表的表= s.getNamedObjects();
对于(枚举E = table.keys(); e.hasMoreElements();){
对象键= e.nextElement();
的System.out.println(键);
obj对象= table.get(键);
的System.out.println(obj.getClass()的getName());
一个Shape3D形状=(一个Shape3D)目标文件;
//shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
外观AP =新外观();
Color3f黑色=新Color3f(0.0,0.0,0.0);
Color3f红色=新Color3f(0.7f,.0f,.15f);
Color3f绿色=新Color3f(0F,.7f,.15f);
ap.setMaterial(新材料(绿色,黑色,绿色,黑色,1.0F));
外观AP2 =新外观();
ap2.setMaterial(新材料(红,黑,红,黑,1.0F));
浮transparencyValue = 0.5F;
TransparencyAttributes t_attr =
新TransparencyAttributes(
TransparencyAttributes.BLENDED,
transparencyValue,
TransparencyAttributes.BLEND_SRC_ALPHA,
TransparencyAttributes.BLEND_ONE);
ap2.setTransparencyAttributes(t_attr);
ap2.setRenderingAttributes(新RenderingAttributes());
ap.setTransparencyAttributes(t_attr);
ap.setRenderingAttributes(新RenderingAttributes());
// bg.addChild(AP);
shape.setAppearance(AP);
mytg2.addChild(新了Shape3D(shape.getGeometry(),AP2));
mytg.addChild(新了Shape3D(shape.getGeometry(),AP));
}
tg.addChild(mytg2);
的System.out.println(完成加载);
BoundingSphere所界限=
新BoundingSphere所(新的三维点(0.0,0.0,0.0),100.0);
Color3f light1Color =新Color3f(.9f,0.9F,0.9F);
Vector3f light1Direction =新Vector3f(4.0F,-7.0f,-12.0f);
平行光光线1
=新的平行光(light1Color,light1Direction);
light1.setInfluencingBounds(边界);
objTrans.addChild(光线1);
//设置环境光
Color3f ambientColor =新Color3f(1.0F,.4f,0.3f);
AmbientLight ambientLightNode =新AmbientLight(ambientColor);
ambientLightNode.setInfluencingBounds(边界);
objTrans.addChild(ambientLightNode);
MouseRotate行为=新MouseRotate();
behavior.setTransformGroup(TG);
objTrans.addChild(行为);
//创建的翻译行为节点
MouseTranslate behavior3 =新MouseTranslate();
behavior3.setTransformGroup(TG);
objTrans.addChild(behavior3);
behavior3.setSchedulingBounds(边界); KeyNavigatorBehavior keyNavBeh =新KeyNavigatorBehavior(TG);
keyNavBeh.setSchedulingBounds(新BoundingSphere所(
新三维点(),1000.0));
objTrans.addChild(keyNavBeh); behavior.setSchedulingBounds(边界);
objRoot.addChild(objTrans);
}赶上(的Throwable T){的System.out.println(错误:+ T);}
返回objRoot;
}
公共RedGreenGriffin(){
}
公共无效的destroy(){
u.removeAllLocales();
}公共静态无效的主要(字串[] args){ RedGreenGriffin S =新RedGreenGriffin();
如果(args.length大于0){
s.URLString = ARGS [0];
}
MF =新的大型机(S,尺寸大小);
}
}
解决方案
我想通过改变扩展的Applet
到延伸的JFrame 启动code>
然而,的JFrame
不需要或不使用公共无效的init()
方法,让你马上要移动的code别处。
只有使之成为一个GUI程序的目标,我的建议是要么:
- 您
的init()
方法重命名为frameInit()
- ...或只是在移动
的code的init()
到构造。
Hi this is my code (sorry for putting this) really I need your help would you please help me that how can I remove applet from this(init method)I don't like use applet also I am beginner I have done something but it doesn't make it OK. thanks
public class RedGreenGriffin extends Applet {
protected Canvas3D c1 = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
// private Canvas3D c2 = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
private static MainFrame mf;
protected SimpleUniverse u = null;
protected BranchGroup scene = null;
protected String URLString = "http://www.java3d.org/saurus.obj";
protected float eyeOffset =0.03F;
protected static int size=600;
public void init() {
setLayout(new FlowLayout());
GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();
String v = getParameter("url");
if (v != null) { URLString = v; }
c1.setSize(size, size);
add(c1);
scene = createSceneGraph(0);
u = new SimpleUniverse(c1);
// This will move the ViewPlatform back a bit so the
// objects in the scene can be viewed.
//u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
}
public BranchGroup createSceneGraph(int i) {
System.out.println("Creating scene for: "+URLString);
// Create the root of the branch graph
BranchGroup objRoot = new BranchGroup();
try{
Transform3D myTransform3D = new Transform3D();
myTransform3D.setTranslation(new Vector3f(+0.0f,-0.15f,-3.6f));
TransformGroup objTrans = new TransformGroup(myTransform3D);
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
Transform3D t = new Transform3D();
TransformGroup tg = new TransformGroup(t);
tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objTrans.addChild(tg);
URL url = new URL(URLString) ;
ObjectFile f = new ObjectFile();
f.setFlags(ObjectFile.RESIZE | ObjectFile.TRIANGULATE | ObjectFile.STRIPIFY);
System.out.println( "About to load" );
Scene s = f.load(url);
Transform3D myTrans = new Transform3D();
myTrans.setTranslation(new Vector3f(eyeOffset, -eyeOffset, 0F));
TransformGroup mytg = new TransformGroup(myTrans);
//mytg.addChild(s.getSceneGroup());
tg.addChild(mytg);
Transform3D myTrans2 = new Transform3D();
myTrans2.setTranslation(new Vector3f(-eyeOffset, +eyeOffset, 0F));
TransformGroup mytg2 = new TransformGroup(myTrans2);
//mytg2.addChild(s.getSceneGroup());
Hashtable table = s.getNamedObjects();
for (Enumeration e = table.keys() ; e.hasMoreElements() ;) {
Object key = e.nextElement();
System.out.println(key);
Object obj = table.get(key);
System.out.println(obj.getClass().getName());
Shape3D shape = (Shape3D)obj;
//shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
Appearance ap = new Appearance();
Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
Color3f red = new Color3f(0.7f, .0f, .15f);
Color3f green = new Color3f(0f, .7f, .15f);
ap.setMaterial(new Material(green,black, green, black, 1.0f));
Appearance ap2 = new Appearance();
ap2.setMaterial(new Material(red, black, red, black, 1.0f));
float transparencyValue = 0.5f;
TransparencyAttributes t_attr =
new TransparencyAttributes(
TransparencyAttributes.BLENDED,
transparencyValue,
TransparencyAttributes.BLEND_SRC_ALPHA,
TransparencyAttributes.BLEND_ONE);
ap2.setTransparencyAttributes( t_attr );
ap2.setRenderingAttributes( new RenderingAttributes() );
ap.setTransparencyAttributes( t_attr );
ap.setRenderingAttributes( new RenderingAttributes() );
// bg.addChild(ap);
shape.setAppearance(ap);
mytg2.addChild(new Shape3D(shape.getGeometry(),ap2));
mytg.addChild(new Shape3D(shape.getGeometry(),ap));
}
tg.addChild(mytg2);
System.out.println( "Finished Loading" );
BoundingSphere bounds =
new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
Color3f light1Color = new Color3f(.9f, 0.9f, 0.9f);
Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
DirectionalLight light1
= new DirectionalLight(light1Color, light1Direction);
light1.setInfluencingBounds(bounds);
objTrans.addChild(light1);
// Set up the ambient light
Color3f ambientColor = new Color3f(1.0f, .4f, 0.3f);
AmbientLight ambientLightNode = new AmbientLight(ambientColor);
ambientLightNode.setInfluencingBounds(bounds);
objTrans.addChild(ambientLightNode);
MouseRotate behavior = new MouseRotate();
behavior.setTransformGroup(tg);
objTrans.addChild(behavior);
// Create the translate behavior node
MouseTranslate behavior3 = new MouseTranslate();
behavior3.setTransformGroup(tg);
objTrans.addChild(behavior3);
behavior3.setSchedulingBounds(bounds);
KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(tg);
keyNavBeh.setSchedulingBounds(new BoundingSphere(
new Point3d(),1000.0));
objTrans.addChild(keyNavBeh);
behavior.setSchedulingBounds(bounds);
objRoot.addChild(objTrans);
} catch(Throwable t){System.out.println("Error: "+t);}
return objRoot;
}
public RedGreenGriffin() {
}
public void destroy() {
u.removeAllLocales();
}
public static void main(String[] args) {
RedGreenGriffin s = new RedGreenGriffin();
if (args.length > 0) {
s.URLString = args[0];
}
mf = new MainFrame(s, size, size);
}
}
解决方案
I'd start by changing the extends Applet
to extends JFrame
However, a JFrame
doesn't need or use a public void init()
method, so you'll want to move that code somewhere else.
With only the goal of making this a GUI program, my suggestion is to either:
- rename your
init()
method toframeInit()
- ... or just move the code in
init()
into the constructor.
这篇关于一些code延伸的小程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文