about preparing the map of Risk game with swing in java [closed] - java

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
i want to start coding a game project which is called "Risk" and my first aim is build the map correctly. So logically, each territory should be a JButton but JButton's are rectangular oriented. Moreover, i know that every territory should be a component so i can use mouse event listeners for each of them. well my question is
should i try to draw each territory with using coordinates, lines, shapes etc ? or
is there any way to draw and combine each territory regularly ?
On the other hand, this is the link for the map of the game.
Map of Risk

try to make fixed territories, so you mustn't have headaches with resizing your actual territory, only change the color of the territory you occupied recently, like in Dune2 was, if you know that game. And I think, definitively you should, and put that jbutton under the numbers on your map (or what will be definitively better, if you replace numbers with territory name and you'd put that button under that). I hope, my answer answered your doubts :)

I feel like it's going to be a lot of work. The easy way out would be to just put JButtons under the numbers.
If you still feel inclined to make irregularly shaped clickable areas, I suggest creating instances of Polygon (java.awt) for each country. They are made using arrays of x and y points that define the corners. Conveniently enough, there is a Polygon.contains(x, y) method that lets you know if (x, y) is in your polygon. If you use a larger JPanel that covers the entire map and get the mouse location relative to the JPanel, you can notify each country whether or not the mouse is inside it.

Related

Draw arrow connected to rectangle in Java [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I am trying to create an image that contains nodes (represented as rectangles) and a path. Two consecutive nodes in the path should be connected with a directed edge (line and an arrowhead at the end). Each line should start at the center of a rectangle and point towards the center of the next rectangle in the path.
The question is whether there is any easy way to calculate the point where each arrow hits the rectangle. Rectangles are not necessarily aligned horizontally and/or vertically, so this is not trivial.
I have managed to come up with a solution that works quite well, but I had to remember all the geometry I was taught at school. Maybe there is an easier way to do it with rotations, instead of calculating directly the end point?
In this example, the endpoints coincide with the centers of the connected rectangles; this obviates the need to calculate the intersection explicitly.
A similar approach is taken in the example cited here, using symmetric shapes.

What kind of components and techniques were used to create Bitdefender's GUI? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm curious as to what each of the components are on BitDefender's GUI. I've provided a picture in hopes that some could explain how this type of GUI was accomplished.
I'm not wanting to re-create the GUI, I'm just wanting to know if someone can name the components and perhaps tell me what they did to get that look and feel?
Thank you to anyone who spends the time explaining.
Swing's GUI framework is very flexible, most likely the arbitrary components such as the big round button at the top were simply custom components with a nice looking skin.
The rest just look to be standard components with custom skins, for example the big rectangles housing the antivirus/firewall/antispam/update are just jpanels or even unselectable buttons. There are many ways to make something look how you want, and there's never one standard way to do it.

Best Swing Solution for Schedule Event Calendar [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Friends!
I want to create a simple schedule event calendar like this one
Question: What can i use in Swing/AWT hiearchy in order to have such flexible grid.
P.S I was trying to do some solution in JTable direction with Custom CellRenderers but it was ugly. Maybe it can be something like JPanel-in-JPanel solution? What do you think?
This is not a simple solution and you have any number of options...
Because the content can expand over multiple rows, JTable isn't really a viable solution (there's probably any number of ways to do it, but each will become more complicated over time...and any solution I've seen doesn't take into account the current Look and Feel).
But if you're interested, you could take a look at
spantable (haven't used)
JTable Examples (haven't used)
You other choice would be to create a custom component capable of rendering the data model.
I, personally, would focus on an individual column, allowing it to be it's panel. With a custom layout manager, you could layout additional components based on the requirements of the data model.
Once you have that figured out, you would be able to expand the concept to allow for multiple rows.
This allows you greater flexibility in how the individual components are laid out and rendered, but is quite complex.
I would take a look at How to use Scroll Panes so you can see how row and column headers work ;)

Different ways to add OnClickListeners to Buttons in Android [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
What are the two ways to add Event Listeners to buttons in Android?
I have seen that you can specify the listener within the XML. I personally prefer this way as it usually involves less code. I know some people like to create an anonymous inner class...
I'm relatively new to programming in Android, so this question is purely to expand my knowledge. Be interested to hear what the community has to say on this!
Jack
The way I look at it, and I would imagine most would agree, if the button is used for a one time function then putting it in the xml is fine. If you have a button that is used in multiple places then it is better to set the onClick listener in the activity. I have a program that has buttons that do certain things depending on other variables in the program. If I call one function from xml then it won't always call the right one or take the appropriate actions. I hope this makes sense. And Tim is right, this question is on the borderline of not being a "constructive" question for SO but hopefully I answered it in a way for you that makes it more objective. Happy Programming!!!
All i've every used are inner classes because that's what all the tutorials i've seen show. I do know that you can also use "implements OnClickListener" on your class declaration and set all the click listeners in your code as one big case statement. It might look neater, but I don't think it follows the natural train of thought when writing an activity, especially one with a lot of buttons.
It depends on your tasks. In one case specify listeners in XML is enough. In other case, for example, when you create buttons dynamically in code, you will need to have defined listener in code or create anonymous inners. Another situation when the listener is used as parameter of method and you won't be able to specify it in XML.

Best API for simple 2D graphics with Java [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I'm not sure what the best api for simple 2d graphics with Java is. I know java.awt.Graphics2D was the standard but has it been replaced? Swing is the new API for Java GUI apps but it seems a bit heavy for what I want. What I really want is something like the C SDL library.
Java 2D (Graphics2D and friends) is indeed the best choice that I know of. Swing is actually implemented on top of Java 2D, so yes, if you want non-GUI-type graphics, Java 2D is the way to go.
If you want to have the least work possible if you're building a game (or even if not) use http://slick.cokeandcode.com/
UPDATE: The link has since changed to http://slick.ninjacave.com/
A Java binding to SDL can be found here:
http://sdljava.sourceforge.net/
Processing.org has some good easy-to-use 2D stuff (and 3D). It has a PApplet class that implements Applet from AWT together with a bunch of useful operations and works well together with Java2D.
If you just want to mess around with 2d graphics it has a "sketchpad IDE" where you don't need to put it in your java IDE if you just want to experiment with it.
Piccolo can be a good choice for drawing graphics. It is a 2D graphics toolkit that supports zoomable user interface. Available for both Java and .Net.

Categories

Resources