I've worked my way through the tutorial series of jme and feel like I've understood the basics. Now I would like to create a first very simple game. Nothing fancy just a simple test scenario: The player should be able to move an object. Then I would like to expand it. However I don't know how to start. It's hard to explain but I just don't know where to put my code. The manual says that there are "controls" (implemented as interfaces) that let you hook your code up to frequent update calls or other events (that's what I understood) but I can't grasp how to use them.
More detailed description. You could skip this:
To get the point clear - I'm coming from the engine Unity3d. The usage was quite pleasant, the community helpful and the documentation great. But you have to spend about 1000$ to get the full version and be allowed to use pro features (shadows, custom shaders, some advanced tools,...). After a while the temptation of open-source was simply to big. In unity3d you basically have an advanced 3d editor and a scene graph. You can place objects in the scene and access and modify them over the scene graph. You can use predefined objects such as lights or particle systems and change them to suit your needs but most things you use are custom made and puzzled together by different components: a mesh, a collider, a few scripts. And this is where your code comes to work. In unity3d your program is split into small scripts and these are added to the objects of each scene. The scripts have access to the underlying engine, the properties of their object and can use a special framework for math, networking,... Each script can also define functions to be called in certain events: update(), onCollisionEnter(Collider other), onTriggerEnter(Collision other), ...
This was extremely easy to use. Admittedly huge architectures can be difficult to implement but this setback was complemented by very high productivity.
Frankly: I need advice how to structure a simple game with JME.
What architecture do you recommend ?
How are controls used ?
I would appreciate a link to a tutorial (I already read the flagrush series) or any other resource.
Thank you for your help
I'm not sure how well you read the tutorials but they quite literally explain the things you asked for.
Anyway, you code everything so you don't add an object and put code in it you instance an object trough code.
Input is handled by the InputManager, as long as you still use SimpleApplication as foundation you don't have to think about it and use it the way you learned in this tutorial
Related
This is kind of an abstract question.
In general, how do I go about learning a library? I don't mean learning how to use it, I mean learning the design and the details of the interworkings.
For some more detail about what I mean, here is the situation that prompted me to ask this question.
My service has the ability to record a call's dependent data into a json blob. I'm working on some code that reads in the json blob, reconstructs the objects in the blob, and replays the call from the blob. The issue that I'm running into is that when one of the objects is being reconstructed I'm getting an exception that says "Field X cannot be null," but the field is not null in the json blob so obviously something is wrong. The stack trace is about 15 levels deep inside the Jackson library, so it's not easy to tell what's going wrong.
I honestly don't mind learning how the library works to fix this problem. I think it will be interesting. I just don't know where to start. I feel like I was just handed a big project full of files with no direction other than that, at a high level, I can imagine how serializing and deserializing Java objects would work.
In general, how do I go about learning a library? I don't mean
learning how to use it, I mean learning the design and the details of
the interworkings.
Generally, mature libraries (like Jackson as you mentioned in your question) have good introductions in their documentation as to their design. You can then drill down deeper for "the details of the interworkings" going as far as source code if needed.
I think a good general order in learning a library is the following
1. Introductory/high level/design view
2. More specific sections
3. Source code (rarely should have to go to this level)
I generally don't find myself as low as the source code view when learning a library...after all, if you're down at that level, one could argue you could write the code yourself...libraries are there to abstract away all the code needed to accomplish a task (like JSON data-binding in the case of Jackson).
I like how the jackson-databind page lays things out nicely in a general-specific order...you can get up and running right away and drill deeper if needed further down the page.
Give yourself time to learn a library...it doesn't happen overnight...
In general, how do I go about learning a library? I don't mean learning how to use it, I mean learning the design and the details of the interworkings.
In general, you don't. That's the point. A well-written library has a stable and well-documented interface. When it comes to Java libraries, "well-documented" means exactly one thing: Javadoc. You can browse the Javadoc to get an overview of the library, and you can attach the Javadoc to your project in your IDE so you can view the documentation for a class or method just by hovering your mouse pointer over it. The library's clients (the programs that use it) and the programmer writing them should not know or care how it works internally. If you know how it works, you may come to depend on how it works, and then your programs will break when it changes.
If you want to make sure a library isn't doing something stupid or malicious, or you want to study it for educational purposes, the best thing to do is read the source.
I think the best way is reading the Library's source code not just reading reference file.I suggest you use Java Decompiler or Jad tools to get source code.
I know this question is vague, but I'll try to make myself clear.
I am starting a Java project involving a Swing GUI. I want to follow the MVC pattern, and could use some help from a framework to organize the project's architecture. I was thinking of using Griffon, though I suppose others might do the trick.
So, is it a good idea to use a framework in terms of:
Programming efficiency: Of course, it will be improved... most of the time. More precisely, what if the project is a small one? Or a large one? What if I'm already very familiar with Java and Swing? What if I'm not? What if the project has to be maintained by someone who knows nothing about the framework I used?
Learning value: Will I merely "learn how to use the framework", instead of learning more about Java and Swing in a different environment?
Professional value: Would companies prefer a developer who knows "more" frameworks (even if they might not be the ones they intend to use) to a developer who knows the "traditional" approach better?
I found little information elsewhere, which is surprising, considering how big this question is. It might seem trivial, but I'm actually wondering about it.
Of course I'm biased when it comes to Griffon however I'll try to be as objective as possible:
Griffon is an MVC framework/platform for the JVM. It's true that the programming language of choice is Groovy, however many others can be used too, see this example from the Guide http://griffon.codehaus.org/guide/latest/guide/tips.html#nonGroovyArtifacts where it shows how a pure Java application can be written. Other options are possible if you install a specific plugin http://artifacts.griffon-framework.org/tags/plugin/polyglot
Griffon's philosophy is one of keeping your choices open. It's true that sometimes the framework will steer you to follow particular path however it has provides plenty of leg room, that is, you make it dance to your own tune. For example, writing Views is usually done following the Groovy SwingBuilder DSL (a subtle abstraction layer on to of Swing), but you can drop down to the Java layer and write in plain Java/Swing if you want; or pick NetBeans Matisse, Abeille Froms Designer, or any other Visual tool that supports Swing.
Plugins are key to Griffon's success. As you can see at http://artifacts.griffon-framework.org/category/all/plugins there are currently 211 plugins, and more are coming.
But in the end there's only one opinion that matters: yours. I'd recommend you to spend a few hours with Griffon, if you don't see the value added by it by then ... I'm afraid we'll have to work harder to make it better.
Cheers
As we know, Griffon is based on Groovy and Groovy has a beautiful Java style, probably you will avoid lots of code line, but always we need to consider some aspects like knowledge and schedule.
Knowledge: Your productivity is related with what you know and how to use what you know, if you feel confortble in Java, use the Java, because, seems that your goal is to use MVC and as Juned said, we can do this with Swing, too.
Schedule : If you have time to study and really want to learn a new framework now, this is the time, but you must to follow your schedule, don't forget that you need to finish this project in the time.
So, consider to use what you know, and study new things to another projects.
Avoid diving in the dark without your flashlight.
I was evaluating Griffon as a framework. I got the impression that this project is slowly dieing. IMHO Groovy is not a mainstream anymore (I wonder if it ever was a mainstream?). Now everybody fancies Scala.
Now back to your question:
Most frameworks expect that you follow the standard development path. Any changes / customizations will most probably introduce difficult to maintain solutions (they will call it architecture afterwards). Choose a framework that allows you to do 95% of the things you plan to do. And yeah, choose a mainstream framework.
Griffon is based on Groovy, so you have to master Groovy first. Ok, Groovy is a JVM language and if you're OK with Java it will greatly help, but still all those DSLs will require some time to settle in your head.
If you know any mainstream framework - this is a valuable asset. The sad fact is that frameworks tend to fade / die and you have to constantly look for new buzz things. You never stop learning (although key principles cannot be changed and remain constant from framework to framework)
Implementing the MVC pattern for an environment should be easy if you understand it. First a note on it: http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
Now coming to your environment which is Swing based, you can implement your code by dividing it Model-View-Controller. Views are your Swing classes where are you are actually creating the user interface. In such classes, you should simply capture the user actions through different listeners but should not implement any business logic.Controller should be doing the business logic and may use Model whenever desired.
For example, you are creating a Swing GUI for login. Create a LoginView class where you will create the frame, textfields, buttons etc. And also attach the listeners to different controls as desired. Now whenever a user submits the login, you should call controller to do the credentials validation. Credentials may be stored in a DB, which should be loaded and stored in Model(DAOs). Controller should get the user input from View, correct credentials from Model, and the compare logic should be implemented in Controller.
Hope it helps!
I'm going to be programming a mind node type of application, namely one that allows text editing within text bubbles, free form movement of the bubbles, small bits of animation, but all the standard properties of a windowed application.
I've only done game programming before, where all elements have to be adjusted and programmed, including the GUI etc. Now that I've decided to try my hand at a more "standard" utility program, I'm at a loss of what kinds of API's I should be looking for.
Thanks for the help!
You could use D3.js for that, putting two collapsible tree layouts side by side. That's what we did for our own mindmapping tool, and it took about a day to get the layout right. It's in JavaScript though, not Java, but I'm sure you could integrate it with you Java back-end fairly easily. If you're using a Java applet, it won't be of much help though, but I really hope you don't, for they're a dying breed...
I want to create a texttwist using Java with a GUI, but I don't know where to start. Can somebody give the steps to create my text twist project?
Well, this is a pretty broad question. The fact is there are dozens of ways to go about it. Do you have any Java experience?
Assuming you have no Java experience at all, I would start by finding a few tutorials online, whatever looks good to you (the official tutorials, though, are an excellent place to start). Then go on codingbat and get really comfortable with the basics of Java (also, a good understanding of the Java Collections Framework is essential for doing many things). You can do that before actually choosing an IDE (Integrated Development Environment, like this or this) to use for future coding.
Once you feel okay about actually writing code, start reading about Object Oriented Programming. Learning to make your code sufficiently modular will actually allow you to work more quickly, as you'll have fewer bugs, will be able to make large changes more easily, and will be able to reuse code.
Next you'll need to be able to create a GUI. Having just started in java, you'll most likely want to use Swing, which can very quickly give you something nice to look at. I think many Java IDEs now have Swing design tools that allow you to drag-n-drop components into your GUI.
Once you have a solid understanding of everything that you're going to have to use to build your TextTwist you should be able to plan it out. Draw some diagrams of your program, both how the classes fit together and how you want it to look (I use MS Paint and Dia). Make sure you know what you need before you start programming. Document everything you want the program and each class in it to do. This way if anything isn't going to work you'll know before you've written half your program and have to go back to fix it.
At this point, it should be a piece of cake! Get a dictionary library, pick a seven letter word, check every combination of its letters against the dictionary and store those. Provide some way for the user to make guesses (through your Swing GUI!), and a way to record them. Stick a timer in there, et voila! TextTwist.
There will be a lot of hard work in there, in and in between every step. But if you read as much as you can and keep asking questions (the more specific the better) it won't be so hard. The biggest obstacle when I started was getting discouraged when I bit off more than I could chew. Take small steps and the distance will fly by.
I find that a good place to start is just looking at existing code.
With that said, I have an Eclipse project that implements TextTwist (multiplayer) in Java that I put up on GitHub, if you're at all interested:
https://github.com/fangsterr/Multiplayer-Text-Twist
I've implemented simple GUIs that hopefully you can learn from. Hope this helps!
I've been told that creating GUI's using drag and drop generates unnecesary code and is frowned upon by most Java developers.
I'm used to dragging and dropping things using Windows Forms **but ** I'm also very comfortable creating things using XAML for WPF applications.
I'm a bit lost however on how to create a basic GUI in Java using only code.
What I'm using: Netbeans 6.8
What I want to do: Create a simple Window that will act as the main one
that opens up when the application
launches.
How can I create a simple Window with the standard window buttons (close, minimize, maximize) and have a little button on the middle of it. Using only code.
Also, what type of project do I create using NetBeans?
Thanks for the help.
I feel like this kind of question is best answered with a link to a tutorial, so here you go:
From java.sun.com, Trail: Creating a GUI With JFC/Swing
The link provided by danben is really helpful. If you really want to lay out everything from scratch, then you have to be able to answer such questions as
What is container? Which components are containers?
How components are positisioned within a container (layout manager)?
The link provided will give you the answer.
I heard that one before. I don't know what is with java developers and always insisting that you have to write the gui by code and can't use drag and drop tools. For me I don't care if it generates unnecessary code. I personally don't think it will make that much of a difference.
The only thing I would never recommend is using a designer for websites since they usually never look the way you designed it when you actually test it on a browser but for windows GUI just use a designer.
I look at it this way. There might be a bit more of unnecessary code but your bosses won't care about that. They will be more concerned why your taking so much longer on something and costing the company so much more money on little to no effect to the final product.
To answer your question you probably can pick up any book from java and they will have tutorials on how to make GUI's by code.
To do it programatically, you have to be able to understand code in general. As far as I know Java does not have a simple XML based layout language for GUI-s. So first you have to learn how to program. (But you can try JavaFX's script language, might be easier to master first.) You can easily learn your way in the simple cases from the generated code, then continue using swing javadoc and google.
GUI builders are handful, nevertheless. It is a plausible that once you are required to mock up a GUI layout as a prototype, tracer bullet, presentation material etc. Generated code might be even completely irrelevant.