Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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
1  Java Game APIs & Engines / J2ME / loading resources from another module on a Blackberry on: 2005-09-07 18:52:26
Hello

Let's say I have two code modules installed on my Blackberry: module A and module B.  Module B is full of images and config files, while module A is full of code.   It has been posted on the Blackberry Dev forum that code in module A can access resources in module B in the following way:

1  
Class.forName("com.class.in.module.B").getResourceAsStream("/imageB.png");


I have had varied success with this method, and somehow deleted the only version of my code and project that worked.  Does anyone have experience loading resources from other code modules on the Blackberry?  If so I'd be all ears.  Ideally module B will be created sometime after the application is deployed and module A would have no declared dependency on module B.

For reference here is the original thread from the Blackberry forum.  (I hope it's cool to post it here)  http://www.blackberry.com/developers/forum/thread.jsp?forum=1&thread=4697

   Cheers!
2  Java Game APIs & Engines / Tools Discussion / Control-L in emacs is to {BLANK} in eclipse on: 2005-08-11 18:38:28
HOW ARE YOU GENTLEMEN!?!?

Is there an answer to my riddle?  I've been spinning my wheels in the help files searching for this feature.  For those unfamiliar with emacs I would like to know what keystrokes in eclipse force the current line to recenter vertically within the view.


   Thanks!

3  Java Game APIs & Engines / Java 2D / finding the points along a QuadCurve2D? on: 2005-04-08 19:39:58
Hello

I need to draw a special arrow for our system today and it kinda looks like this:  )--->

That ascii arrow is where I am at now.  Given two points and a value for width I draw an arrow from tip to tail with a curve who's end points are width pixels apart.  My curve is a QuadCurve2D.Float and by carefully choosing my control point the curve intersects the end of the arrow.  

The tricky part comes next:  drawing line segments off the curve which are perpendicular to the arrow.  How can I find the points on the curve?  Should I even bother?

My only idea thus far is to define a clip that is my existing curve, an identical curve transformed behind my arrow and two lines connecting their end points.  That clip will allow me to draw line segments of equal length off the back of my visible curve, but I'd still like to know how to find those points.

Any thoughts appreciated.  thanks!



4  Discussions / General Discussions / Re: Where Are You? on: 2005-03-17 17:43:47
Washington D.C. a half a mile from the White House.

Bethesda Software (http://www.bethsoft.com/) is in Rockville Maryland 30 minutes from downtown DC, but that's the only game company I know of around here.  If you want to do graphics in Java you'll probaby be working on a military simulation - which is what I'm doing now.

5  Discussions / Miscellaneous Topics / Re: Pics of yerselves!  Put faces to the names. : on: 2005-02-16 15:19:21
I haven't posted in at least 6 months, but I've been lurking a bit since my latest Swing/2D project started.  Self potrait in the car after a haircut.

6  Game Development / Newbie & Debugging Questions / Re: Reading BMPs in ImageIO on: 2004-06-29 00:15:19
NeHe (http://nehe.gamedev.net/) tutorial 8, as ported to Java by Abdul and Pepijn (http://pepijn.fab4.be/nehe/), contains a rather handy class.

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  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
package demos.common;

import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.awt.image.DataBufferInt;
import java.io.IOException;
import java.io.InputStream;

/**
 * Windows bitmap file loader.
 * @author Abdul Bezrati
 * @author Pepijn Van Eeckhoudt
 */

public class BitmapLoader {
    public static BufferedImage loadBitmap(String file) throws IOException {
        BufferedImage image;
        InputStream input = null;
        try {
            input = ResourceRetriever.getResourceAsStream(file);

            int bitmapFileHeaderLength = 14;
            int bitmapInfoHeaderLength = 40;

            byte bitmapFileHeader[] = new byte[bitmapFileHeaderLength];
            byte bitmapInfoHeader[] = new byte[bitmapInfoHeaderLength];

            input.read(bitmapFileHeader, 0, bitmapFileHeaderLength);
            input.read(bitmapInfoHeader, 0, bitmapInfoHeaderLength);

            int nSize = bytesToInt(bitmapFileHeader, 2);
            int nWidth = bytesToInt(bitmapInfoHeader, 4);
            int nHeight = bytesToInt(bitmapInfoHeader, 8);
            int nBiSize = bytesToInt(bitmapInfoHeader, 0);
            int nPlanes = bytesToShort(bitmapInfoHeader, 12);
            int nBitCount = bytesToShort(bitmapInfoHeader, 14);
            int nSizeImage = bytesToInt(bitmapInfoHeader, 20);
            int nCompression = bytesToInt(bitmapInfoHeader, 16);
            int nColoursUsed = bytesToInt(bitmapInfoHeader, 32);
            int nXPixelsMeter = bytesToInt(bitmapInfoHeader, 24);
            int nYPixelsMeter = bytesToInt(bitmapInfoHeader, 28);
            int nImportantColours = bytesToInt(bitmapInfoHeader, 36);

            if (nBitCount == 24) {
                image = read24BitBitmap(nSizeImage, nHeight, nWidth, input);
            } else if (nBitCount == 8) {
                image = read8BitBitmap(nColoursUsed, nBitCount, nSizeImage, nWidth, nHeight, input);
            } else {
                System.out.println("Not a 24-bit or 8-bit Windows Bitmap, aborting...");
                image = null;
            }
        } finally {
            try {
                if (input != null)
                    input.close();
            } catch (IOException e) {
            }
        }
        return image;
    }

    private static BufferedImage read8BitBitmap(int nColoursUsed, int nBitCount, int nSizeImage, int nWidth, int nHeight, InputStream input) throws IOException {
        int nNumColors = (nColoursUsed > 0) ? nColoursUsed : (1 & 0xff) << nBitCount;

        if (nSizeImage == 0) {
            nSizeImage = ((((nWidth * nBitCount) + 31) & ~31) >> 3);
            nSizeImage *= nHeight;
        }

        int npalette[] = new int[nNumColors];
        byte bpalette[] = new byte[nNumColors * 4];
        readBuffer(input, bpalette);
        int nindex8 = 0;

        for (int n = 0; n < nNumColors; n++) {
            npalette[n] = (255 & 0xff) << 24 |
                    (bpalette[nindex8 + 2] & 0xff) << 16 |
                    (bpalette[nindex8 + 1] & 0xff) << 8 |
                    (bpalette[nindex8 + 0] & 0xff);

            nindex8 += 4;
        }

        int npad8 = (nSizeImage / nHeight) - nWidth;
        BufferedImage bufferedImage = new BufferedImage(nWidth, nHeight, BufferedImage.TYPE_INT_ARGB);
        DataBufferInt dataBufferByte = ((DataBufferInt) bufferedImage.getRaster().getDataBuffer());
        int[][] bankData = dataBufferByte.getBankData();
        byte bdata[] = new byte[(nWidth + npad8) * nHeight];

        readBuffer(input, bdata);
        nindex8 = 0;

        for (int j8 = nHeight - 1; j8 >= 0; j8--) {
            for (int i8 = 0; i8 < nWidth; i8++) {
                bankData[0][j8 * nWidth + i8] = npalette[((int) bdata[nindex8] & 0xff)];
                nindex8++;
            }
            nindex8 += npad8;
        }

        return bufferedImage;
    }

    private static BufferedImage read24BitBitmap(int nSizeImage, int nHeight, int nWidth, InputStream input) throws IOException {
        int npad = (nSizeImage / nHeight) - nWidth * 3;
        if (npad == 4 || npad < 0)
            npad = 0;
        int nindex = 0;
        BufferedImage bufferedImage = new BufferedImage(nWidth, nHeight, BufferedImage.TYPE_4BYTE_ABGR);
        DataBufferByte dataBufferByte = ((DataBufferByte) bufferedImage.getRaster().getDataBuffer());
        byte[][] bankData = dataBufferByte.getBankData();
        byte brgb[] = new byte[(nWidth + npad) * 3 * nHeight];

        readBuffer(input, brgb);

        for (int j = nHeight - 1; j >= 0; j--) {
            for (int i = 0; i < nWidth; i++) {
                int base = (j * nWidth + i) * 4;
                bankData[0][base] = (byte) 255;
                bankData[0][base + 1] = brgb[nindex];
                bankData[0][base + 2] = brgb[nindex + 1];
                bankData[0][base + 3] = brgb[nindex + 2];
                nindex += 3;
            }
            nindex += npad;
        }

        return bufferedImage;
    }

    private static int bytesToInt(byte[] bytes, int index) {
        return (bytes[index + 3] & 0xff) << 24 |
                (bytes[index + 2] & 0xff) << 16 |
                (bytes[index + 1] & 0xff) << 8 |
                bytes[index + 0] & 0xff;
    }

    private static short bytesToShort(byte[] bytes, int index) {
        return (short) (((bytes[index + 1] & 0xff) << 8) |
                (bytes[index + 0] & 0xff));
    }

    private static void readBuffer(InputStream in, byte[] buffer) throws IOException {
        int bytesRead = 0;
        int bytesToRead = buffer.length;
        while (bytesToRead > 0) {
            int read = in.read(buffer, bytesRead, bytesToRead);
            bytesRead += read;
            bytesToRead -= read;
        }
    }
}

7  Game Development / Newbie & Debugging Questions / Re: find all implementors of an interface? on: 2004-06-28 23:46:12
Quote
And then make it all available as a tiny self-contained JAR, with no reserved rights other than authorship details...

Duncan?


I was given permission to post the code with the intent to give back to the community, so I think that sounds great.

8  Java Game APIs & Engines / Java 2D / Re: custom Scrollable Component? on: 2004-06-23 21:02:17
Using JScrollPane, ScrollablePicture, and ImageIcon as described here
http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html I was able to display the 22meg image and scroll with good performance.  

Unfortunately it took me a very long time to generate the image, so I will be investigating the methods you guys have mentioned for generating only what I need to display.

thanks!
9  Java Game APIs & Engines / Java 2D / Re: custom Scrollable Component? on: 2004-06-23 15:56:26
The image is a representation of float data already in memory.  In this example, the 22meg image would have been generated via a simple algorithm from 2.4meg (33*20,000*4) of floats.

> 60000*100*4 is only 22meg or so - whats the problem with loading the entire image in (if its from a file)?

Perhaps I'm being overly pessimistic.  I'll give this a try with the complete image and standard Swing, and post my results.
10  Java Game APIs & Engines / Java 2D / custom Scrollable Component? on: 2004-06-23 00:23:10
Hello

The task before me is to scroll a HUGE image, preferably using Swing.  The image is going to be on the order of 100 pixels by 60,000 pixels.  I don't want to create an image that big or create a bunch of tiles that add up to it, but rather generate the visible portion of the image on the fly.  Basically I want a JTable-like widget that only draws what is visible and scrolls quickly.  In fact JTable would be useful if I could actually get cells that were 3 pixels by 3 pixels with absolutely no space between them.  [ JTable.setIntercellSpacing( new Dimension( 0, 0 ) ) leads to intercell spacing of 2 pixels.  perhaps I'm using that wrong. ]

I'm fairly confident I can do this with a custom Component wired to a JScrollbar through an AdjustmentListener.  I had hoped to find examples somewhere that used JScrollPane and a custom widget, but nothing is coming up.  

Any thoughts or pointers to examples appreciated.


- duncan
11  Discussions / Miscellaneous Topics / Re: What's orange, and sounds like a parrot? on: 2004-06-05 00:01:10
How many surrealists does it take to screw in a lightbulb?

banana.

12  Game Development / Newbie & Debugging Questions / Re: trouble loading images in Applet on: 2004-05-27 23:59:14
Quote
Regarding forward & backward slashes...
Try something like java.io.File.separator (a String) or java.io.File.separatorChar (a primitive char).

In case you still care :-/


The thing is, the slashes I'm talking about are in the HTML of the page that launches my applet Huh  But I suppose if I was writing a JSP and used File.separatorChar I'd get the correct slash and things would be cool.
13  Game Development / Newbie & Debugging Questions / Re: trouble loading images in Applet on: 2004-05-27 23:56:44
Quote


Might be the ImageIO bug. You could try the following workaround in the second block:

1  
background = ImageIO.read(new BufferedInputStream(getClass().getResourceAsStream("logo2.jpg") )); 


I tried this (with the right filename ), but background remains null after the try and then the code blows up.  Wild.  Well, I'm off 'til Tuesday celebrating my new Junior Member status all weekend!  woohoo!

/duncan  
14  Game Development / Newbie & Debugging Questions / Re: trouble loading images in Applet on: 2004-05-27 19:42:31
Quote
You aren't using ImageIO so it could be something completely different.

Actually I am, in the second block of code.  That same code always works from a doubleclick jar which contains the jpg, but it seems that something is different when it's run in the browser.  Again, it works in the appletviewer, so I suppose it's the plugin JVM or IE generally mucking with me.
15  Game Development / Newbie & Debugging Questions / Re: trouble loading images in Applet on: 2004-05-27 19:10:07
Yup.  It must be that I'm running off a directory in XP using Internet Explorer.  

Any thoughts on the jar'd image decoding all chunky?
16  Game Development / Newbie & Debugging Questions / Re: trouble loading images in Applet on: 2004-05-26 01:13:21
Gross!  The problem I was having with Applet.getImage(...) was that I wasn't using forward slashes!

Wrong: <PARAM name="splash_image" value="splash/images/tgen_logo2.jpg">
Correct:  <PARAM name="splash_image" value="splash\\images\\tgen_logo2.jpg">

I still have no idea why I couldn't load from the jar, but now it doesn't really matter.

Cheers!
17  Game Development / Newbie & Debugging Questions / trouble loading images in Applet on: 2004-05-26 00:06:33
UPDATE:  both methods currently work in the AppletViewer but not Internet Exploder

I am having a heck of a time loading images in my applet.  Since the project has just begun, I'm launching from a directory on my computer.  Using JRE version 1.4.2 Java HotSpot(TM) Client VM, No proxy.

The first problem I noticed is that Applet.getDocumentBase() is returning the wrong thing.  It's supposed to return a URL to the directory that the HTML page lives in, but no, it returns a URL to the HTML page itself.  Fine, I'll cull the real base out of the URL.  I put together a real document base URL and try Applet.getImage().

It never worked.  I draw the image and there's just nothing there.  I switched my code around to use a MediaTracker ala nonnus29's game tutorial ( thanks! ) but now I just know that I have errors.  I'm really stuck on this one.  How do I find out what the error was?  Why is my documentBase screwed up?

Perhaps even more interesting is what happens when I load the image from the jar.  Using my old fade-in Splash Screen code I got some weird results.  It opens the image and "reads" it without error, but the image loaded is mostly screwed up.  You can tell it came from my image file, but more than half of it looks like stretched out pixels.  But it fades in nicely!  Sure glad to see my rendering loop and bufferstrategy work cause not much else is.

this always prints "Error loading Image"
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  
            URL docBase = getDocumentBase();
        String docPath = docBase.toString();
        if ( !docPath.endsWith("/") ) {
              // java gave us the file name, not the actual base
             // maybe this only happens with files
             int pos = docPath.lastIndexOf('/');
              docPath = docPath.substring(0, pos );
        }
        URL realDocBase = null;
        try {
              realDocBase = new URL( docPath );
              
        } catch (MalformedURLException mfux ) {
              mfux.printStackTrace();
              throw new RuntimeException( "cannot open images" );
              
        }
        System.out.println( realDocBase );
          MediaTracker t = new MediaTracker (this);
          image = getImage(realDocBase,getParameter("splash_image" ));
          t.addImage(image,0);
          try  {
              t.waitForAll();
          }
          catch (InterruptedException e) {}
          if (t.isErrorAny())  {
              System.out.println("Error loading Image");
          }


And this loads a broken image from the jar
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  
29  
private void loadImage() {
          BufferedImage background = null;
          URL imageURL = getClass().getClassLoader().getResource( "logo2.jpg");
          try {
              background = ImageIO.read( imageURL );

          } catch ( IOException e ) {
              System.err.println( "couldn't load image" );
              e.printStackTrace();  //To change body of catch statement use Options | File Templates.
         }
          compatible = graphicsConfig
            .createCompatibleImage(background.getWidth(), background.getHeight(),
                Transparency.BITMASK);

          backBuffer = graphicsConfig
                    .createCompatibleImage(background.getWidth(), background.getHeight(),
                        Transparency.BITMASK);

          Graphics g = null;
          try {
              g = compatible.getGraphics();
              g.drawImage(background, 0, 0, null);
          } finally {
              if (g != null)
                  g.dispose();
          }
          background = null;

     }


Thanks!
18  Discussions / Miscellaneous Topics / Re: Rant: Why parallel processing will never take on: 2004-05-14 00:50:34
Quote

You judge from some lines of code to the habits of a whole group?

He did say it was a rant!  I've read through enough researcher code to have a sympathic ear, but I'd stop short of damning all of || computing.  
19  Discussions / Miscellaneous Topics / Re: building my own computer on: 2004-05-14 00:40:50
http://arstechnica.com/news/posts/1084398037.html
Quote
Video Array is an accelerated graphics processing subsystem that will allow users to add multiple, off-the-shelf video cards to their Alienware computer systems and have both cards process graphic commands in parallel...
Alienware is currently saying that they expect users to see a ~50% performance boost over single card implementations

Awww yeah!  Note that the Video Array uses PCI Express cards. Roll Eyes


20  Game Development / Artificial Intelligence / Re: [AI] Java Rules engines - especially Rete-base on: 2004-04-19 18:26:33
For what it's worth I used JESS on a project about 3 years ago.  We optimized our code to death and it was still too slow for needs.  We were running an extraction engine on a news feed and the JESS component was at the end of the pipeline.  Ultimately we decided on a homegrown XML rule language which was translated into compilable code giving us the flexibility of a rule language and the speed of a hardcoded solution.

The inventor of RETE has made a RETE2 algorithm which he claims is faster for large amounts of data.
Rete II: http://www.pst.com/rete2.htm
OPSJ: http://www.pst.com/opsjbro.htm ( the java based Rete II engine )
There's a development license but no runtime license.  Might be worth looking into.
21  Discussions / Miscellaneous Topics / Re: building my own computer on: 2004-04-19 18:05:51
Quote
 Also, don't worry about FSB above 400MHz

I'm curious to hear your reasoning on the FSB, as it sets the speed limit for memory and all future upgrades.  Which leads to another of the Athlon64's advantages: since it has a memory controller on dye, it can run the board at the frequency of the chip ( or at least the memory. )  I don't have my special issue of MaximumPC in front of me, but I was reading about it last month in their "355 PC questions answered" issue.
22  Discussions / Miscellaneous Topics / Re: building my own computer on: 2004-04-19 15:59:04
Raghar

> I thought about 2.4 GHz Celleron, or a low end prescott.

The Prescotts have not been getting the kind of press I'd like to see.  Basically they aren't any faster than the cheaper Northwoods.  

> 256 MB RAM

You'll want at least 512 if you are running XP and want performance.  I want a gig so I can edit video or run doom3 in memory.

> How long is waranty for that memory?

That's a good question, and I don't know, but Cosair seems to be the quality reccomendation across the board.

> Actually I don't understand why do you want both DVD burner and CD-RW?

There's no good reason, just the convience of two trays for copying.
23  Discussions / Miscellaneous Topics / Re: building my own computer on: 2004-04-15 19:00:36
I *almost* built a new computer recently, but I choose to wait.  Here are the specs and then my reasons for waiting.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
Case: Lian Li PC-65 PC Case w/ 480W or higher name brand PSU - $191
Processor: Athlon 64 3400+ Retail - $423
Cooling: Retail Heatsink/Fan - $0
Motherboard: ASUS K8V Deluxe - $139
Memory: 2 X 512-MB Corsair TwinX XMS DDR400/PC3200LL - $249
Hard Drive: Western Digital 250 GB 7200RPM SATA - $212
Video Card: ATI Radeon 9800 Pro- $421
Sound Card: SoundBlaster Audigy Platinum 2 ZS Retail - $166
Speakers: Logitech Z-680 5.1 - $284
CD-ROM/DVD-RW: NEC 8X DVD+RW/-RW ND-2500A OEM - $121
CD-RW: Lite-On 52x32x52 CD-RW LTR-52327S - $33
Mouse: MSFT Explorer - $30
Keyboard: Microsoft Natural Multimedia Keyboard - $20
Operating System: Windows XP Pro - $134
Total: USD 2423

It's been years, so I was going all out.  I've decided to wait a bit for three reasons:
  • DDR2 compatible mobos
  • PCI Express compatible mobos
  • BTX form factor
That's three big changes set to hit the market any days now.  Will I buy DDR2 memory?  No.  Will I get a PCI Express Graphics card?  Maybe!  Do I want a motherboard that is ready to upgrade to that stuff?  Definitely.
I'd love to hear opinions on this.  I really need a new machine at home and I'm trying to draw the line between upgradable and not-worth-waiting for.
24  Discussions / Miscellaneous Topics / Re: 40 posts and I'm still a newbie? on: 2004-04-08 17:49:41
Quote
duncan, you will ALWAYS be a newbie ...  Grin

Ooooooo!  That was so low I don't feel bad about replying and padding my posts Wink

25  Discussions / Miscellaneous Topics / 40 posts and I'm still a newbie? on: 2004-04-07 21:06:42
Maybe 41 will do it Tongue
26  Game Development / Newbie & Debugging Questions / Re: find all implementors of an interface? on: 2004-04-07 21:00:59
Good point.

This version of ClassPath fixes that issue ( use with SubClasses above ) by scanning the manifest and digging through any Class-Path entries.

note:  javac assumes Class-Path entries are relative to the path of the jar they are in, so I do as well!!  I have tested this with a main.jar, a second.jar referenced in main's manifest, and a third.jar referenced in second.jar's manifest.

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  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
250  
251  
252  
253  
254  
255  
256  
257  
258  
259  
260  
261  
262  
263  
264  
265  
266  
267  
268  
269  
270  
271  
272  
273  
274  
275  
276  
277  
278  
279  
280  
281  
282  
283  
284  
285  
286  
287  
288  
289  
290  
291  
292  
293  
294  
295  
296  
297  
298  
299  
300  
301  
302  
303  
304  
305  
306  
307  
308  
309  
310  
311  
312  
313  
314  
315  
316  
317  
318  
319  
320  
321  
322  
323  
324  
325  
326  
327  
328  
329  
330  
331  
332  
333  
334  
335  
336  
337  
338  
339  
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;


/**
 * Created with Eclipse
 * User: duncanIdaho for java-gaming.org
 *
 */


/**
 * ClassPath find and records the fully qualified name of every Class
 * on the classpath via the system property "java.class.path".
 *
 */

public class ClassPath {
     
      public static final int SILENT = 0;
      public static final int QUIET = 1;
      public static final int VERBOSE = 2;
     
      public static final String JAR_EXT = ".jar";
      public static final String ZIP_EXT = ".zip";
      public static final String CLASS_EXT = ".class";

      private ArrayList classNames;
     
      private int outputLevel;
     
      /**
       * create a new ClassPath instance and find all classes on the classpath
       *
       */

      public ClassPath() {
            this( SILENT );
           
      }
     
     
      public ClassPath(int type) {
            super();
            outputLevel = type;
            findAllClassNames();
     
      }
     
      /**
       * Answers an <code>Iterator</code> over fully qualified <code>Class</code>
       * names found on the classpath.
       * @return an <code>Iterator</code> over the elements in this list
       */

      public Iterator classNameIterator() {
            return classNames.iterator();
           
      }
     
      /**
       * Answers an <code>ArrayList</code> of all <code>Class</code> names found
       * on the classpath.
       * @return an <code>ArrayList</code> of class names.
       */

      public ArrayList getClassNames() {
            return classNames;
           
      }

      /**
       * Initialize the member variable <code>classNames</code> and
       * look for classes.
       *
       */

      private void findAllClassNames() {
            String path = null;
            classNames = new ArrayList();
            try {
                  path = System.getProperty( "java.class.path" );
            } catch ( Exception x ) {
                  x.printStackTrace();
                 
            }
            if ( outputLevel != SILENT )
                  System.out.println( "scanning classpath: " + path );
            StringTokenizer toke = new StringTokenizer( path, File.pathSeparator );
           
            analyzeClasspathTokens( toke );

            if ( outputLevel != SILENT )
                  System.out.println( "found " + classNames.size() + " classes." );
           
            if ( outputLevel == VERBOSE ) {
                  Iterator i = classNames.iterator();
                  while ( i.hasNext() ) {
                        String name = (String)i.next();
                        System.out.println( name );
                       
                  }
                 
            }
           
      }
     
      /**
       * Adds a file explicitly mentioned on the classpath to the list
       * of classes.
       * @param classFile a class file listed on the classpath itself.
       */

      private void addClass( File classFile ) {
            classNames.add( getClassNameFrom( classFile.getName() ) );
           
      }
     
      /**
       * Adds all class names found in the jar.
       * @param jarFile a jar file explicitly listed on the classpath.
       */

      private void addJarContents( File jarFile ) {
            JarFile jar = null;
            try {
                  jar = new JarFile( jarFile );

            } catch ( IOException iox ) {
                  // boom!
           }
            if ( jar != null ) {
                  Manifest man = null;
                  try {
                        man = jar.getManifest();
                  } catch( IOException iox ) {
                        System.err.println("error obtaining manifest from: " + jar.getName());
                       
                  } finally {
                        if ( man != null ) {
                              this.scanClasspath( man, jar, jarFile );
                             
                        }
                       
                  }
                  Enumeration e = jar.entries();
                  while (e.hasMoreElements()) {
                        JarEntry entry = (JarEntry)e.nextElement();
                        if ( !entry.isDirectory() && entry.getName().endsWith( CLASS_EXT ) ) {
                              String className = getClassNameFrom( entry.getName() );
                              classNames.add( className );

                        }
                 
                  }      

            }
           
      }
     
      /**
       * Adds all class names found in the zip mentioned
       * @param zipFile
       */

      private void addZipContents( File zipFile ) {
            ZipFile zip = null;
            try {
                  zip = new JarFile( zipFile );
                 
            } catch ( IOException iox ) {
                 
            }
            if ( zip != null ) {
                  Enumeration e = zip.entries();
                  while (e.hasMoreElements()) {
                        ZipEntry entry = (ZipEntry)e.nextElement();
                        if ( !entry.isDirectory() && entry.getName().endsWith( CLASS_EXT ) ) {
                              String className = getClassNameFrom( entry.getName() );
                              classNames.add( className );
                             
                        }
                  }      
            }      
      }

      /**
       * This method takes a top level classpath dir i.e. 'classes' or bin
       * @param dir
       */

      private void addDirectoryContents( File dir ) {
            // drill through contained dirs ... this is expected to be the
           // 'classes' or 'bin' dir
           File files[] = dir.listFiles();
            for( int i = 0; i < files.length ; ++i ) {
                  File f = files[i];
                  if ( f.isDirectory() ) {
                        addDirectoryContents( "", f );
                       
                  } else {
                        if ( f.getName().endsWith( CLASS_EXT ) )
                              addClass( f );
                                   
                  }
                 
            }
           
      }
     
      /**
       * This method does the real directory recursion, passing along the
       * the corresponding package-path to this directory.
       *
       * @param pathTo the preceding path to this directory
       * @param dir a directory to search for class files
       */

      private void addDirectoryContents( String pathTo, File dir ) {
            String pathToHere = pathTo + dir.getName() + File.separator;
            File files[] = dir.listFiles();
            for( int i = 0; i < files.length ; ++i ) {
                  File f = files[i];
                  if ( f.isDirectory() ) {
                        addDirectoryContents( pathToHere, f );
                       
                  } else {
                        if ( f.getName().endsWith( CLASS_EXT ) ) {
                              String absFilePath = pathToHere + f.getName();
                              classNames.add( getClassNameFrom( absFilePath ) );
                             
                        }
                                   
                  }
                 
            }
           
      }
     
      /**
       * While the StringTokenizer has classpath elements, attempt to
       * add any contained classes to the list.
       *
       * @param toke class path elements
       */

      private void analyzeClasspathTokens( StringTokenizer toke ) {
            while ( toke.hasMoreTokens()) {
                  String pathElement = toke.nextToken();
                  analyzeClasspathElement( pathElement );

            }
           
      }
     
      /**
       * Make a file out of the String, determine which kind of
       * interesting classpath file it might be, and add it to the list.
       *
       * @param pathElement
       */

      private void analyzeClasspathElement( String pathElement ) {
            File elementFile = new File( pathElement );
            String elementName = elementFile.getAbsolutePath();
            if ( elementName.endsWith( JAR_EXT ) ) {
                  addJarContents( elementFile );
                 
            } else if ( elementName.endsWith( ZIP_EXT ) ) {
                  addZipContents( elementFile );
                 
            } else if ( elementName.endsWith( CLASS_EXT ) ) {
                  addClass( elementFile );
                 
            } else {
                  addDirectoryContents( elementFile );
                 
            }
           
      }
     
      /**
       * replace ANY slashes with dots and remove the .class at the
       * end of the file name.
       * @param entryName a file name relative to the classpath.  A class
       * of package org found in directory bin would be passed into this
       * method as "org/MyClass.class"
       * @return a fully qualified Class name.
       */

      private String getClassNameFrom( String entryName ) {
            String foo = new String(entryName).replace( '/', '.' );
            foo = foo.replace( '\\', '.' );
            return foo.substring( 0, foo.lastIndexOf( '.' ) );
           
      }
     
      /**
       * Use the manifest associated with the jar to determine if there are
       * any Class-Path elements names in the jar that should also be scanned.
       *
       * @param man the manifest of the given jar
       * @param jar the jar associated with the given manifest.
       */

      private void scanClasspath( Manifest man, JarFile jar, File jarFile ) {
            Map map = man.getEntries();
            if ( map != null ) {
                  Attributes atts = man.getMainAttributes();
                  if ( atts != null ) {
                        Set keys = atts.keySet();
                        Iterator i = keys.iterator();
                        while ( i.hasNext() ) {
                              Object key = (Object)i.next();
                              String value = (String)atts.get( key );
                              if ( outputLevel == VERBOSE )
                                    System.out.println( jar.getName() + "  " + key + ": " + value );
                              if ( key.toString().equals( "Class-Path" )) {
                                    if ( outputLevel != SILENT )
                                          System.out.println( "scanning " + jar.getName() +"'s manifest classpath: " + value);
                                    StringTokenizer toke = new StringTokenizer( value );
                                    while (toke.hasMoreTokens() ) {
                                          String element = toke.nextToken();
                                          if ( jarFile.getParent() == null )
                                                analyzeClasspathElement( element );
                                          else {
                                                analyzeClasspathElement( jarFile.getParent() + File.separator +  element );
                                          }
                                         
                                    }
                                   
                              }
                             
                        }
                       
                  }      
                 
            }
           
      }

}
27  Game Development / Newbie & Debugging Questions / Re: find all implementors of an interface? on: 2004-04-06 23:07:53
Not exactly a timely post, but here is code to find all subclasses of a class (or all implementors of an interface) on your classpath.  

To use it, add these classes to your classpath and from somewhere in your program call:  
Class[] interestingClasses = Subclasses.of( MyInterface.class );
// or add a regex
Class[] interestingClasses = Subclasses.of( MyClass.class, ".*Suffix$ );
Once you have the array of classes you can instantiate them with relfection, but I beleive that only works if your class has an empty constructor.

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  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
import java.util.ArrayList;
import java.util.Iterator;

/**
 * Created with Eclipse
 * User: duncanIdaho for java-gaming.org
 *
 * copyright 2004
 */


/**
 * A class to find all subclasses of a given <code>Class</code> or interface.
 *
 */

public class Subclasses {
     
      /**
       * Find all subclasses of the given <code>Class</code> or interface by
       * loading all classes on the class path.
       *
       * @param targetType the superclass of all returned classes.
       * @return an array of all subclasses of <code>targetType</code>
       */

      public static Class[] of( Class targetType ) {
            return of( targetType, ".*" );
           
      }
     
      /**
       * Find all subclasses of the given <code>Class</code> or interface by
       * loading only those classes with names that match the given regular
       * expression.
       *
       * @param targetType the superclass of all returned classes.
       * @param regex a regular expression that will match with every subclass
       * @return an array of all subclasses of <code>targetType</code>
       */

      public static Class[] of( Class targetType, String regex ) {
            ArrayList matches = new ArrayList();
            ClassPath cp = new ClassPath();
            Iterator i = cp.classNameIterator();
            while ( i.hasNext() ) {
                  String className = (String)i.next();
                  if ( className.matches( regex ) &&
                              !className.equals( targetType.getName() ) ) {
                        Class clazz = null;
                        try {
                              clazz = Class.forName( className );
                             
                        } catch (ClassNotFoundException cnfx ) {
                              continue;
                             
                        } finally {
                              if ( clazz != null && targetType.isAssignableFrom( clazz ) ) {
                                    matches.add( clazz );
                                   
                              }
                             
                        }
                       
                  }
                 
            }
            return (Class[])matches.toArray( new Class[0] );
           
      }
     
}

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  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
250  
251  
252  
253  
254  
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;


/**
 * Created with Eclipse
 * User: duncanIdaho for java-gaming.org
 *
 * copyright 2004
 */



/**
 * ClassPath find and records the fully qualified name of every Class
 * on the classpath via the system property "java.class.path".
 *
 */

public class ClassPath {
     
      public static final int SILENT = 0;
      public static final int QUIET = 1;
      public static final int VERBOSE = 2;
     
      public static final String JAR_EXT = ".jar";
      public static final String ZIP_EXT = ".zip";
      public static final String CLASS_EXT = ".class";

      private ArrayList classNames;
     
      private int outputLevel;
     
      /**
       * create a new ClassPath instance and find all classes on the classpath
       *
       */

      public ClassPath() {
            this( SILENT );
           
      }
     
     
      public ClassPath(int type) {
            super();
            outputLevel = type;
            findAllClassNames();
     
      }
     
      /**
       * Answers an <code>Iterator</code> over fully qualified <code>Class</code>
       * names found on the classpath.
       * @return an <code>Iterator</code> over the elements in this list
       */

      public Iterator classNameIterator() {
            return classNames.iterator();
           
      }
     
      /**
       * Answers an <code>ArrayList</code> of all <code>Class</code> names found
       * on the classpath.
       * @return an <code>ArrayList</code> of class names.
       */

      public ArrayList getClassNames() {
            return classNames;
           
      }

      /**
       * Initialize the member variable <code>classNames</code> and
       * look for classes.
       *
       */

      private void findAllClassNames() {
            String path = null;
            classNames = new ArrayList();
            try {
                  path = System.getProperty( "java.class.path" );
            } catch ( Exception x ) {
                  x.printStackTrace();
                 
            }
            if ( outputLevel != SILENT )
                  System.out.println( "scanning classpath: " + path );
            StringTokenizer toke = new StringTokenizer( path, File.pathSeparator );
            while ( toke.hasMoreTokens()) {
                  String pathElement = toke.nextToken();
                  File elementFile = new File( pathElement );
                  String elementName = elementFile.getAbsolutePath();
                  if ( elementName.endsWith( JAR_EXT ) ) {
                        addJarContents( elementFile );
                       
                  } else if ( elementName.endsWith( ZIP_EXT ) ) {
                        addZipContents( elementFile );
                       
                  } else if ( elementName.endsWith( CLASS_EXT ) ) {
                        addClass( elementFile );
                       
                  } else {
                        addDirectoryContents( elementFile );
                       
                  }

            }
            if ( outputLevel != SILENT )
                  System.out.println( "found " + classNames.size() + " classes." );
           
            if ( outputLevel == VERBOSE ) {
                  Iterator i = classNames.iterator();
                  while ( i.hasNext() ) {
                        String name = (String)i.next();
                        System.out.println( name );
                       
                  }
                 
            }
           
      }
     
      /**
       * Adds a file explicitly mentioned on the classpath to the list
       * of classes.
       * @param classFile a class file listed on the classpath itself.
       */

      private void addClass( File classFile ) {
            classNames.add( getClassNameFrom( classFile.getName() ) );
           
      }
     
      /**
       * Adds all class names found in the jar.
       * @param jarFile a jar file explicitly listed on the classpath.
       */

      private void addJarContents( File jarFile ) {
            JarFile jar = null;
            try {
                  jar = new JarFile( jarFile );

            } catch ( IOException iox ) {
                  // boom!
           }
            if ( jar != null ) {
                  Enumeration e = jar.entries();
                  while (e.hasMoreElements()) {
                        JarEntry entry = (JarEntry)e.nextElement();
                        if ( !entry.isDirectory() && entry.getName().endsWith( CLASS_EXT ) ) {
                              String className = getClassNameFrom( entry.getName() );
                              classNames.add( className );

                        }
                  }      
            }
      }
     
      /**
       * Adds all class names found in the zip mentioned
       * @param zipFile
       */

      private void addZipContents( File zipFile ) {
            ZipFile zip = null;
            try {
                  zip = new JarFile( zipFile );
                 
            } catch ( IOException iox ) {
                 
            }
            if ( zip != null ) {
                  Enumeration e = zip.entries();
                  while (e.hasMoreElements()) {
                        ZipEntry entry = (ZipEntry)e.nextElement();
                        if ( !entry.isDirectory() && entry.getName().endsWith( CLASS_EXT ) ) {
                              String className = getClassNameFrom( entry.getName() );
                              classNames.add( className );
                             
                        }
                  }      
            }      
      }

      /**
       * This method takes a top level classpath dir i.e. 'classes' or bin
       * @param dir
       */

      private void addDirectoryContents( File dir ) {
            // drill through contained dirs ... this is expected to be the
           // 'classes' or 'bin' dir
           File files[] = dir.listFiles();
            for( int i = 0; i < files.length ; ++i ) {
                  File f = files[i];
                  if ( f.isDirectory() ) {
                        addDirectoryContents( "", f );
                       
                  } else {
                        if ( f.getName().endsWith( CLASS_EXT ) )
                              addClass( f );
                                   
                  }
                 
            }
           
      }
     
      /**
       * This method does the real directory recursion, passing along the
       * the corresponding package-path to this directory.
       *
       * @param pathTo the preceding path to this directory
       * @param dir a directory to search for class files
       */

      private void addDirectoryContents( String pathTo, File dir ) {
            String pathToHere = pathTo + dir.getName() + File.separator;
            File files[] = dir.listFiles();
            for( int i = 0; i < files.length ; ++i ) {
                  File f = files[i];
                  if ( f.isDirectory() ) {
                        addDirectoryContents( pathToHere, f );
                       
                  } else {
                        if ( f.getName().endsWith( CLASS_EXT ) ) {
                              String absFilePath = pathToHere + f.getName();
                              classNames.add( getClassNameFrom( absFilePath ) );
                             
                        }
                                   
                  }
                 
            }
           
      }
     
      /**
       * replace ANY slashes with dots and remove the .class at the
       * end of the file name.
       * @param entryName a file name relative to the classpath.  A class
       * of package org found in directory bin would be passed into this
       * method as "org/MyClass.class"
       * @return a fully qualified Class name.
       */

      private String getClassNameFrom( String entryName ) {
            String foo = new String(entryName).replace( '/', '.' );
            foo = foo.replace( '\\', '.' );
            return foo.substring( 0, foo.lastIndexOf( '.' ) );
           
      }

}
28  Java Game APIs & Engines / JOGL Development / Re: native code crashes on: 2004-04-06 22:25:32
It works!  Woohoo!  Thanks so much.

29  Game Development / Newbie & Debugging Questions / Re: How to get in to Java games programming? on: 2004-04-02 00:03:09
To add to the good advice above I'll say that I learned a LOT by reading these forums, searching the archives, and picking apart sample code found on the site.

There are many technologies out there and choosing one can be really tough if you want your game to run on many platforms.  I agree with a previous poster that you should start 2D, and that J2SE is a nice place to start using the Java2D APIs.

Finally I'll plug a great book in line with my suggestion:  Vincent J. Hardy's "Java 2D API Graphics" ISBN 0-13-014266-2.  Easy to read with great pictures although it never mentions game programming.
30  Discussions / Miscellaneous Topics / Re: Sun Makes Linux 3D on: 2004-04-01 23:39:44
Quote
I am actually referring in a very straightforward, straightfaced and honest way to women, who are genuinely wired differently. Present a 3D interface to Jane Doe and she'll just be totally baffled.


My girlfriend gets sick to her stomach just watching me play Quake3.  She would never in a million years want a 3D desktop.  

I do though!  putting windows far into the screen seems kinda cool.  No more guessing what percent-size to view your document at, just slide your window in or out.  I can see Photoshop and the like being more fun to use with the ability to see things overlaid just by moving windows around.  Rendering your background onto a surface might be cool too.  All eye candy though.

Pages: [1] 2 3
 

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

The first screenshot will be displayed as a thumbnail.

Riven (11 views)
2014-07-29 18:09:19

Riven (8 views)
2014-07-29 18:08:52

Dwinin (9 views)
2014-07-29 10:59:34

E.R. Fleming (25 views)
2014-07-29 03:07:13

E.R. Fleming (10 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (27 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!