• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Displaying an X3D image within a subpanel

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm writing code for a Java project that displays X3D models and I'm using an XML parser to import the X3D files into the project. I've used some Subpanels to show where the X3D models would go when they're selected. The code that I have so far in the main class is:



The XML parser that I have so far is:





As you can see the XML parsers have a different layout as I used it to show a file called employees.xml and I haven't changed it round yet. The question that I'm asking is, how do I display the X3D models in the subpanels that I have in the main class at the top.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a lot of code, so please excuse me if I missed it when scrolling through it, but... where would I find some X3D models in that code?

By the way, on the subject of "a lot of code", it seems to me that your code could be made a lot shorter if you used some arrays.
 
Matthew Yeend
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The X3D model that I've got in is in the first XML parser code called possi04.x3d
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean the DomParserExampleJava class? But that's a Java application. You should turn it into a class whereby you can extract the parsed values from an object of the class after it parses the XML document.
 
Matthew Yeend
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah that class. And how would I go about turning it into a class? I'm sorry if it seems a silly question
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh dear. You have jumped into two swamps full of alligators at the same time. First there's Swing, which isn't an easy thing to get started with. And using Swing properly requires a reasonably good knowledge of object-oriented principles, the other swamp I referred to. So I'd really recommend spending some time going through this introductory tutorial: Classes and Objects.

However your XML parsing code looks reasonably good to me, so I don't think you have an XML problem. I'm going to move this thread to the Beginning Java forum instead.
 
Bartender
Posts: 732
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I've used some Subpanels to show where the X3D models would go when they're selected.


No, you have created 36 panels of size 135x135, and added all of them to a JPanel whose default layout manager is FlowLayout. So they will ba laid out in one row until there is no more room, then wrap to the next row. Changing the size of the main frame will re-arrange those panels.

Also, you call first call frame.setSize(1200,650) which will allow for 8 of the subpanels per row so it takes 5 rows to dhow all of them, but that requires a minimum of 675 pixels in height to show them - without taking into account the size of the menu -so some of the rows will be clipped. Then you call frame.setVisible(true) before you add any of the panels to the primary panel, so none would be visible initially.

Then after you add the subpanels to the primary panel you call frame.pack(), which causes your setSize() call to be ignored and everything will be laid out in their preferred size, and call frame.setVisible(true) again.

And none of this is done on the Event Dispatch thread, so the visible look may be all fouled up.
 
Matthew Yeend
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Subpanels are in place where I want to X3D models to be shown, so the X3D models would be where the Subpanels are.

So I'd need to research into Swing and understand that, along with object oriented principles? So the XML parsing code looks okay? How would I change it to parse X3D through it so it displays?
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Yeend wrote:So the XML parsing code looks okay?



As far as I can tell it looks okay. Whether it extracts the correct data or not, I can't tell.

How would I change it to parse X3D through it so it displays?



You wouldn't do that. You would write something which displays data, and have it get the data from an object which includes that parsing code. One of the key architectural principles of Swing is that the data model should be kept separate from the display components. Have a look at the Wikipedia article about Model–view–controller to see how that works.
 
Matthew Yeend
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you'd suggest writing code that displays the data, and have it import the data from an object that includes the parsing code?
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, that would be the "controller" part of the application which gets your parsed data from the "model" and updates some display components (the "view").
reply
    Bookmark Topic Watch Topic
  • New Topic