java编写空白窗口,Java3D绘制空白窗口(不在applet中)

本文档描述了使用Java3D编程时遇到的一个常见问题:窗口有时显示为空白,直到重新调整窗口大小才会显示内容。问题根源在于重绘更新问题。解决方法是在程序开始时设置系统属性`sun.awt.noerasebackground`为`true`,或者通过命令行启动程序时添加相应参数。此解决方案可以解决白色背景的问题,确保Java3D内容正常显示。
摘要由CSDN通过智能技术生成

I'm trying to do something interesting using Java 3D, and i'm learning by official tutorials.

My problem is: sometimes it shows well without any problem but sometimes window is white and nothing shows until i resize the window.

How can i overcome this drawing-update problem?

Here is all code

import com.sun.j3d.utils.geometry.Sphere;

import com.sun.j3d.utils.universe.SimpleUniverse;

import javax.media.j3d.BoundingSphere;

import javax.media.j3d.BranchGroup;

import javax.media.j3d.DirectionalLight;

import javax.media.j3d.Transform3D;

import javax.media.j3d.TransformGroup;

import javax.vecmath.Color3f;

import javax.vecmath.Point3d;

import javax.vecmath.Vector3f;

public class Main {

public Main()

{

SimpleUniverse simpleUniverse = new SimpleUniverse();

BranchGroup group = new BranchGroup();

Sphere sphere = new Sphere(0.5f);

Color3f light1Color = new Color3f(0.7f,0.7f,5f);

BoundingSphere bounds = new BoundingSphere(new Point3d(0,0,0),100);

Vector3f light1Direction = new Vector3f(4.0f,-7.0f,-12.0f);

DirectionalLight light1 = new DirectionalLight(light1Color,light1Direction);

light1.setInfluencingBounds(bounds);

group.addChild(light1);

Transform3D transform = new Transform3D();

TransformGroup tg = new TransformGroup();

Vector3f pos = new Vector3f(0,0,-5);

transform.setTranslation(pos);

tg.setTransform(transform);

tg.addChild(sphere);

group.addChild(tg);

simpleUniverse.getViewingPlatform().setNominalViewingTransform();

simpleUniverse.addBranchGraph(group);

}

public static void main(String[] args) {

new Main();

}

}

解决方案

This is a common problem with heavyweight rendering components, like the Canvas3D that is used internally for Java3D.

You can avoid this by calling

System.setProperty("sun.awt.noerasebackground", "true");

as the first line of cour main method, or by starting your program with

java YourProgram -Dsun.awt.noerasebackground=true

(Websearches for noerasebackground bring further information about the details, but this flag should solve the issue of the white background)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值