I've found that apparently applets aren't allowed to access files and images on your computer. (I tried and got some kind of security exception.)
How do you put the files and stuff into the html page? I suppose an
<img source="./image.gif">
could work to add an image to the html document, but how would the applet get to it?
Also, if you had a file called text.txt, how would you get your applet to find it? I'm not even sure how to embed a text file in an html document, let alone get an applet to access it. I've no clue how to pull this off, so no applet code at the moment. (So no asking for an SSCCE, or you'll get an from me!)
If you really want a JApplet, I can make one up.
import javax.swing.JApplet; import java.io.File; import javax.swing.ImageIcon; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.Color; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JPanel; import java.util.Scanner; import javax.swing.JMenuBar; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JLabel; import javax.swing.Image; import javax.swing.Icon; import java.awt.GridLayout; public class TestApplet extends JApplet { private JPanel contentPane; private JScrollPane contentScroll; private File textFile; private Scanner fileReader; private JMenuBar mBar; private JMenu file, edit, view, help, save; private JMenuItem exit, save2, load, saveAs, print, help2, copy, paste, cut, selectAll; private JTextArea textArea; private JScrollPane textScroll; private JLabel image; private ImageIcon icon; public void init() { contentPane = new JPanel(); contentScroll = new JScrollPane(contentPane, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); setContentPane(contentScroll); mBar = new JMenuBar(); file = new JMenu("File"); mBar.add(file); edit = new JMenu("Edit"); mBar.add(edit); view = new JMenu("View"); mBar.add(view); help = new JMenu("Help"); mBar.add(help); help2 = new JMenuItem("Help"); help.add(help2); help.addSeparator(); save = new JMenu("Save"); file.add(save); file.addSeparator(); save2 = new JMenuItem("Save"); save.add(save2); save.addSeparator(); saveAs = new JMenuItem("Save As"); save.add(saveAs); save.addSeparator(); load = new JMenuItem("Load"); file.add(load); file.addSeparator(); exit = new JMenuItem("Exit"); file.add(exit); file.addSeparator(); copy = new JMenuItem("Copy"); edit.add(copy); edit.addSeparator(); textArea = new JTextArea(200,200); setJMenuBar(mBar); textScroll = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); contentPane.setLayout(new GridLayout(2,1)); contentPane.add(textScroll); try { textReader = new Scanner( new File("./text.txt")); // how do I get it to find this file? } catch(java.io.FileNotFoundException fnfe) { System.out.println("File not found."); } icon = new ImageIcon("./image.gif"); // how do I get it to find this image? image = new JLabel("I am an Image in a JApplet!", icon, JLabel.LEFT); contentPane.add(image); } public void start() { setBackground(Color.GREEN); } public void run() { start(); } }
Not sure if all the imports will compile and don't quite recall how to set up an applet that much either. But I can look that part up pretty quickly in the API. I already have some samples of JApplets, somewhere. However, how to access images from an html from with the applet and how to get text files to go into a spot that the files can be found.