Forum Stats

  • 3,838,499 Users
  • 2,262,376 Discussions
  • 7,900,672 Comments

Discussions

X3D Edit in Java code

3071418
3071418 Member Posts: 3
edited Dec 13, 2015 3:25PM in Java 3D

I'm using X3D Edit in Netbeans 8.1 and I'm planning on importing several dozen X3D models in. The application that I'm aiming to make to load different .x3d models when clicked. I'm programming the rest of the application in java, and the code that I have so far is as follows:

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

class MenuActionListener implements ActionListener {
     public void actionPerformed(ActionEvent e) {
          System.out.println("Selected: " + e.getActionCommand());
     }
}

public class HeritageTogeter{
     public static void main(final String args[]) {
          JFrame frame = new JFrame("3D Heritage Model Viewer");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          JMenuBar menuBar = new JMenuBar();
          
          //File Menu, F -Mnemonic
          JMenu fileMenu = new JMenu("Areas");
          fileMenu.setMnemonic(KeyEvent.VK_F);
          menuBar.add(fileMenu);

          //File->New, N - Mnemonic
          JMenuItem new MenuItem = new JMenuItem("Area1");
          newMenuItem.addActionListener(new MenuActionListener());
          fileMenu.add(newMenuItem);

          JMenuItem new MenuItem = new JMenuItem("Area2");
          newMenuItem.addActionListener(new MenuActionListener());
          fileMenu.add(newMenuItem);

          JMenu fileMenu = new JMenu("Types of Models");
          fileMenu.setMnemonic(KeyEvent.VK_F);
          menuBar.add(fileMenu);

          JMenuItem new MenuItem = new JMenuItem("Model1");
          newMenuItem.addActionListener(new MenuActionListener());
          fileMenu.add(newMenuItem);

          JMenuItem new MenuItem = new JMenuItem("Model2");
          newMenuItem.addActionListener(new MenuActionListener());
          fileMenu.add(newMenuItem);

          frame.setJMenuBar(menuBar);
          frame.setSize(1200, 650);
          frame.setVisible(true);

          //Set up first subpanel
          JPanel subPanel1 = new JPanel();
          subPanel1.setPreferredSize (new Dimension(600, 650));
          subPanel1.setBackground (Color.white);
          JLabel label1 = new JLabel ("Model One");
          subPanel1.add (label1);

          //Set up second subpanel
          JPanel subPanel2 = new JPanel();
          subPanel2.setPreferredSize (new Dimension(600, 650));
          subPanel2.setBackground (Color.white);
          JLabel label2 = new JLabel ("Model Two");
          subPanel2.add (label2);

          //Set up primary panel
          JPanel primary = new JPanel();
          primart.setBackground (Color.black);
          primary.add (subPanel1);
          primary.add (subPanel2);

          frame.getContentPane().add(primary);
          frame.pack();
          frame.setVisible(true);
     }
}

What I want to know is, is if there is a line or two of java code that will help import the .x3d models that I have saved on my USB into the application.

This discussion has been closed.