Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (488)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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 ... 11
1  Game Development / Newbie & Debugging Questions / Re: lwjgl_util_applet WToolkit NPE Annoyance on: 2014-07-12 04:43:46
Smells like this issue:

https://bugs.openjdk.java.net/browse/JDK-8019274

Fixed in 7u65 and 8u11 (neither one of which I believe is available yet).
2  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
3  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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
public class MyFileChooserUI extends MetalFileChooserUI {

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

   public MyFileChooserUI(JFileChooser chooser) {
      super(chooser);
   }

   @Override
   public void setFileName(String filename) {
      if (new File(filename).equals(getFileChooser().getFileSystemView().getHomeDirectory())) {
         super.setFileName("");
      }
      super.setFileName(filename);
   }

}


4  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.
5  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?
6  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.
7  Discussions / General Discussions / Re: Java "Mods" on: 2013-12-04 03:28:33
Isn't that one of the kickass features of Lisp?
8  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.

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

9  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.
10  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:

1  
printf(template, param);


But how is this sort of thing handled with C++ streams?
11  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!
12  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.
13  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.

Quote
  • 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...

Quote
  • 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.
14  Game Development / Newbie & Debugging Questions / Re: File Not Found Exception on: 2013-04-17 18:55:39
java.io.FileReader 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

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

15  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.
16  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().
17  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!
18  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.
19  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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
   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);
      g2d.dispose();
      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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
   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?
20  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.
21  Game Development / Newbie & Debugging Questions / Re: JFrame/Frame and the Event Dispatch Thread on: 2013-02-18 19:50:30
You're right that there's no effective "real-world" difference.  The main reason I think people suggest to use AWT over Swing for games is that there's simply less overhead.  As soon as you create a JFrame, a JPanel, etc., Swing's LookAndFeel-related classes all get loaded, but if you're not using any JComponents other than say a custom-painted JPanel, you don't actually use them.  Why load classes you don't need or use?  etc.

Again, this is a negligible "benefit", and certainly isn't noticed by users.
22  Discussions / Miscellaneous Topics / Re: Legend of Zelda: Look into item dropping algorithms on: 2013-02-17 01:05:25
I'm surprised nobody's analyzed the ROM and figured out the exact algorithm for item drops, including the bits and pieces the video says are still unknown.

Those speedrunner guys though, they always figure out *everything*.
23  Discussions / Miscellaneous Topics / Re: Java blocked on Macs? on: 2013-02-02 19:53:46
According to the article the Department of Homeland Security also recommends against Java...isn't their time better spent catching intentionally malicious things or, say, terrorist attacks? Roll Eyes

This reminds me of people who get a speeding ticket and complain, "Shouldn't the cops be out catching murderers and bank robbers?"
24  Discussions / General Discussions / Re: Why java over other languages? on: 2013-01-31 16:30:09
- the lambda introduces a new operator "->" which must be learned
- Also the "e -> " part of the expression is alien to Java. It seems to be sort of argument passing to a parameter which has the same name as the argument ... it's also somethign new, other parts of java don't work this way.

But if Java 1.0 were shipped supporting lambdas and this syntax you'd think differently, as you'd be used to it.  Just because you have to learn new syntax doesn't mean Java suddenly becomes bloated or confusing.

If you were learning Java post-Java 8, and your education included lambdas, would you think "this one feature is just too confusing," or would you simply accept it and happily move on?
25  Game Development / Newbie & Debugging Questions / Re: Quick Swing Question on: 2013-01-29 22:41:44
You set the layout of the JFrame to null, when you probably meant to set the content pane's layout to null.  This works:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
public Window() {
      JFrame mainFrame = new JFrame();
      mainFrame.setSize(1024, 786);
      mainFrame.setLocationRelativeTo(null); //Centers the window on the users screen.
     mainFrame.setTitle("Temp Name");
      mainFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
      mainFrame.setResizable(false);
      insets = mainFrame.getInsets();
      mainFrame.getContentPane().setLayout(null);
     
      JTextArea gameTextArea = new JTextArea();
      gameTextArea.setEditable(false);
      gameTextArea.setBounds(50, 30, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
     mainFrame.getContentPane().add(gameTextArea);
     
      mainFrame.setVisible(true);
}


Standard Swing-fanatic disclaimer:  It's really preferable to use a LayoutManager rather than null layout, as then your UI could be designed to allow the window to be resizable and still look nice, not to mention handling different LookAndFeels having different widget sizes, the user's desktop settings, etc.
26  Game Development / Newbie & Debugging Questions / Re: [FPS Camera: Robot.mouseMove() persistency] on: 2013-01-27 05:28:06
Quote from: GabrielBailey74 link=topic=28565.msg260180#msg260180
If someone thinks the reason I'm not getting the persistency I'd prefer is due to the reason of my implementation of compensating for the window's borders, I've executed the program without compensation and it made no difference.

I see what you're trying to do, but note that hard-coding the size of the window's title bar and borders is a bad idea.  Different OSes will have different values, let alone if the user has different themes, font sizes, display settings, etc.  You will need to handle such information dynamically.

As for the mouse events, you'll never get one for each pixel the mouse moves.  Your best bet might be to also listen for mouseExited() events and move the mouse back on them as well.  You'll most likely need to handle mouseDragged() events the same way too, since they won't get handled by your mouseMoved() handler.
27  Discussions / General Discussions / Re: how to make a soccer game in 2D with java? on: 2013-01-18 03:10:22
I had a software manager once that didn't know anything about coding and determined your performance based on lines of code....it was hell.

You had a manager that read through your code?  That in and of itself is strange to me.  Unless you're saying he gauged your performance based on `wc -l`, like the old joke, in which case I don't see the problem - that's easily abusable in your favor...
28  Game Development / Newbie & Debugging Questions / Re: [Loading A 'small movie' in .PNG frames (Memory DEBO)] on: 2013-01-17 22:39:57
Yes, but you saved 20MB because the ImageIcons were simply wrapping the BufferedImages, so naturally there was more stuff in memory with a list of ImageIcons.  The actual RAM used by BufferedImages was the same.  If you cannot cut down your image size or resolution, you'll probably have to find an Image implementation that is more space efficient than BufferedImage (which I believe typically is just uncompressed RGB data).  See this StackOverflow post for a discussion about this very problem and possibly some ideas for minimizing your memory requirements.
29  Game Development / Newbie & Debugging Questions / Re: [Loading A 'small movie' in .PNG frames (Memory DEBO)] on: 2013-01-17 04:16:50
Are you getting OutOfMemoryErrors?  Or just performance problems but the program runs?  If the former, just increase the maximum heap size:
1  
java -Xmx1024m ...
30  Discussions / Suggestions / Re: Bugs on: 2013-01-09 21:48:46
I have the opposite problem.  I get angry when sites require fewer than X characters. (And unbelievably, it's a financial institution I use that does this - where I want a long password the most!).
Pages: [1] 2 3 ... 11
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (17 views)
2014-08-28 18:26:30

CopyableCougar4 (26 views)
2014-08-22 19:31:30

atombrot (39 views)
2014-08-19 09:29:53

Tekkerue (36 views)
2014-08-16 06:45:27

Tekkerue (33 views)
2014-08-16 06:22:17

Tekkerue (22 views)
2014-08-16 06:20:21

Tekkerue (33 views)
2014-08-16 06:12:11

Rayexar (68 views)
2014-08-11 02:49:23

BurntPizza (45 views)
2014-08-09 21:09:32

BurntPizza (36 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!