import java.awt.*;
import javax.swing.*;
import java.awt.image.*;
import java.io.*;
public class AnimationTester extends JFrame implements Runnable
{
public static void main(String args[]) throws IOException
{
AnimationTester at = new AnimationTester();
at.show();
new Thread(at).start();
}
Toolkit tk;
int frame;
int delay;
int distance;
Image tile;
Image[] upFrame;
Image[] downFrame;
Image[] leftFrame;
Image[] rightFrame;
public AnimationTester() throws IOException
{
super("Animation Tester");
setSize(600,600);
tk = Toolkit.getDefaultToolkit();
frame = 0;
delay = 150;
loadFiles();
}
void loadFiles() throws IOException
{
BufferedReader buffer = new BufferedReader(new FileReader(new File("settings.txt")));
delay = Integer.parseInt(buffer.readLine(),10);
distance = Integer.parseInt(buffer.readLine(),10);
upFrame = new Image[Integer.parseInt(buffer.readLine(),10)];
for(int i=0; i = tk.getImage(buffer.readLine());
downFrame = new Image[Integer.parseInt(buffer.readLine(),10)];
for(int i=0; i = tk.getImage(buffer.readLine());
leftFrame = new Image[Integer.parseInt(buffer.readLine(),10)];
for(int i=0; i<leftFrame.length; ++i)
leftFrame = tk.getImage(buffer.readLine());
rightFrame = new Image[Integer.parseInt(buffer.readLine(),10)];
for(int i=0; i<rightFrame.length; ++i)
rightFrame = tk.getImage(buffer.readLine());
}
public void run()
{
while(true)
{
Thread thisThread = Thread.currentThread();
try{thisThread.sleep(delay);}
catch (InterruptedException e){}
frame++;
repaint();
}
}
Image offScreenBuffer;
public void update(Graphics g)
{
Graphics gr;
if (offScreenBuffer==null || (! (offScreenBuffer.getWidth(this) == this.size().width &&
offScreenBuffer.getHeight(this) == this.size().height)))
offScreenBuffer = this.createImage(size
().width, size().height);
gr = offScreenBuffer.getGraphics();
paint(gr);
g.drawImage(offScreenBuffer, 0, 0, this);
}
public void paint(Graphics g)
{
int x;
int y;
y = 600-distance*(frame%(9*upFrame.length));
x = 60;
g.drawImage(upFrame[frame%upFrame.length],x,y, this);
y = 60+distance*(frame%(9*downFrame.length));
x = 540;
g.drawImage(downFrame[frame%downFrame.length],x,y, this);
x = 60+distance*(frame%(9*rightFrame.length));
y = 60;
g.drawImage(rightFrame[frame%rightFrame.length],x,y, this);
x = 600-distance*(frame%(9*leftFrame.length));
y = 60;
g.drawImage(leftFrame[frame%leftFrame.length],x,y, this);
}
}
</pre> </i>
hmm not sure how to fix this, the pre tags turned into code tags, sorry about the word wrap
Edited by - pleaseHelpMe on 10/20/00 12:17:12 AM
[java] I can't make a program from source
I quickly threw together a simple program to test the animation frames that my friend is making for our game, not too polished but none of the code will be used again. As far as I can tell it works properly, when run in the IDE (I'm using code warrior by the way) it gives an exception as expected (since the file it loads doesn't exist). So it works fine.
The problem is I'm not sure how to turn it into a program I can run. I found a command called "build" near compile. It seems to be the right one. Ok so I use it and it makes a .JAR file. If I go double click on the jar the hour glass comes up for about a second and then disappears. I cannot seem to get jar files to do anything. I might have something set up wrong, not sure. I found a menu where I can change what it makes.
If I choose application I get a .zip file, which is also useless. It just opens up the unzipper and shows me a .class file. If I double click on the .class file it opens up my IDE and says something about the debugger and then basically nothing happens. If I choose class folder it makes a folder with the class file in it, also basically useless.
So after doing all that I went to the sun site and learned how to do it with the console. I got to where the .java file was and typed: c:\jdk1.3\bin\javac AnimationTester.java and it worked, I got the .class file. Then I tried c:\jdk1.3\bin\java AnimationTester and this time it gave me an error: something like ClassDefNotFound. I tried it some more, with different options and then I tried all the same things in the IDE but it always gave me that, or sometimes a popup window saying that it couldn't fine AnimationTester, the error messages were all pretty much the same. I tried changing the .class filetype to automatically run c:\jdk1.3\bin\java but that also gave the same error.
I don't think it is my code causing the problem but here it is in case (the update() method was taken from a sun tutorial) thanks
path=%PATH%;i:\jdk1.3\bin
set CLASSPATH=.
I bet that fixes it.
I wanrned you! Didn't I warn you?! That colored chalk was forged by Lucifer himself!
Edited by - GKW on October 20, 2000 1:48:24 AM
set CLASSPATH=.
I bet that fixes it.
I wanrned you! Didn't I warn you?! That colored chalk was forged by Lucifer himself!
Edited by - GKW on October 20, 2000 1:48:24 AM
"... we should have such an empire for liberty as she has never surveyed since the creation ..."Thomas Jefferson
Depends on the os. win9598me in the autoexec.bat. winnt2k you can change it in the system setting. You can also just put it in a .bat file that you would run from the command line or you can just type it in at the command line before every session. Don''t know about *nix. Maybe someone else can explain what happens there.
I wanrned you! Didn't I warn you?! That colored chalk was forged by Lucifer himself!
I wanrned you! Didn't I warn you?! That colored chalk was forged by Lucifer himself!
"... we should have such an empire for liberty as she has never surveyed since the creation ..."Thomas Jefferson
I''d wonder if anything happens after doubleclicking a .jar file on an unprepared box. Java is, by itself, an interpreted language that needs its interpreter to run compiled files (.java files). If you want to enable your machine to run your game, I know three options:
1. Make an applet from your application, but remember the limitations of applets. Viewing the html-document the applet is embedded in starts the applet.
2. Register a new action for .java files: open My Computer, View, Folder Options, File Types (please don''t mind if it''s called different-I''m from germany, using a german Windows), select Java Programs (again, it MAY be called different, just look for .java files), click new, the action is called Run and the the application is called java (great for testing, too).
If you want to distribute your game, e.g. with InstallShield, look for the registry entries in
HKEY_CLASSES_ROOT\.java
HKEY_CLASSES_ROOT\java
HKEY_CLASSES_ROOT\java\shell
HKEY_LOCAL_MACHINE\Software\CLASSES\.java
HKEY_LOCAL_MACHINE\Software\CLASSES\java
HKEY_LOCAL_MACHINE\Software\CLASSES\java\shell
before and after defining the new action (this is WIN98, check the other Windows''es, too). You should include the exported registry trees
HKEY_CLASSES_ROOT\.java
HKEY_CLASSES_ROOT\java
HKEY_LOCAL_MACHINE\Software\CLASSES\.java
HKEY_LOCAL_MACHINE\Software\CLASSES\java
for each Windows in your distribution. Unfortunately, this works only for Windows boxes.
3. There are, as I learned, native compilers on every platform that generate executable code.
1. Make an applet from your application, but remember the limitations of applets. Viewing the html-document the applet is embedded in starts the applet.
2. Register a new action for .java files: open My Computer, View, Folder Options, File Types (please don''t mind if it''s called different-I''m from germany, using a german Windows), select Java Programs (again, it MAY be called different, just look for .java files), click new, the action is called Run and the the application is called java (great for testing, too).
If you want to distribute your game, e.g. with InstallShield, look for the registry entries in
HKEY_CLASSES_ROOT\.java
HKEY_CLASSES_ROOT\java
HKEY_CLASSES_ROOT\java\shell
HKEY_LOCAL_MACHINE\Software\CLASSES\.java
HKEY_LOCAL_MACHINE\Software\CLASSES\java
HKEY_LOCAL_MACHINE\Software\CLASSES\java\shell
before and after defining the new action (this is WIN98, check the other Windows''es, too). You should include the exported registry trees
HKEY_CLASSES_ROOT\.java
HKEY_CLASSES_ROOT\java
HKEY_LOCAL_MACHINE\Software\CLASSES\.java
HKEY_LOCAL_MACHINE\Software\CLASSES\java
for each Windows in your distribution. Unfortunately, this works only for Windows boxes.
3. There are, as I learned, native compilers on every platform that generate executable code.
When using code warrior you can do the following to compile and .exe instead of a .jar:
1). Goto Edit -> Java Application Settings... (Alt-F4)
2). In the popup window goto Linker -> Java Output.
3). There is an Output Type: combo box in it select Application.
4). Recompile your code.
5). Now you have an .exe
1). Goto Edit -> Java Application Settings... (Alt-F4)
2). In the popup window goto Linker -> Java Output.
3). There is an Output Type: combo box in it select Application.
4). Recompile your code.
5). Now you have an .exe
---Ranok---
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement