Hallo! Ich kann auf eigene localhost meine Queldateien lesen und anzeigen, nicht aber wenn ich zum Provider auflade. Dann passiert nämlich das JRE endlos lang den Ladevorgang anzeigt und hängen bleibt. Sonnst ist die Queldatei nicht vorhanden, wird die Fehlermeldung in JOptionPane angezeigt.
Warum!? Vielleicht habt ihr Kollegen eine Lösung?
Warum!? Vielleicht habt ihr Kollegen eine Lösung?
Java:
package codeview;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.*;
/**
*
* @author Janos [url=http://www.tojasoft.at]Modellierung in UML[/url]
*/
public class ViewSourceCode extends JApplet {
JTextArea jta;
JScrollPane jsrlp;
FileReader fr;
BufferedReader br;
private String tmp;
private String thisSrcPath;
private URL url;
private InputStream is;
private InputStreamReader isr;
public void init() {
this.setLayout(new BorderLayout());
jta = new JTextArea();
jta.setBackground(Color.GREEN);
jta.setEditable(false);
jsrlp = new JScrollPane(jta);
this.add(BorderLayout.CENTER, jsrlp);
}
public final void showSource(String path) {
// thisSrcPath = "src." + path;
// thisSrcPath = thisSrcPath.replaceAll("\\.", "/");
// thisSrcPath = thisSrcPath + ".java";
// //try whether the source code documents local available
// try {
// fr = new FileReader(thisSrcPath);
// br = new BufferedReader(fr);
// while ((tmp = br.readLine()) != null) {
// jta.append(tmp + " \n");
// }
// fr.close();
// br.close();
// } catch (Exception e) {
//try whether http response available
try {//standard 'localhost' at any provider
url = new URL("http://localhost/" + path);
try {
is = url.openStream();
isr = new InputStreamReader(is, "UTF-8");
br = new BufferedReader(isr);
while ((tmp = br.readLine()) != null) {
jta.append(tmp + " \n");
}
isr.close();
br.close();
} catch (IOException ex) {
// JOptionPane.showMessageDialog(rootPane, "IOException: " + ex);
try {//local 'localhost' with Port:8080 at Apache Tomcat
url = new URL("http://localhost:8080/myjdk6/" + path);
try {
is = url.openStream();
isr = new InputStreamReader(is, "UTF-8");
br = new BufferedReader(isr);
while ((tmp = br.readLine()) != null) {
jta.append(tmp + " \n");
}
isr.close();
br.close();
} catch (IOException ex1) {
JOptionPane.showMessageDialog(this, "IOException1: " + ex1);
}
} catch (IOException e1) {
JOptionPane.showMessageDialog(this, "IOException2: " + e1);
}
}
} catch (MalformedURLException ex) {
JOptionPane.showMessageDialog(this, "URLException: " + ex);
}
}
/**the main method is an option to launch this 'amphibien' application in JFrame*/
public static void main(String... args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
private void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame jf = new JFrame("demo of sourcecodeview");
ViewSourceCode vsc = new ViewSourceCode();
vsc.init();
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setPreferredSize(new Dimension(600, 600));
jf.add(vsc);
jf.pack();
jf.setVisible(true);
// vsc.showSource(vsc.getClass().getName());
vsc.showSource("src/codeview/ViewSourceCode.java");
}
});
}
}