Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
//this is a simple java applet that shows how to load differing resources from a .jar file,
//this is showing how to load an image and a text file....
//The image is put on the screen
//The text file is dumped to the system console
//Even the .class file is included in the .jar file
import java.applet.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.lang.*;
import java.io.*;
public class JarTest extends Applet
{
Image sample;
public void init()
{
sample = getImage("arrowdown.gif");
try
{
InputStream in = JarTest.class.getResourceAsStream("JarTest.txt");
BufferedReader br =new BufferedReader(new InputStreamReader(in));
String line;
while( (line = br.readLine() ) !=null)
System.out.println(line);
//dumps the contents of the data file to the System Console
}
catch(IOException e)
{
System.out.print(e + "This error has occurred \n");
}
}
public void paint(Graphics screen)
{
screen.drawImage(sample,0,0,this);
//This code is from CoreJava Fundementals
}
//from http://dev-gamelan.earthweb.com/journal/techworkshop/121197_jar.html
public Image getImage(String imageFileName)
{
URL imageURL = getClass().getResource(imageFileName);
if (imageURL == null)
{
// or otherwise handle the error
System.out.println("No image named" + imageFileName);
return null;
}
Toolkit tk = Toolkit.getDefaultToolkit();
Image img = null;
try
{
img = tk.createImage( (java.awt.image.ImageProducer) imageURL.getContent());
}
catch (java.io.IOException ex)
{
System.out.println(ex);
}
return img;
}
}