// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

public class XhtmlCheck extends JFrame {
    private JTextField tf;
    private JButton btn;
    public XhtmlCheck() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setTitle("Text field update");
        getContentPane().setLayout(new GridLayout(2, 1));
        tf = new JTextField();
        tf.setPreferredSize(new Dimension(500, 30));
        getContentPane().add(tf);
        btn = new JButton("Check");
        getContentPane().add(btn);
        pack();
        final ExecutorService es = Executors.newFixedThreadPool(2);
        btn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    final URL url = new URL("http://www.reedcopsey.com");
                    es.submit(new Callable<Void>() {
                        public Void call() throws Exception {
                            BufferedReader br = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream()));
                            final String str = br.readLine();;
                            EventQueue.invokeLater(new Runnable() {
                                public void run() {
                                    tf.setText(String.format("Page at %0$s supports XHTML 1.0: %1$b", url, str.contains("XHTML 1.0")));
                                }
                            });
                            br.close();
                            return null;
                        }
                    });
                } catch (MalformedURLException ex) {
                    ex.printStackTrace();
                }
            
            }
        });
    }
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JFrame f = new XhtmlCheck();
                f.setVisible(true);
            }
        });
    }
}
