I'm trying to implement a small-scale strategy, taking turns game
implemented in Java, GUI is made with JFace and SWT.
My challenge is to write a GUI implementation of the world map,
where countries will act as clickable buttons. However, countries
have no fixed boundaries, no rectangular shape, and simply no way
I can think of to be described in a grid layout.
This is my first time trying to implement a project of this type,
please advise
If it's a tile based map (like at Civilization) or it's displayed as pixmap, you could save the ownership of each tile/pixel in a two-dimensional array. Just display the map a a simple, clickable pixmap in a canvas an add a MouseListener. If you get a click event at the coordinates (X,Y), you can just get your country like:
Country clickedCountry = myCountriesOnMap[X][Y];
... in your Listener implementing the MouseListener interface. myCountriesOnMap would be of type Country[][].
Of course, you will need an algorithm that will resolve the ownership for each tile/pixel at startup or if a territory gets conquered (I don't know, if this may happen). May be you will have to define your countries as polygons (like you would do it for a HTML map). I cannot help you on this, as I haven't done anything similar jet, but I'm sure you will find something on Google.
Greetings
Sacher
Try to use the OpenStreetMap data. It contains exact country borders and good image export possibilities.
The Key:border tag will show you all borders. You could extract it and calculate your clickable areas.
Related
I am fairly new to android studio and I am trying to make a car rental app for a university project.
I designed an app which has a horizontal slider containing blocks of different cars however I am unsure on how I would do this, I understand how the slider works and how to add elements to it.
I have a linear layout within the horizontal slider which will contain all of the blocks but I am unsure how to make a block of elements. Within the block it should have two buttons, an image and some text. Here is a picture of the design.
As you can see the available blocks are surrounded by a square. this is what I want, a small container which surrounds my data. Sort of like a div box in html.
Is there a way to do this?
Please just point me in the correct direction!
Many thanks!
It seems like cardviews can handle most of the grouping you want to do. I would reccomend looking into them because they incorporate a lot of material design components right out of the box.
https://developer.android.com/guide/topics/ui/layout/cardview
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.
I need to make an expandable list using java swing. I will attempt to demonstrate:
Unexpanded:
>[Expand me!]
>[And me!]
Expanded:
|[Expand me!]
>[Expand us too!]
>[Expand us too!]
>[Expand us too!]
>[And me!]
So, when you click on the "Expand me" portion of the list, another lists will drop down, possibly containing more expandable lists. If you were to click on it again, it's "sub-lists" would then retract. Pretty basic. And, as you can see, I am not looking for JComboBox, and I do not think JList can do this. If someone were to point me in the right direction, or give some programming examples, I would be grateful.
Thanks,
MirroredFate
How about using a JTree.
A control that displays a set of hierarchical data as an outline.
You can try using a JTable and put a button in the first column. When the button is clicked you add more data in the rows in between.
update
Something like this:
Or this
I think the first uses a JTree but that the idea.
BTW these two belong to JIDE Soft, check if it is feasible for you to buy a license:
http://www.jidesoft.com/products/grids.htm
Is not trivial to roll you own but is not impossible either.
check for TreeTable or one example or Outline, but with notice, that on official Java (SnOracle) pages any progress died ...,
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.
We would like to display all countries by continent (e.g. asia, europe, south america, africa ...) and capture user selection of a particular country within a continent. What kind of options are available for achieving this? This would be much similar to identifying countries on the map in freerice. I am not sure of the available options other than google maps, but not sure if this can be done using google maps api either. Need some direction on this.
EDIT: Ours is a Java EE 5 based application developed using java, seam, richfaces and deployed on a jboss 5.1 container
I am assuming that you want to create a clickable map for users to select a country - like this Map.
This can be done either using an HTML image map, or Flash. You would need to manually define the clickable hotspots in both cases.
If you only have a few selectable areas (rather then every country on the planet), using Google Maps could be used with custom markers (to blend it with your site style) each with their own click handlers to handle the selection.
You could accomplish this with HTML and CSS. And maybe use JavaScript for your functionality.
Here is an example:
http://www.cssplay.co.uk/menu/imap.html
I can only advise on the Java Swing case so here it goes. Your best bet is to first find a vector map of the world with different shapes for each country (or make one yourself). Then you can convert the shapes to java2D shapes, create a zoomable JPanel (easier than it sounds trust me) and simply have your mouse clicks checked against all the country shapes with the contains(Point p) method. (of course you will have to take into account the zoom transformations of the panel but as i said it is far easier than it sounds).