import java.io.*;
import java.awt.* ;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JEditorPane;

public class MyBrowser extends JFrame implements Runnable {
    String theURL,themessage;
    int URL_size;
    boolean showURL=true;
    java.net.URL thisURL;
    JEditorPane editorPane;

    public MyBrowser(int i,String thisURL){ 
        theURL=thisURL;        
        switch (i) {
        case 1:  URL_size=500;
            break;
        case 2: URL_size=1000;
            break;
        }
    }

    public void run() {
        try {
            thisURL=new  java.net.URL(theURL);
        } catch (java.net.MalformedURLException|java.lang.RuntimeException e) {
            showURL=false;
            thisURL=null;
            themessage="Not A Valid URL";
        }
        if (showURL) {
            editorPane = new JEditorPane();
            editorPane.setEditable(false);   
            try {
                editorPane.setPage(thisURL);
            } catch (IOException|java.lang.RuntimeException e) {
                showURL=false;
                editorPane=null;
                themessage=" URL Not Available or Invalid";
            }
            if (showURL) {
                setBackground(Color.white);
                setTitle("A Browser Window");
                setSize(1000,1000);
                setLayout(new BorderLayout()); 
                setLocationRelativeTo(null);
                setDefaultCloseOperation(DISPOSE_ON_CLOSE);
                add(buildHtmlPane(),BorderLayout.CENTER);
                setVisible(true);
                pack();
            } else {
                startURL.theURL.setText(themessage);
                stop_thread();
            }
        }
    }

///////////////////////////////////////////////////////

    public  JPanel buildHtmlPane () {
        editorPane.setPreferredSize(new Dimension(URL_size,URL_size));
        editorPane.setVisible(true);
        JScrollPane scrollPane = new JScrollPane(editorPane);
        scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); //SETTING SCHEME FOR HORIZONTAL BAR
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        scrollPane.setVisible(true);
        JPanel leftPane = new JPanel(new BorderLayout());
        leftPane.setVisible(true);
        leftPane.add(scrollPane);//, BorderLayout.PAGE_START);
        return leftPane;
    }

    public static void main(String[] args ) {
        (new Thread(new MyBrowser(2,"http://www.umsl.edu/~siegel/littleFile.html"))).start();
    }
    public int stop_thread(){
        return 0;
    }

}