现在的位置: 首页 > 综合 > 正文

J3d终于调试成功了,感觉java在UI设计方面,还是很复杂

2018年05月11日 ⁄ 综合 ⁄ 共 3654字 ⁄ 字号 评论关闭

 鼓捣了半天,终于成功了,j3d是sun的官方扩充包,主要用于3d显示,调用的是本地库,所以速度算不上慢,但是编写起来也是有一定的复杂度的,如果有一个好一点的框架就好了,只能给爱好者玩玩了,java做企业web还是更靠点谱,不过我对企业什么的很没兴趣,而且还发现了一个IBM的IFRAME包,不是html里的<iframe></iframe>里的标签的意思,是一个基于swing的UI框架,可以设计出比较复杂的UI,效果还不错,透明框架什么的,还有不规则框架都可以做,不过也相当难写,这是我的亲身体会,额!

重新购买了域名和空间,希望别再和谐我的博客了,我一个悲剧程序员容易吗我,我真的什么也不知道,什么也不知道阿!

 

Code:
  1. import java.awt.*;  
  2. import java.awt.event.*;  
  3. import javax.swing.*;  
  4. import javax.media.j3d.*;  
  5. import javax.vecmath.*;  
  6. import com.sun.j3d.utils.universe.*;  
  7. import com.sun.j3d.utils.geometry.*;  
  8.   
  9. public class Titles {  
  10.   
  11.     public static void main(String[] args) {  
  12.         Titles t = new Titles();  
  13.         t.setUp();  
  14.     }  
  15.   
  16.     public void setUp() {  
  17.         JFrame jf = new JFrame("Welcome");  
  18.         // kill the window on close  
  19.         jf.addWindowListener(new WindowAdapter() {  
  20.             public void windowClosing(WindowEvent winEvent) {  
  21.                 System.exit(0);  
  22.             }  
  23.         });  
  24.         JPanel panel = new JPanel();  
  25.         panel.setLayout(new GridLayout(1122));  
  26.   
  27.         GraphicsConfiguration config = SimpleUniverse  
  28.                 .getPreferredConfiguration();  
  29.         Canvas3D canvas3D = new Canvas3D(config);  
  30.         canvas3D.setSize(360160);  
  31.         SimpleUniverse universe = new SimpleUniverse(canvas3D);  
  32.         BranchGroup group = new BranchGroup();  
  33.         addObjects(group);  
  34.         addLights(group);  
  35.         universe.getViewingPlatform().setNominalViewingTransform();  
  36.         universe.addBranchGraph(group);  
  37.         panel.add(canvas3D);  
  38.         jf.getContentPane().add(panel, BorderLayout.CENTER);  
  39.         jf.pack();  
  40.         jf.setVisible(true);  
  41.     }  
  42.   
  43.     public void addLights(BranchGroup group) {  
  44.         BoundingSphere bounds = new BoundingSphere(new Point3d(0.00.00.0),  
  45.                 1000.0);  
  46.   
  47.         Color3f light1Color = new Color3f(1.0f, 1.0f, 1.0f);  
  48.         Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);  
  49.         DirectionalLight light1 = new DirectionalLight(light1Color,  
  50.                 light1Direction);  
  51.         light1.setInfluencingBounds(bounds);  
  52.         group.addChild(light1);  
  53.   
  54.         // Set up the ambient light  
  55.         Color3f ambientColor = new Color3f(.1f, .1f, .1f);  
  56.         AmbientLight ambientLightNode = new AmbientLight(ambientColor);  
  57.         ambientLightNode.setInfluencingBounds(bounds);  
  58.         group.addChild(ambientLightNode);  
  59.     }  
  60.   
  61.     private void addObjects(BranchGroup group) {  
  62.         Font3D f3d = new Font3D(new Font("TestFont", Font.PLAIN, 2),  
  63.                 new FontExtrusion());  
  64.         Text3D text = new Text3D(f3d, new String("Java3D.org"), new Point3f(-3.5f,  
  65.                 -.5f, -4.5f));  
  66.            
  67.         text.setString("Java3D.org");  
  68.         Color3f white = new Color3f(1.0f, 1.0f, 1.0f);  
  69.         Color3f blue = new Color3f(.2f, 0.2f, 0.6f);  
  70.         Appearance a = new Appearance();  
  71.         Material m = new Material(blue, blue, blue, white, 80.0f);  
  72.         m.setLightingEnable(true);  
  73.         a.setMaterial(m);  
  74.   
  75.         Shape3D sh = new Shape3D();  
  76.         sh.setGeometry(text);  
  77.         sh.setAppearance(a);  
  78.         TransformGroup tg = new TransformGroup();  
  79.         Transform3D t3d = new Transform3D();  
  80.         Transform3D tDown = new Transform3D();  
  81.         Transform3D rot = new Transform3D();  
  82.         Vector3f v3f = new Vector3f(-1.6f, -1.35f, -6.5f);  
  83.         t3d.setTranslation(v3f);  
  84.         rot.rotX(Math.PI / 5);  
  85.         t3d.mul(rot);  
  86.         v3f = new Vector3f(0, -1.4f, 0f);  
  87.         tDown.setTranslation(v3f);  
  88.         t3d.mul(tDown);  
  89.         tg.setTransform(t3d);  
  90.         tg.addChild(sh);  
  91.         group.addChild(tg);  
  92.           
  93.     }  
  94. }  

 

抱歉!评论已关闭.