Skip to main content

New to JavaFX?

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
site_support
Offline
Administrator
Joined: 2011-07-06

This forum is for those that are new to JavaFX.

More experienced users should post questions in the OTN JavaFX 2.0 and Later forums, but please check in here once in a while to help out those who are new!

Welcome!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Peter-G
Offline
Joined: 2013-05-25

HELLO... Ello... ello... trailing off echo...
I've been trying to mix Swing and J3d to make a 3d drag and drop CAD program. It seems that I find posts from 2010 and before. I didn't want to spend this much time on it.
It seems the JCanves3D is heavyweight so I can't have 4 panels of it the same time and J3d doesn't seem to have a lightweight 3D panel. I thought adding 4 viewers with different views was going to be the hard part.

I want to make a panes that would have 4 panels (plus a properties panel) with Top/Bottom, Left/Right, Front/Back, top/left/front views.

Is it possible. I'v got this much done.
Can I have 4 views of the same scene?

<br />
//CAD3D<br />
/**<br />
 *<br />
 * Peter<br />
 * in NetBeans<br />
 */<br />
package cad3d;</p>
<p>import java.applet.Applet;<br />
import java.awt.*;<br />
import java.awt.event.*;<br />
import java.awt.Frame;<br />
import java.awt.GraphicsConfiguration;<br />
import javax.swing.*;<br />
import com.sun.j3d.utils.applet.MainFrame;<br />
import com.sun.j3d.utils.universe.*;<br />
import com.sun.j3d.utils.geometry.*;<br />
import javax.vecmath.*;<br />
import javax.media.j3d.*;</p>
<p>//import LayoutPkg.*;</p>
<p>public class CAD3D extends JApplet<br />
//public class CAD3D extends Canvas3D<br />
{</p>
<p>	/**<br />
	 * @param args the command line arguments<br />
	 */<br />
	public static void main(String[] args)<br />
	{<br />
        // TODO code application logic here<br />
		JFrame frame = new JFrame("CAD3D");<br />
		frame.setSize(600, 400);<br />
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
		frame.setDefaultLookAndFeelDecorated(true);<br />
		//frame.setJMenuBar(frame.getMenus());</p>
<p>		CAD3D program = new CAD3D();<br />
		program.setApp(false);<br />
		//JApplet program = new JApplet();<br />
		program.setBackground(Color.yellow);<br />
		program.init();<br />
		program.start();<br />
		frame.getContentPane().add(program, BorderLayout.CENTER);//makes 2 frames???</p>
<p>		//frame.setVisible(true);//would make 2 frames<br />
	}</p>
<p>	Boolean isApplet = true;<br />
	SimpleUniverse universe;<br />
	BranchGroup group;</p>
<p>	public CAD3D()<br />
	{<br />
	universe = new SimpleUniverse();<br />
        group = new BranchGroup();<br />
        Sphere sphere = new Sphere(0.5f);<br />
        group.addChild(sphere);</p>
<p>        Color3f color = new Color3f(0,0,2);<br />
        BoundingSphere bounds = new BoundingSphere(new Point3d(0,0,0),1000);<br />
        Vector3f direction = new Vector3f(5, -6, -10);<br />
        DirectionalLight light = new DirectionalLight(color, direction);<br />
        light.setInfluencingBounds(bounds);</p>
<p>	group.addChild(light);<br />
        universe.addBranchGraph(group);<br />
        universe.getViewingPlatform().setNominalViewingTransform();</p>
<p>	}</p>
<p>	public void setApp(Boolean b)<br />
	{<br />
		isApplet = b;<br />
	}</p>
<p>    /**<br />
     * Initialization method that will be called after the Applet is loaded<br />
     * into the browser.<br />
     */<br />
	@Override<br />
	public void init()<br />
    {<br />
        // TODO start asynchronous download of heavy resources<br />
		System.out.println("Init()");<br />
		if (isApplet)<br />
			System.out.println("Running as Applet");<br />
		else<br />
			System.out.println("Running as Application");</p>
<p>		try {<br />
			SwingUtilities.invokeAndWait(new Runnable(){<br />
				public void run() {<br />
					InitGUI();<br />
				}<br />
			});<br />
		} catch (Exception e) {<br />
			System.out.println("Error: " + e);<br />
		}<br />
	}</p>
<p>    // TODO overwrite start(), stop() and destroy() methods<br />
	@Override<br />
	public void start()<br />
	{<br />
	}</p>
<p>	@Override<br />
	public void stop()<br />
	{<br />
	}</p>
<p>	@Override<br />
	public void destroy()<br />
	{<br />
	}</p>
<p>	public void InitGUI()<br />
	{<br />
		setBackground(Color.blue);<br />
		setLayout(new BorderLayout());<br />
		//setLayout(new PercentageLayout pl = new PercentageLayout(2, 2, new int[] {50, 50}, new int[] {50, 50}, 0, 0, 0, 0, true));//rows, cols);<br />
		getContentPane().add(new TempPanel());//test nothing being added to JFrame (ok cause I can't add heavyweight to heavyweight)<br />
        //add(universe.getViewingPlatform());//where DO I add my panels<br />
		setVisible(true);<br />
	}</p>
<p>	class TempPanel extends Panel<br />
	{</p>
<p>		public TempPanel()<br />
		{<br />
			super();</p>
<p>			setLocation(200, 200);<br />
			setSize(new Dimension(50, 50));//w, h<br />
			int rval, gval, bval;</p>
<p>			rval = (int)Math.floor(Math.random() * 256);<br />
			gval = (int)Math.floor(Math.random() * 256);<br />
			bval = (int)Math.floor(Math.random() * 256);</p>
<p>			setBackground(new java.awt.Color(rval, gval, bval));<br />
			setVisible(true);<br />
		}<br />
	}</p>
<p>}</p>
<p>