O.K. I wrote my own version of the Addiction Solitaire game using a JFrame and it worked. I want to put it on the web, so I'm converting it to a JApplet. I have 52 PNG files, one for each card, that I need to be able to access for the game to work properly. I switched the JFrame over to a JApplet and previewed it using Java's appletviewer. That works fine, so it's clearly getting enough permission to read the PNG files and create BufferedImages from them. When I switch to a browser, though, it doesn't work, and I am assuming that is because, due to the fact that it is an applet, it can't read the files due to security/permissions considerations. Keep in mind that I have no need or desire to try to read files from the user's computer with this JApplet. I am supplying the 52 files and these are the files that I am trying to open in the program. Below is a very stripped-down version of the program. Can anyone confirm that this is the problem and suggest a solution please? Thanks.
import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import java.util.*;
import javax.imageio.*;
import java.io.*;
public class AppletWithPNG extends JApplet
{
MainPanel mp;
public void init ()
{
AppletWithPNG awp = new AppletWithPNG ();
}
public AppletWithPNG()
{
mp = new MainPanel ();
this.add(mp);
this.setVisible(true);
this.setSize(150, 150);
}
}
class MainPanel extends JPanel
{
BufferedImage bi = null;
File file = null;
public MainPanel ()
{
String filename = "AceClubs.png";
try
{
file = new File (filename);
bi = ImageIO.read (file);
}
catch (Exception ex)
{
// problem. exit program
System.exit (1);
}
this.setVisible (true);
this.setMinimumSize(new Dimension (150, 150));
}
public void paintComponent(Graphics g)
{
super.paintComponent (g);
this.setBackground(Color.GREEN);
g.drawImage (bi, 5, 5, null);
}
}