Java 3D的和用户界面 : 三维画板 « 三维图形动画 « Java

En
Java
1. 图形用户界面
2. 三维图形动画
3. 高级图形
4. 蚂蚁编译
5. Apache类库
6. 统计图
7. 
8. 集合数据结构
9. 数据类型
10. 数据库JDBC
11. 设计模式
12. 开发相关类
13. EJB3
14. 电子邮件
15. 事件
16. 文件输入输出
17. 游戏
18. 泛型
19. GWT
20. Hibernate
21. 本地化
22. J2EE平台
23. 基于J2ME
24. JDK-6
25. JNDI的LDAP
26. JPA
27. JSP技术
28. JSTL
29. 语言基础知识
30. 网络协议
31. PDF格式RTF格式
32. 映射
33. 常规表达式
34. 脚本
35. 安全
36. Servlets
37. Spring
38. Swing组件
39. 图形用户界面
40. SWT-JFace-Eclipse
41. 线程
42. 应用程序
43. Velocity
44. Web服务SOA
45. 可扩展标记语言
Java 教程
Java » 三维图形动画 » 三维画板屏幕截图 
Java 3D的和用户界面
Java 3D的和用户界面


/*
The Joy of Java 3D

by Greg Hopkins

Copyright Copyright 2001


*/

/*
Canvas3D

Each area where three-dimensional graphics can be painted is called a Canvas3D.  This is 
a rectangle that contains a view of the objects in your universe. You place the canvas 
inside a frame, then you create a universe to be displayed in the canvas.

The following example shows how to create a canvas in a frame with labels at the top and 
bottom. The program can be run as either an applet or an application. 


Java 3D and Swing

The Canvas3D takes advantage of your computer's graphics card to increase performance. 
Unfortunately, this means that it does not mix very well with Sun's swing user interface 
components. These components are called "lightweight" Lightweight components can be 
hidden by a Canvas3D even if they are supposed to be at the front.

There are several solutions to this problem:

* You can mix lightweight and heavyweight components on the same screen if you keep them in separate containers. 

* if you use Popup menus, a static function on JPopupMenu fixes the problem:
setDefaultLightWeightPopupEnabled(false);

* You can use the older AWT components insteadof swing.


*/

//



import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import java.awt.Label;

import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;

import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class CanvasDemo extends Applet {

  public CanvasDemo() {

    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse
        .getPreferredConfiguration();
    Canvas3D canvas = new Canvas3D(config);
    add("North"new Label("This is the top"));
    add("Center", canvas);
    add("South"new Label("This is the bottom"));
    BranchGroup contents = new BranchGroup();
    contents.addChild(new ColorCube(0.3));
    SimpleUniverse universe = new SimpleUniverse(canvas);
    universe.getViewingPlatform().setNominalViewingTransform();
    universe.addBranchGraph(contents);
  }

  public static void main(String[] args) {
    CanvasDemo demo = new CanvasDemo();
    new MainFrame(demo, 400400);
  }
}

           
       
Related examples in the same category
1. 打印Canvas3D
2. 关闭试镜关闭试镜
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.