For my Comp Sci assignment, I have to make a world that has Village objects connected via Roads in a graph data structure.Gnomes, each running their own thread traverse this world from one village to another using the shortest path. This whole thing needs to have a GUI, however.
Basically I need to have a grid with the villages on the intersections. Something like this ( without the numbers):
(source: kwiznet.com)
The villages have to be interconnected with roads. If it is not too difficult, roads should be deletable if they are not the only road connecting the village to the rest of the graph. This would be done via clicking.
There must also be an option to add villages by clicking on the graph, and select current villages, deleting them.
Basically:
Graph data structure is translated to GUI grid
Roads and Villages can be selected
Selected items can be deleted
Could you please just point me to what I need to research as I am new to GUIs? Such as the best layout manager, in what way to handle action events, how to draw a grid, etc. I just need a brief outline.
This is a HUGE question, although that's not really your fault. Here goes:
Read through the Java Swing Tutorial.
Learn a bit about MVC. Link1 Link2
Understand that Swing is not thread safe.
Then:
The best layout manager for your graph is likely the grid layout.
Probably you should add a JButton to each node so you can just click on it. JButtons can be made to look like anything so don't be put off by how they look by default.
Then MOST IMPORTANT: probably you should use a GUI Builder tool of some sort. I recommend NetBeans Matisse if you are new.
Now you should try all of that, and ask a SPECIFIC QUESTION when you get stuck. Good luck!
Related
I am just learning AWT / Swift / JavaFx recently and I feel like I have learned a lot but have barely scratched the surface. There might be a much easier way to do this BUT, I am trying to make a GUI button in eclipse that calculates the distance between two objects that the user creates. Lets call them Robots for now. So, I have one button that allows the user to create the Robots and it stores them in a DefaultListModel (listModel) and displays them in a Jlist (list) below the buttons. When the user then clicks on a robot, another button becomes actice and allows them to calculate the distance between them (one of the parameters of the robots is their location on a grid). I have all that worked out but my problem is that I am trying to make it to where they have to select two different Robots. At first I thought I could let them select two Robots and then make the computeDistance button becomes active, but I am not really sure how to do that because the only way I can select more than one object in the JList is to cntrl click and I don't want the user to have to know that trick.
My next idea was to allow the user to have one Robot selected and then give them a popup window displaying the other Robots and have them select one. Via showOptionsDialog, I have discovered how to make a custom JOptionPane, so I thought, why not make them buttons (probably will look awful, but I don't know how to make anything other than JOptionPane.showXxx at this point (like I said, only skin deep so far). Have tried consulting the javadocs, but right now that is a LOTTT to take in and have read a decent amount, I thought.
Ok, sorry if this is long, but is there a way, using my DefaultListMethod to make custom buttons? I tried a bunch of ways by creating Object[] options = {list.elements()}; etc but that doesn't work. Any help would be much appreciated!
I'm trying to write a program that has several navigation buttons, for example the classical "Back" and "Forward" buttons. I would need a way to let the user to navigate through the different pages (JPanels, to be true). How can I do that? Or better, how would a real programmer (I'm a beginner jet) do that? I'm using for the moment CardLayout and I thought to store the "path" that the user does and use previous() and next() methods that CardLayout provides. What about this solution? Is it a bit "dummy"? Does a kind of "navigation pattern" exist?
You may simply store created JPanels in a List or a Stack as long as they keep they internal states unchanged by any other JPanels. However this might be a little resources hungry, thats why its better to store just internal state of an object rather than whole object.
Take a look at Memento Pattern:
http://en.wikipedia.org/wiki/Memento_pattern
I would like to ask what swing control to use in case below.
I am working on some school project and developing application for digital evolution. There will be big number of processes and I would like to chose only single one. For this one I will draw a graph.
I think JComboBox is not the good solution, because there could be many processes (like hundreds). What is the best way for this selection?
Go for Paging or pagable JTable(Table) Model for large data set
JScrollPane will help you out for scrolling around records
Here is a tutorial about how to achieve it
I am creating a RadialTreeLayout of a graph using JUNG. Now I want to see one more RadialTreeLayout of another graph (with same type of vertices and edges) as a part of the main layout.
The problem is not of uniting the two graphs (as explained here) but actually of visualizing a similar layout in the main window.
Few ways I thought of doing that, but not sure if they are feasible or not. e.g. to create one such node which actually is the layout (and can be seen with zooming in) or when one clicks on that node, another layout appears in a separate window.
Or are there existing ways to do that in JUNG already. Any help/suggestions would be appreciated.
Check out the demos. I don't remember offhand which one, but at least one demonstrates visualization of multiple graphs.
I am creating a GUI program using MVC which should look like this..
alt text http://img137.imageshack.us/img137/6422/93381955.jpg
I have created a Window and Panel class. I am thinking of creating the Input and Display tabs in the Panel class and then creating two more classes, InputPanel and DisplayPanel. So the InputPanel will contain the stuff in this picture under the Input tab and same for the Display tab. Is there a better way to design this?
Also, since there are 3 sections in the Input tab (Name and sentence, crime, button), should I create 3 panels or just 1 panel containing all those?
Thanks
To answer your specific question about using three panels instead of 1, I would suggest two. There's rarely a need to create a panel just to create a single widget. So, one widget for the name and sentence, one for the crime.
As for the question about "is there a better way to design this"?... It sounds like you are learning, so I suggest you don't focus too much on the perfect way to do it. Stick with your original design then after the task is done ask yourself what worked* and what didn't. With that information you'll be able to decide for yourself whether what you did was the right design.
There usually isn't a "best" when designing GUI code -- there are many ways to solve the problem. What you've described sounds like a perfectly good way to attack the problem
(*) "worked" in this context means, was it easy to code? Did it allow you to achieve the layout you desired? Does it make the code maintainable over time if, for example, a requirement comes down to reorganize the GUI?.
Bryan gave good advices, I will just add that ergonomics isn't an exact science, although experience helps there.
Tabs are nice, eg. to separate settings, or group in a same panel (toolbox for example) different sets of tools (layers, colors, brushes...).
But they might not be adapted to all workflows. But we are lacking information about the role of the Display tab. Is it supposed to list all crimes in a table? Can't the table, if any, be below the controls?
As hinted by Bryan, it is better to design the GUI, then to test it, like would do a real user. Do you find the workflow easy to understand? (make somebody else to test it!) Does the usage feels natural? Is it fast to use?
Then you can adjust the design in light of these observations.
You were right to create InputPanel and DisplayPanel as seperate classes.
As for further splitting those panels? Yes you should further split them up, but not into separate classes. You should add jPanels inside of your InputPanel, and DisplayPanel, and group the controls within those internal jPanels.
Please let me know if you would like me to clarify what I mean.