Input streams kill my applet
This is probably a little thing that I have forgotten but I can't for the life of me get. Ok I should probably say I am running XP, with Java 1.5 and Firefox
I have an applet that works fine on Eclipse but when I try to run it by it self it seems to die at the point where I have my input streams.
Basicly I have included the test code that removes all the input processing and tree building. This test script below just opens a input stream, creates a tree with two nodes and displays the tree. If you remove any the 3 TRYS it will not work.
I have tried various methods to read in the URL I have but it seems to die every time. I have included the code below. If anyone has any suggestions I would greatly appreciate it.
Thanks
Luis
import java.applet.AppletContext;
import java.awt.Color;
import java.awt.Font;
import java.io.DataInputStream;
import java.io.InputStream;
import java.net.*;
import java.io.*;
import javax.swing.JApplet;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import java.net.URLConnection;
publicclass TestAppletextends JApplet{
// Variables used by the applet
protected JTree jt;
protected URL url;
publicvoid init(){
setBackground(Color.lightGray);
setFont(new Font("Verdana", Font.BOLD, 12));
try{
url =new URL("http://www.yahoo.com");
//IF I REMOVE ANY OF THE FOLLOWING COMMENTS IT DOES NOT WORK
//TRY 1. IF REMOVED IT WILL NOT WORK
/*URL yahoo = new URL("http://www.yahoo.com/");
BufferedReader in = new BufferedReader(yahoo.openStream());
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
*/
//TRY 2. IF REMOVED IT WILL NOT WORK
/*URLConnection connection = url.openConnection();
InputStream in = connection.getInputStream();
DataInputStream stream = new DataInputStream(in);
*/
//TRY 3. IF REMOVED IT WILL NOT WORK
//BufferedReader stream = new BufferedReader(new InputStreamReader(url.openStream()));
DefaultMutableTreeNode rootNode =new DefaultMutableTreeNode(url);
rootNode.add(new DefaultMutableTreeNode("Child 1"));
JTree jt =new JTree(rootNode);
// Tree Setup
jt.setExpandsSelectedPaths(true);
jt.setVisible(true);
jt.putClientProperty("JTree.lineStyle","Angled");
getContentPane().removeAll();
getContentPane().add(jt);
//stream.close();
//iStream.close();
}catch (Exception e){
e.printStackTrace();
}
}
publicvoid start(){
}
}// end TreeApplet Class

