Java Reference
In-Depth Information
JButton exit
-
button = new JButton ("Exit");
exit
-
button.addActionListener (this);
JPanel control
-
panel = new JPanel ();
control
-
panel.add (go
-
button);
control
-
panel.add (clear
-
button);
control
-
panel.add (exit
-
button);
panel.add (control
-
panel, BorderLayout.SOUTH);
// Add text area with scrolling to the content pane.
content
-
pane.add (panel);
// If running in a browser, read file name from
// applet tag param value. Else use the default.
if (fInBrowser) {
// Get setup parameters from applet html
String param = getParameter ("FileToRead");
if (param != null) {
fFileToRead = new String (param);
}
}
}
// init
/** Use a URL object to read the file. **/
public void readFile () {
String line;
URL url = null;
// Get the URL for the file.
try {
if (fInBrowser)
url = new URL (getCodeBase (), fFileToRead);
else {
File file = new File (fFileToRead);
if (file.exists ())
url = file.toURL ();
else {
fTextArea.append ("No file found");
System.out.println ("No file found");
System.exit (0);
}
}
}
Search WWH ::
Custom Search