It is a mere proof of concept I did when playing around with java, but I think it might help beginners getting into both GUI and internet programming
Code:
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import javax.swing.*;
import java.awt.*;
public class JKyo extends JFrame {
public static void main(String args[]) {
new JKyo();
}
JKyo () {
this.setSize(600, 300);
JPanel mainpanel;
mainpanel = new JPanel();
mainpanel.setLayout(new GridLayout(2, 5, 2, 2));
//mainpanel.setBorder(BorderFactory.createEtchedBorder(Color.white, Color.blue));
Label status = new Label();
JTextArea html = new JTextArea(5,20);
JScrollPane htmlscroll = new JScrollPane(html);
htmlscroll.getViewport().add(html);
//html.setEditable(false);
status.setText("Idle...");
mainpanel.add(htmlscroll);
mainpanel.add(status);
add(mainpanel);
setVisible(true);
KyoWrapper wrapper = new KyoWrapper();
status.setText("Loading...");
html.append(wrapper.getUrl("http://google.com"));
html.selectAll();
status.setText("Done!");
}
}
class KyoWrapper {
public void main () {
}
String getUrl(String purl) {
String Content = "";
try {
URL url = new URL(purl);
HttpURLConnection huc = (HttpURLConnection)url.openConnection();
huc.setRequestMethod("GET");
huc.setRequestProperty("User-Agent","Super special awesome browser");
huc.setRequestProperty("Pragma","no-cache");
huc.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(huc.getInputStream()));
String line = null;
while((line = reader.readLine()) != null) {
Content += line+"\n";
}
} catch(IOException ioe) {
ioe.printStackTrace();
}
catch (Exception e) {
System.err.println("General Exception " + e);
e.printStackTrace();
}
return Content;
}
}