Java : How to draw graphic object? - java

I am developing a small desktop application in Netbeans. The application is complete and working fine. A small description of application is as follow:
The application is basically an object manager, where user add new object, remove old objects and connect object with each other. What i did is that i simply add 3 panel and change its type to titled border. One for Add object one for remove and one for connect.
Status:
Every thing is working fine as expected.
What Left:
In order to make UI more appealing i added a new panel at the end and called it "Object Viewer". I am planing to visualize the steps which user performs e.g
If user add an object then i that pannel i will daraw a little
circle and fill it with green color
Similarly if user remove some object then again i will draw another
cricle and fill that with red
And when user connects two object then i will draw two circle and
connect them with a dotted line
This is my first java application, i only want to know how do i acheive this task. Some links or experience are highly appreciated

As for custom painting in swing, have a look here: http://download.oracle.com/javase/tutorial/uiswing/painting/
However, I'd suggest using a graph visualization library like JUNG etc. Using this you'd basically only have to define your object graph.

You can either do that manually with Java 2D, which I don't recommend, or, since you are using Netbeans (and I assume the Netbeans Platform, but this is not required), I would strongly suggest looking at the Netbeans Visual Library. It can do exactly what you want.

As Nico Huysamen said you can do that with Java 2D. But because it's your first Java application I strongly recommend to do it manually with this lybrary in order to understand how higer level lybraries work.

Related

3d modelling loading , updating and rendering in java

i am new to java 3d. i have encountered a situation like , i want to load ready made developed 3d model of any object [as an example shoe] developed in 3d modeling software like 3d studio max or Maya in my java program , update its texture or color properties etc. then render it and then display the updated model to the end user.
so i am asking all the 3d experts how should i proceed ahead to accomplish my goal ?
which input should i load into my program ?
how can i update the loaded model , render it and display the updated model to the end user ?
in simple story , i want to give my users ability to modify 3d model by their interactions as such ,
they provided 3d model of shoe for example in default colors and textures & some fields like sole color , if they choose color red then the loaded 3d model's sole is colored red (i.e. updated) and then displayed to end user with red color rubber sole shoe instead of default color shoe.
please, advice me to accomplish my goal.
Ok so first of all, complex objects are usually created using some 3D editing software like Blender or Art of Illusion. These programs can output the object into several different file formats, the most common being the .obj file format:
http://en.wikipedia.org/wiki/Wavefront_.obj_file
Another common format is .3ds, which in my experience is a lot more work than it's worth. They do make a .3ds file loader for Java3D, the page can be found here:
http://www.starfireresearch.com/services/java3d/inspector3ds.html
My advice for you is to just use the .obj file format, it is a lot easier to use. You can also just make your own parser for it which is not as hard as it sounds. This way you know exactly how your object is being loaded into the environment. Java does come with it's own parser, instructions on how to use it are here:
http://www.vrupl.evl.uic.edu/LabAccidents/java3d/lesson08/indexa.html
I have had a lot of trouble with files exported with Blender while using this file format unfortunately, they may have fixed the problem by now but I'm not sure. When I used to do a lot more 3D stuff I just used Art of Illusion, even know Blender is a lot more powerful. Blender can be run on a Mac but is a lot smoother on windows with the proper setup. Good luck! If you need some example code let me know and I would be more than happy to post some for you.
Art of Illusion:
http://www.artofillusion.org
http://www.artofillusion.org/documentation#
Blender:
http://www.blender.org
http://www.blender.org/education-help/tutorials/
Im not sure how you want the user to be able to change the object. If you want them to be able to change the color, or the type of shoe or whatnot that is not a huge deal. If you want the user to be able to change the lace length or something where you are changing the actual object's structure, that requires an in depth knowledge of 3D structure. If you want to change a color, just change the material. If you want to be able to change the type of shoe, just load a different shoe object. I hope this was helpful for you.
In the comments, you also talk about texture mapping, which in my experience is a lot easier to do in Blender than it is to do in Art of Illusion. I would probably use blender to accomplish this:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Textures/Mapping/UV
John
I assume you just want the user to select a different texture/color, right?
Then have a look at the Java3D tutorials out there, e.g. this one: http://www.java3d.org/tutorial.html
I further guess your shoe is actually a 2-part model, i.e. just the sole should get another color while the rest might get a different texture, right?
In that case, you'd need 2 models/shapes, each with its own appearance. Then, for example, alter the soles appearance as you like, e.g. by assigning a different material or changing the material's color.

Java gui that allows user to move fields

I'm trying to create a java gui, currently I'm playing around in the netbeans IDE using their gui creator, but I've also been reading a book about Swing and trying to learn it that way as well. Im hoping someone can help me with a problem I'm having. I'm attempting to allow users to have a "pool" of fields they can choose from (for instance a title, a paragraph, a text fiend, buttons, etc) and be able to move items from the pool into another potion of the window which would let them create their own layout. At this point I don't need these fields to DO anything, but I do want the user to be able to move them around and create their own layout. Is there any way to do this?
I think that to do this, you'd need to use a null layout on the container that would hold the movable components, and you'd have to give the components MouseListeners and MouseMotionListeners (conveniently combined into MouseAdapters) that are active when the program is in the set-up state, but then inactive when the program's components have been all set.
You could use the DragLayout from the tips4java website.

Multiple Page Development in Java with Eclipse and GWT

I have been writing some basic code for an application I am designing. I have learned the basics and gotten some simple database connection working with RPC calls etc. What I need to do now and am completely lost (as I am traditionally a c# developer with windows forms).
In c# if I wanted a new form I would just create it, and then call the show method.
How does one create multiple pages in GWT, and switch between them?
Thanks in advance,
Chris
The simplest way would be to
Make a new java class (GwtHome.java, GwtHelp.java etc)
Extend these classes by using the Composite class
Make the equivalent of a Master Page and add it to the rootPanel as a class with the appropriate headers, menu, footer and Content Placeholder (Could be any of the AbsolutePanel, VerticalPanel, HorizontalPanel objects provided by the GWT Framework)
By clicking on the menu clear the Placeholder and add the appropriate object of GwtHome, GwtHelp etc.
After getting aquanted with the above procedure, you might want to break up the code in many files using a design pattern as suggested by Andrei.
Simply clear the root panel (RootPanel.get().clear()) and add the widget for your new "page", the same way you added your first one.
If you're using LayoutPanels, do RootLayoutPanel.get().clear() instead.
Look at Activities and Places design pattern: https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces
I highly recommend it for a multipage GWT app. It explains pretty well how you create different "views", that are driven by their "activities", and tied to specific "places" (pages) that users can navigate.
Typically you use a LayoutPanel as your "page" container that occupies the entire available browser window. You split this LayoutPanel into 2-3 layers (zones), like top menu, side menu, main area. Each area contains one widget, usually a ScrollPanel, FlowPanel, or HtmlPanel. Then you use different widgets or HTML inside each of these widgets to display whatever you need. You may also create your own composite widgets that you can reuse in different pages.

UI for an intended XSL-FO designer in Java

I intend to write a XSL-FO designer in java for which i need to write an UI. The basic idea is to give the user a work pane wherein he/she can draw rectangles and these rectangles would in turn be associated to field containers in the underlying XSL-FO generator. Once the field container are done, the user should also be able to select any of the rectangles(field containers) created and add components into it. These will in turn be translated into field blocks that fall under the chosen field container.
Till now I have created a simple UI using JFames with mouseListeners hooked to them so that i can have users draw the rectangles on the work area.
Im stuck at the point on how to implement the part where the user selects one of the rectangles created in the previous steps.
Given the intent of the designer, is it possible to accomplish this using Jframes ?
Any pointers/suggestions on how i can achieve the motive of this designer would be of great help !
Please excuse me if any part of this post is noobish. I am one when it comes to UI.
JInternalFrame might be a starting point. You can connect them, as shown here, and add arbitrary components as required.

Java: Interface with squares (to drag), lines (to link the squares) and animation (square follows the line)

I'm starting to create a Industrial Simulation (IS) interface, using Java.
The problem I'm pointing here is the interface.
A IS interface will have some big squares (geometrical figure) (unfilled, instead of it they will have their "names" inside it), one or more lines linking the squares, and while time will be going, some "mini-squares" will get out of one big square to another, following the line that links both.
I have to construct a interface that is able to have either the geometric (square) figures and the animation with the "minisquares" following the link (that will be the line).
Is there any API, or tool, whatever, in java, that could help me starting this part of the project?
If you can use javafx... runs on the JVM... that might be easiest way. Here's a link to a tutorial for animating along a path
Otherwise I guess you'll be looking at Swing, but I suspect it's a lot trickier. Here's a similar link.
Visual editors like Matisse can help you get started with layout etc., but I don't know of anything that will let you point-and-click your way round animation.

Categories

Resources