Alec Porter

Greenhorn
+ Follow
since Sep 05, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Alec Porter

I thought the default Toolkit inside the ImageIcon class gets the image from a FileStream. I was just wondering why it was able to get the image without problems but I couldn't get the list of the files from that directory.
12 years ago

If you just want to print to console (as your example would) contents of /images/ from .jar file, like names of images stored there, you should check the JarFile class from java.util.jar; package.



Yes this is what I would like to do. I'll take a look and do some messing around and see what I can come up with. Thanks. The problem is that the jar isn't created till I make the code into a jar file that means there would be no way to test it in the compiler, should I make a separate jar file for images? I wanted to have the images in the same jar as the main class so I could load them like I did in the code. Is it not possible to get the listFiles() to work because their in the jar? And if so how does new ImageIcon( getClass().getResource("/images/image.png") ) this work for files in the jar but not listFiles?
12 years ago
This gives me:




file:/C:/Users/Sam/Desktop/ImageTest.jar!/images/

And this:




jar:file:/C:/Users/Sam/Desktop/ImageTest.jar!/images/


Not sure what the mistake is,

I tried .replaceFirst("file:", ""); on the path and that didn't work.


And yes canRead is returning false. So I was assuming that the path is incorrect from that.

Also this is in my policy file for testing so I don't think there should be a problem with security:

12 years ago
I've written some code to list all the files in a folder. The problem is that I'm getting a NullPointer Exception at f.listFiles(). The problem is it works fine when I run it with my IDE but when I run it as a JAR it doesn't work. So I'm going to assume that I'm getting the path of the directory incorrectly. So my question is how do I get the correct path for my files?


12 years ago
I'm not sure what exactly your problem is but, if you are calling



in the inner class it will not work because the inner class has no reference to object t inside it.
12 years ago
Try this.


12 years ago
So I made some my own JFrame class and it seems to work properly now. If there is any problem doing it this way I would like to know, but for now this is what I will use.
The component listener will get the the resize event that has been resizing the pane incorrectly and adjust it so it still maintains the correct size.

12 years ago
Okay so here is my problem. I have created a JFrame class and I want to make the content pane inside be a certain size. Since the JFrames size is not the size of the content pane I have to resize the contentpane and pack the JFrame to the correct size. The problem is that I think that setting the JFrame resizable to false causes an increase in the panels size even if I set to maximum size. This happens verry randomly (1 in 50 or so) so I decided to put the code in the AWT thread because I thought it would fix it. Here is the said code:

12 years ago
Dear Fellow Javites,

Hello there! First of all I'd like to say thanks for reading my post. I know that you are busy people and taking the time to read this means a lot to me. Second, I purchased the book 'Developing Games in Java' and I have read through and enjoyed it. It is one of the best books I could find on the market for creating games in Java.

I'm writing this for some assistance with code in the book.

I started awhile back trying to put the pieces together and learn how to create a software renderer of my own. Of course it wasn't as easy as I thought it would be. I started with learning about vectors, projections, and scanline conversion. But my inexperience and lack of knowledge has lead me to a dead end.
The problem I'm facing currently is that I want to create a polygon zbuffered renderer that draws only solid colored polygons, no textures, and no shading. Now when I go to the book for reference on the subject it introduces zbuffering after shading and texture mapping. This extra information has obfuscated me and my attempts to understand how zbuffering works on its own.

I've done a fare share of research and I know(or at least think I do) how to calculate the ZDepth of a given point using the Polygon form Ax + By + Cz + D = 0, or in the book Z = d(UxV dot O) / (UxV dot W). But not for the life of me can I figure out how to apply this into code.

Attached to this link http://pastebin.com/jThNfNYh is a file that has taken the original ZBufferedRenderer class where I lopped off the shading and texture mapping parts in order to better understand how to calculate z depth by boiling it down to its bare essentials. If you have and suggestions how to do this I would greatly appreciate them.

Usually I'll keep working on a problem and try to not bother people with my questions that could be fixed by looking it up or just experimenting till it works. But this has become such a pain in my side that I'm reaching out for some help.

Thanks,
Alec
12 years ago
So I'm making a little game that has a background and a player "ship", the problem is I can't get the ship to draw on top of the background. The player is a tranparent png(with alpha channel) 32x32 image. When I try to draw the image over the background tiles it just draws the player. I know its good to have code so this is just an example of how I'm drawing things.



One thing to note is that when I draw the background over the player, I can move to where there isnt a part of the map drawn and I can see the player is draw. So I think it has something to do with the transparency.

Edit: Upon futer examination I've seen that it might have to do with the layout of the contentPane. I will look into this more.
14 years ago
Okay well it might take me a couple days to create a short example but for now can someone tell me what methods get called when a JFrame is minimized, because that seems to remove the JPanel properly only when I do that. So I think I need to call one of those methods.
14 years ago
I'm working with Developing games in java and I've been having problems with removing a panel from being visible. If you have the book then the problem is much like chapter 3 "KeyConfigText.java". If you don't own the book then I'm basically tying to get a JPanel to dissapear after hitting a Button on a JPanel. Now I follow all the code in the book that does this as one of its examples(no exactly but very close). The problem is when setting the JPanel to not be visible it doesn't make it invisible it just freezes the JPanel and when I minimize the JFrame from full screen then maximize it the Panel goes away. So I guess that something is happening when I do that that I need to call on the frame so I don't have to do that to get it to go away. I tried to look up what happens when you minimize JFrames but I didn't find anything, so what is happening that isn't happening when I just have the frame open?
14 years ago
Well that fixed it. Thanks, not sure why it does that though.
14 years ago
Why is it doing that and how do I fix it?
14 years ago
So I'm trying to get the class files by calling listFiles()



For the parent file I'm getting my class directory which is what I want.



but it's returning null. On the java API it says for that method that "If this abstract pathname does not denote a directory, then this method returns null. " Event though I know it has the correct directory I need and there are files in it. So why does this happen?
14 years ago