Java 3D Tutorial: 6. Java 3D and user interface

Source: Internet
Author: User

Ava 3D and user interface

Canvas3d

Each area that can draw a 3D image is called canvas3d. It contains the rectangle of the object view in your environment (universe. You put the canvas into a frame, so you create an environment that can be displayed in the canvas.

The following example shows how to create a canvas in a frame with labels at the upper and lower ends. The program can run as an applet or application.

 1 import com.sun.j3d.utils.universe.SimpleUniverse; 2 import com.sun.j3d.utils.geometry.ColorCube; 3 import javax.media.j3d.BranchGroup; 4 import javax.media.j3d.Canvas3D; 5 import java.awt.GraphicsConfiguration; 6 import java.awt.BorderLayout; 7 import java.awt.Label; 8 import java.applet.Applet; 9 import com.sun.j3d.utils.applet.MainFrame;10 public class CanvasDemo extends Applet11 {12     public CanvasDemo()13     {14         setLayout(new BorderLayout());15         GraphicsConfiguration config =16             SimpleUniverse.getPreferredConfiguration();17         Canvas3D canvas = new Canvas3D(config);18         add("North", new Label("This is the top"));19         add("Center", canvas);20         add("South", new Label("This is the bottom"));21         BranchGroup contents = new BranchGroup();22         contents.addChild(new ColorCube(0.3));23         SimpleUniverse universe = new SimpleUniverse(canvas);24         universe.getViewingPlatform().setNominalViewingTransform();25         universe.addBranchGraph(contents);26     }27     public static void main(String[] args)28     {29         CanvasDemo demo = new CanvasDemo();30         new MainFrame(demo, 400, 400);31     }32 }

Java 3D and swing

Canvas3d leverages your computer's graphics card to enhance performance. Unfortunately, this also means that it cannot work well with Sun's swing user interface controls. These controls are called "lightweight. These lightweight controls are hidden by canvas3d even at the front end.

We have several solutions to this problem:

● If you place lightweight and heavyweight controls in different containers, they can be mixed on one screen.

● If you use the pop-up menu, the static jpopupmenu method can solve this problem:
Setdefalightlightweightpopupenabled (false );

You can also use the old AWT controls to replace swing.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.