Writing applications instead of applets so our programs are allowed to manipulate files |
Applets that are run via a Web page are restricted in the kinds of actions they can take. In particular, applets are not allowed to read or write files. To work with files we need to write applications instead. There are only a few things we need to do differently:
public static void main (String[] args)This method should just construct an instance of the class it is in.
JFrame window = new JFrame();
Container contentPane = window.getContentPane();
Here are the relevant parts of the ShortWordsFixedFiles demo showing how to create an application.
public void createGUI() { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); // Code to create the components is omitted frame.pack(); frame.setVisible(true); } public static void main(String[] args) { new ShortWordsFixedFiles(); }
Writing applications instead of applets so our programs are allowed to manipulate files |