NOTE: if this FAQ doesn't clear up your question, please ask the course staff! If you find any bugs, tell us that too!
Q: Can Java display images (such as GIFs or JPEGs)?
A: Yes! Let's say you have an image called
myimage.gif
. You can load it using the following Java code:
java.awt.Toolkit tk = java.awt.Toolkit.getDefaultToolkit(); java.awt.Image myImage = tk.getImage("myimage.gif");That's it! Then, you could display the image in your paint method like so:
public void paint(java.awt.Graphics g) { g.drawImage(this.myImage, // The image you want to draw this.x, // The x position of the image this.y, // The y position of the image this // The ImageObserver. (Just use "this"). ); }
Q: Can we use the cs101 classes? How?
A: Yes, you are allowed to use the cs101 classes for this project except for the wire classes you used in the Cat & Mouse problem set. Here's how:
From Athena:
> cd <cs101_dir> > echo 'setenv CLASSPATH ${CLASSPATH}:<cs101_dir>/cs101.jar' >> ~/.environment
From Windows95/98:
c:\autoexec.bat
. Add the following
line to the bottom of that file:
set CLASSPATH=%CLASSPATH%;<cs101_dir>\cs101.jar
Q: Making the user of my game specify a hostname and a port (ala Cat & Mouse) is not very user-friendly. Is there any way I can hide these low-level details from the user?
A: Yes there is. Mike Wessler has written a very nice utility that does this for you. For a description and download, go here.