Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (602)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (650)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2 3 ... 12
1  Game Development / Game Mechanics / Re: Making GUIs on: 2015-02-28 00:18:47
This is a pretty presumptuous statement. Can you name any other thread-safe gui libraries?

Indeed, I thought that many (most?) of the "popular" UI toolkits are single threaded - Win32, Android, etc.  Looking it up though I can't tell about OS X or whatever rendering pipelines are popular for LInux these days.  I'd also be interested in whether the new, cool ways of creating Windows desktop apps all still boil down to (custom-drawn) win32 stuff or if things are different these days.
2  Discussions / Miscellaneous Topics / Re: C#, did Microsoft just want to be different? on: 2014-12-03 05:04:28
I didn't meant to start a language vs language thing here, I was genuinely curious to these naming conventions and why C# had to be different from other OOP languages despite sharing the exact same principles.

Actually a project is not a soultion. A solution can hold multiple projects  Wink mean a workspace like every other IDE has? :p

Actually, I don't think "workspace" is any kind of de-facto standard.  In IntelliJ Idea, for example, the equivalent of an Eclipse "workspace" is called a "project", and the equivalent of an Eclipse "project" is called a "module." 
3  Game Development / Newbie & Debugging Questions / Re: Clean code & Smooth development on: 2014-10-17 14:34:54
When princec says "Sun's bracket conventions" that means either of the two types that Cero demonstrated, yes?

Actually, Sun's recommendations with regard to curly braces is only "opening curly NOT on a separate line."

Note its style recommendations have not been updated since 1999; see this StackOverflow thread for a relatively recent discussion about this and a link to the (archived) "official" documentation from Oracle.

Anecdotally, I find most Java programmers prefer Sun/Oracle's recommendation for curly brace placement, but I've also met some traditionally-C-style separate-liners.  Personally I'm in the "use whatever the standard formatting is for the particular language you're working with" camp.
4  Discussions / Miscellaneous Topics / Re: Poor performance with JFileChooser on: 2014-10-15 23:01:38
mhm ... try invokeLater in actionPerformed anyway. just a guess Smiley

ActionListener.actionPerformed() is always called on the EDT.  All Swing event listeners are.  You only need to worry about SwingUtilities.invokeLater()/invokeAndWait() when you are off in your own thread, or something like the main application thread.

yes, but no.

if boot off things in the EDT right ahead it can still hang and screw you over. invokeLater from the EDT ensures the new action is queued to the end, rendering the current EDT process not block. Cranky


I'm not quite sure I understand what you're saying here.  If a Swing EventListener class is not triggered on the EDT, you have found a bug in the JDK (or perhaps you have a custom JComponent going rogue and not playing by the rules).  I am assuming of course that the programmer is doing "the right thing," starts their Swing app on the EDT, etc.

If you're stating that running long-running processes in an ActionListener on the EDT causes the EDT to appear to hang, that is certainly true.  But if you're performing long-running tasks you should run them off the EDT in the first place, perhaps via SwingWorker.  Delaying a long-running task by calling SwingUtilities.invokeLater() when you're already on the EDT only delays when that long-running task will run on the EDT, it doesn't cause it not to occur.  The UI will still hang for the same length of time, only perhaps after performing a few other tasks.

on the other side, if you run invokeAndWait from the EDT you make it hang 100%.

Yes, again, I'm assuming the programmer isn't doing something stupid.
5  Discussions / Miscellaneous Topics / Re: Poor performance with JFileChooser on: 2014-10-15 22:53:47
Something that can cause random hangs in windows filesystems is attempting to access floppy drives, CD drives, or network drives that don't exist. Domain-related woes especially. You might want to whip open Explorer and see if it has trouble at the same time.

'Tis true.  I recall back in the 1.4 days (I think), I hacked JFileChooser code (perhaps FileSystemView) to return a hard-coded display name of "A:\" for a floppy drive (if on Windows) instead of letting Java do whatever native call to determine the drive name.  Terrible I know, but I recall back then there was some issue where Java would actually access the drive (you'd hear the physical drive access) before fetching the drive's name.  It just wasn't worth it back then, when Swing had so many other things going against it performance-wise.

I've also seen JFileChooser hang for long periods of time while trying to access information about certain mounted drives in both Linux and AIX.  Always in native calls, never in something you could control.
6  Discussions / Miscellaneous Topics / Re: Poor performance with JFileChooser on: 2014-10-15 22:38:10
mhm ... try invokeLater in actionPerformed anyway. just a guess Smiley

ActionListener.actionPerformed() is always called on the EDT.  All Swing event listeners are.  You only need to worry about SwingUtilities.invokeLater()/invokeAndWait() when you are off in your own thread, or something like the main application thread.
7  Discussions / Miscellaneous Topics / Re: Poor performance with JFileChooser on: 2014-10-14 20:51:01
This is the most infamous JFileChooser performance bug, but you'd have to be running a pretty old JVM to hit it (JDK6 pre-u10).
8  Discussions / General Discussions / Re: Mobile Java game development, without using a full-size laptop on: 2014-10-11 21:34:00

For dinner and drinks with friends?

Yes, your going to go somewhere every one can afford, and even if they had the money for it they certainly aren't going to go somewhere that is more expensive for the sake of it.

Funny, for a lot of these I disagree with you.  You're assuming I'm saying people buy more expensive stuff when cheaper alternatives exist willy-nilly.  I'm not saying that.  People usually have a price range they believe is "reasonable" when buying something, and sometimes they splurge, for any number of reasons.  Sometimes they splurge on cheap stuff, other times on expensive stuff.

I agree with you that, if asked these hypotheticals, most people will respond, "Of course, why would I pay more than I have to?"  In actuality, however, many people splurge on the items I mentioned above.  I believe you're arguing that people don't purposely waste money, and *try* to get good deals, live within their means, etc.  I don't disagree.  I'm arguing that sometimes people spend more for intangible benefits, which vary from person to person.

For gum, even "expensive" gum is relatively cheap, so people often buy one whose flavor they like better, or at a minimum, don't calculate that pack A is 0.5 cents per ounce cheaper than pack B.  This example is basically "it's so cheap it's worth spending an extra 20 cents to have the specific type of gum I prefer."

For a car or house, people often spend a little more than they have to, specifically because they're long-term investments.  Yes, they haggle, and don't purposely waste money.  They do not buy a $500k house when they only need a $150k house (well, some people do, but that's not my point  Smiley).  But you may buy a house with upgraded features - hardwood floors, higher-quality granite, a garage, etc.  Such features aren't a requirement, by any means, for anybody.  But they have benefits hard to quantify financially, such as how much enjoyment you get out of them.  This example is "I'm going to use X for so long, I want to be sure it has lots of features I want in it, and I really enjoy using it."

Cars in particular.  Not everyone picks out what vehicle to buy based *solely* on quality + long-term cost of ownership.  Most pick out what criteria are important for them (# of passengers, fuel efficiency, safety features, total cost of ownership), figure out what cars are in their "acceptable" price range based on these criteria, then strike out a few possibilities based on looks alone, then head out to dealerships.  Test drive several, eliminate some based on "feel," then haggle on the price for the one they like the most.  Why is this a bad way to car shop?  Again, I'm not arguing buying a car $20k over what you should.  I'm saying people factor in things like looks, handling and feel.

For dinner and drinks with friends, I very much disagree.  With dinner, the question is rarely whether or not you can afford it.  Do you always ask yourself "Restaurant A I get a larger quantity of food than Restaurant B, with roughly the same nutritional value, so therefore I'll go to A", or do you, at least sometimes, ask yourself, "What do I feel like tonight?  We went out for Mexican last week, and I haven't had a steak in awhile... let's try out that new steak place!" ?  Most people allow themselves a huge amount of wiggle room with dining.  They have a price range they believe is "reasonable", but nothing more than that.  This example is "As long as it's not outrageously too expensive, I like to try new places and do new things."

Again, this is all subjective, and depends on where you are financially and other factors.

Some people will by the cheapest, most fuel-efficient car every time, rent/buy the cheapest place possible to maximize investments, and never eat out, because cooking at home is cheaper.  But that's not the case for everybody.  At some point, everybody splurges.
9  Discussions / General Discussions / Re: Mobile Java game development, without using a full-size laptop on: 2014-10-10 01:22:46
In some ways a Mac is better than a Windows-based PC, in other ways it isn't.

When buying a new computer, tablet, etc., some people do a cost-benefit analysis and buy the best specs they can per dollar.  Others are OK buying something for a price they deem acceptable, even if it isn't the best absolute value, because they prefer the design, usability differences, or some other quality.  Is this bad?  If so, why?

Do you use cost-benefit analysis to get the absolute best value out of the groceries you buy at the store?

For the car you buy?

For your new apartment or house?

For a pack of gum?

For dinner and drinks with friends?

At some point, everybody gives themselves a little wiggle room to purchase something that costs a little more, for reasons other than its absolute value.  Many factors influence where this point is for a person - disposable income, personality, etc.  But everybody's willing to spend a little more money on something, just because they like it more than other choices, *sometimes*.  And what/how much varies from person to person.

Why is this something to criticize?
10  Discussions / General Discussions / Re: Microsoft to buy Mojang for $2 billion? on: 2014-09-10 20:44:05
"As long as I've got my health, and my millions of dollars and my gold house and my rocket car, I don't need anything else."

- Chester J. Lampwick
11  Game Development / Newbie & Debugging Questions / Re: lwjgl_util_applet WToolkit NPE Annoyance on: 2014-07-12 04:43:46
Smells like this issue:

Fixed in 7u65 and 8u11 (neither one of which I believe is available yet).
12  Game Development / Newbie & Debugging Questions / Re: JFileChooser: How to stop autofill file name after clicking on home directory? on: 2014-06-12 12:24:59
What this workaround is doing is just preventing the home directory's path from being entered into the text field; it shouldn't make the "Home" button not work (the chooser will still navigate to the Home directory in its list/details view).

A side effect might be (untested) if the user actually types in their home directory path and hits Enter, that text will be cleared out as opposed to sticking around (IIRC, JFileChooser would keep the directory name entered when the user manually types something and hits Enter, though to me that's ridiculous.  But maybe they've fixed that now.  Though again, such behavior is likely LAF-dependent).  I left that testing as an exercise for the OP.  Smiley
13  Game Development / Newbie & Debugging Questions / Re: JFileChooser: How to stop autofill file name after clicking on home directory? on: 2014-06-12 03:14:13
This is theoretically LookAndFeel-specific, even though most LAFs probably handle it the same way.  If you're set on a specific LookAndFeel (e.g. Metal) across all OSes, set a custom LookAndFeel overridden to not insert the file name when going home:

public class MyFileChooserUI extends MetalFileChooserUI {

   public static ComponentUI createUI(JComponent c) {
      return new MyFileChooserUI((JFileChooser)c);

   public MyFileChooserUI(JFileChooser chooser) {

   public void setFileName(String filename) {
      if (new File(filename).equals(getFileChooser().getFileSystemView().getHomeDirectory())) {


14  Game Development / Newbie & Debugging Questions / Re: Does using a library still expand one's abilities in general game-development? on: 2014-03-16 21:07:29
Like pitbuller says, in software development (not just game development), knowledge of industry-standard libraries is a *good thing*, not something to be avoided.  Someone with experience using the tools of the trade will get more job offers than someone who doesn't, simply because they have a broader skill set.

You're right that you could arguably learn more about certain "low-level" things when re-inventing the wheel, but you'll be a way more productive, and desirable, developer if you make smart decisions about tools and libraries.
15  Discussions / General Discussions / Re: new Youtube? on: 2014-02-22 18:22:49
I write web apps with Dojo in my day job ( => many, many JS files), and one very small but very important feature that the Chrome developer tools has that othes don't have is Ctrl+O to quickly open downloaded JS files by name.

With Firebug AFAIK I have to physically click, or tab to, the filename drop down to start typing a file name.  And I avoid debugging in IE whenever possible since its dev. tools are markedly inferior than either Chrome or FF (though perhaps IE11 is better?), but having a shortcut to type a file name to view is worth its weight in gold.  It's such a small thing, I don't know why don't other browsers' developer tools have this?  Or am I just missing something?
16  Game Development / Newbie & Debugging Questions / Re: JFrame dimensions? on: 2014-01-01 05:51:47
Abuse's second suggestion is the better approach.  You're rendering to some component you shove into a JFrame, such as a Canvas or JPanel.  Use setPreferredSize(new Dimension(640, 480) to set the size of that component.  Then your drawing surface is 640x480, and you don't have to care about the window's frame size.

On resize events, just grab the new size of the Canvas or JPanel you're rendering on.  Then you can decide whether to stretch your screens to fit, center them, etc.
17  Discussions / General Discussions / Re: Java "Mods" on: 2013-12-04 03:28:33
Isn't that one of the kickass features of Lisp?
18  Game Development / Newbie & Debugging Questions / Re: Xmx ignored when used in Runtime.exec on: 2013-11-26 20:01:27
Note that any parameters after the jar name will be command line arguments to your program, not to the JVM.  Move the -Xms/-Xmx to be before the "-jar jarName" parameters.

java -Xms1024m -Xmx1200m -jar "data.jar"

19  Discussions / Miscellaneous Topics / Re: What would you like to see in Java? on: 2013-10-09 12:57:34
Often though, doing that is a terrible idea and universally considered bad practice. A lot of bugs have been created by using non-literal format strings (bugs, and software exploits)

Objective(ly)-C(rap) compilers usually do a check for that and throw a warning on compile time if you are doing that. Like-wise, so do a lot of modern C++\C compilers.

Really?  But all of my user-facing text is externalized.  No idea how that's typically done with C++, but how it's done is irrelevant - format strings can vary in the location of their parameters from one language to the next.  Of course the format strings aren't going to be freeform, they're known at build time, as they were given to you by localizers.

Good to see Boost and/or newer standards support this kind of thing though.
20  Discussions / Miscellaneous Topics / Re: What would you like to see in Java? on: 2013-10-08 21:39:09
Getting really off topic here, and maybe this is simple, as I haven't really touched C++ in ages, but...

One advantage printf() seems to have over e.g. std::cout is localization, particularly positional parameter substitution.  For example, if I have a message template like so:

English: "Hello, {0}!"
Other-Language: "{0} xcvlxcvj!"

It's easy enough to handle this with a printf call:

printf(template, param);

But how is this sort of thing handled with C++ streams?
21  Discussions / General Discussions / Re: Java games on PC's with no Java? on: 2013-08-25 21:17:20
I'd definitely also recommend launch4j for Windows packages.  A single fat jar isn't a requirement, your project can have any structure, and your process can be launched with custom names, not java.exe.

I've also used NSIS for installers, which was also very nice.

I've also heard rumors that the JavaFX native packaging works for all Java apps, not just JavaFX ones (another linky).  If so, that's a nice option because it creates native bundles for Windows, OS X and Linux.

In short, you have lots of options!
22  Discussions / General Discussions / Re: What would you modify in Swing if you had to rewrite it? on: 2013-08-17 03:26:31
(and not being "native" when bindings for native toolkits, like SWT, were the cool thing).
It depends on your customers, some people don't expect a native "look and feel".

Aye, to a degree, that's what I was alluding to.  A few years ago, native looking (desktop) apps was what everybody wanted to build.  Nowadays, we've done a 180 and everybody wants unique looking apps.  Or maybe it just seems that way because so much stuff is being built as webapps these days, and it's so much easier for designers to get creative with CSS than it is with a programmatic styling API like Swing LookAndFeels.
23  Discussions / General Discussions / Re: What would you modify in Swing if you had to rewrite it? on: 2013-08-14 22:24:42
I'm yet another idiot who loves Swing.  Once you get past the steep learning curve, it's both very powerful and configurable.  I think it just got a bad rap for looking like crap for so long (and not being "native" when bindings for native toolkits, like SWT, were the cool thing).

I never touch GridBagLayout.  You can do everything you need with the other built-in layouts, and a fair amount of nesting.  It is often easier to use a 3rd-party LayoutManager though.

Besides what's already mentioned here, maybe that application framework JSR that never got off the ground, based on NetBeans RCP I believe.  It would help remove a lot of boilerplate from Swing applications of any appreciable size.

  • The amount of sizes you have to set to make stuff work. Setting size doesn't work, setting defaultSize doesn't work, setting preferred size doesn't work, then you have to create a random dimension object to set another size. Seems like I'm always setting everything to get it to work.

Typically, if you find yourself calling set*Size() on any components, "you're doing it wrong."  Properly-used LayoutManagers size everything properly for you 99.9% of the time.

  • Some children are possible only from a JFrame, but not in nested objects. So you want a filedialog window to appear when you click a button in your panel? Well, you can't.

I'm not sure I follow?  You can create and show FileDialog (or JFileChooser?) from any JButton anywhere in your UI...

  • Is swing JFrame the one where you cant convert easily to an Applet?

Either one would just be a container for your UI.  If you want to write an application that can run in both a window and an applet, typically you'd add all your components to a JRootPane.  JRootPane is basically all the content in your GUI application.  Then you can shove your JRootPane containing your application content into either a JFrame or a JApplet.
24  Game Development / Newbie & Debugging Questions / Re: File Not Found Exception on: 2013-04-17 18:55:39 doesn't take URLs, or string representations of URLs, as parameters to its constructor; it expects a (local) file path.  When you pass a string with "%20" embedded in it to represent a space, the class will assume you mean literally "%20", and not a space character.  Hence the file isn't found, because what you passed to it literally does not exist.

You need to pass the file name "normally," not URL-encoded.  Or use some other construct, such as

new BufferedReader(new InputStreamReader(classLoader.getResourceAsStream("/path/to/resource")));

25  Game Development / Newbie & Debugging Questions / Re: Use LUA for ingame computers on: 2013-04-09 20:56:53
Aye, FWIW, you can "script" in JavaScript in Java 6 and 7 also, just ask for the "javascript" engine instead of "nashorn".  I believe it uses some older Rhino version.
26  Game Development / Newbie & Debugging Questions / Re: Resizing JPanels on: 2013-03-15 04:03:03
I'm not 100% clear on what you're doing, but if you're adding and removing components at runtime, and want to do things the "right" way (e.g. have components laid out according to the installed LayoutManager), you typically just call revalidate().
27  Discussions / General Discussions / Re: I Switched to IDEA! on: 2013-03-11 13:21:45
Personally I have to flex my entire hand to be able to "ctrl+y", but I can do "ctrl+d" with ease.

Not that I use IDEA, but can't you just use both  hands for that shortcut?  If you're shortcut-driven then both hands will be on the keyboard most of the time, then shortcuts like those aren't a problem.  Not to mention you get to be one of those geeky people who brag about never using a mouse!
28  Java Game APIs & Engines / Java 2D / Re: Manipulating BufferedImages with IndexColorModels on: 2013-02-24 23:40:32
Thanks guys.  Sorry about the super-small sample image; I was using the simplest test case possible, a single 16x16 tile, all one color, while trying to figure things out.

I had tried all those RenderingHints in the hope they would make a difference (as well as perhaps ward off issues when creating new images with scales > 1) but they seem to make no difference - the result is still the same, apparent dithering.

I found this old thread, in which Abuse gives an approach that does work.  If you start with one IndexColorModel'd Image, and create a new BufferedImage with a new ColorModel but the same Raster, things are much happier.  I'm still not sure why you get differing results when using a "grayscale" IndexColorModel vs. another IndexColorModel, when using a source image that has all pixels the same color, but whatever.
29  Java Game APIs & Engines / Java 2D / Manipulating BufferedImages with IndexColorModels on: 2013-02-24 06:41:18
Hopefully it's just because it's so late, but for the life of me I can't figure this out.  I start with an 8-bit PNG image.  I can create a grayscale version of this image with Java2D like so:

   private static final IndexColorModel createGreyscaleModel() {
      int SIZE = 256;
      byte[] r = new byte[SIZE];
      byte[] g = new byte[SIZE];
      byte[] b = new byte[SIZE];
      for (int i=0; i<SIZE; i++) {
         r[i] = g[i] = b[i] = (byte)i;
      return new IndexColorModel(8, SIZE, r, g, b);

   private static final BufferedImage createIndexedCopy(Image orig, IndexColorModel cm, int scale) {
      int w = orig.getWidth(null);
      int h = orig.getHeight(null);
      BufferedImage out = new BufferedImage(w*scale, h*scale, BufferedImage.TYPE_BYTE_INDEXED, cm);
      Graphics2D g2d = out.createGraphics();
//      g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
//      g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
//      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
//      g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
      g2d.drawImage(orig, 0, 0, w*scale, h*scale, null);
      return out;

   // ...

   BufferedImage grayscaleImage = createIndexedCopy(otherImage, createGreyscaleModel(), 1);

The end result looks like what I'd expect.  So next, I thought I'd try to create a "greenscale" version of the image by creating the color model like so:

   private static final IndexColorModel createGreenModel() {
      int SIZE = 256;
      byte[] r = new byte[SIZE];
      byte[] g = new byte[SIZE];
      byte[] b = new byte[SIZE];
      for (int i=0; i<SIZE; i++) {
         g[i] = (byte)i;
      IndexColorModel model = new IndexColorModel(8, SIZE, r, g, b);
      return model;

But the end result isn't what I want.  It looks as if some kind of interpolation was done, even though the image was never scaled.  This happens even when the original image is just a single color.  See the example below.  The original (blue) image has all pixels a single color, the grayscale version looks good, but the green version doesn't...

What am I missing?
30  Java Game APIs & Engines / Java 2D / Re: Event handling on: 2013-02-22 00:38:49
If you need custom events, and not built-in events as xsvenson speaks of, there are two available options.  You can choose which one is more appropriate for your situation.

1. Use java.beans.PropertyChangeEvents.  JComponents can fire such events by any of their many firePropertyChange() overloads.  Then the other component interested in these events would call customComponent.addPropertyChangeListener("propName", this);  This technique is common if you have say boolean, int or String properties that other components might be interested in receiving change notifications for.

2. The second option is more legwork, but allows you to notify listeners with an entire event object containing arbitrary data, instead of just an old/new value pair.  Roll your own Event class (subclassing java.util.EventObject), Listener interface (extending java.util.EventListener), and make your custom component accept Listeners of that type.  It follows the same pattern as the "built-in" event types like ActionListener, so it's pretty straightforward.  A simple example can be found here.  Note that JComponents already have a protected EventListenerList field named "listenerList", so you don't have to add such a field in your custom component yourself.
Pages: [1] 2 3 ... 12
Jesse (15 views)
2015-07-29 04:35:27

Riven (37 views)
2015-07-27 16:38:00

Riven (18 views)
2015-07-27 15:35:20

Riven (21 views)
2015-07-27 12:26:13

Riven (12 views)
2015-07-27 12:23:39

BurntPizza (30 views)
2015-07-25 00:14:37

BurntPizza (42 views)
2015-07-24 22:06:39

BurntPizza (24 views)
2015-07-24 06:06:53

NoxInc (31 views)
2015-07-22 22:16:53

NoxInc (18 views)
2015-07-22 22:13:39
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!