Go Back   Gaming Gutter > Non-Gaming > Programming > Source Code


Source Code - Have a source code/project files you want to post? Do so here.

» Site Navigation
» Home
» FAQ
» Log in
User Name:

Password:

Not a member yet?
Register Now!
» Advertisement
» Recent Threads
Go to first new post Heather wants to kill a...
Today 06:49 PM
Last post by Ruzzeh
Today 07:22 PM
9 Replies, 10 Views
Go to first new post Li Luv's you <3
Yesterday 05:38 AM
by Li-Shun
Last post by Li-Shun
Today 07:21 PM
49 Replies, 243 Views
Go to first new post ENTER
Today 07:08 PM
Last post by Axed
Today 07:18 PM
1 Replies, 2 Views
Go to first new post Gaia Online.
Today 08:48 AM
by ~Bloo~
Last post by Phail-kun
Today 07:06 PM
1 Replies, 7 Views
Go to first new post If you had one day to...
11-03-2008 05:09 AM
Last post by Phail-kun
Today 07:03 PM
37 Replies, 635 Views
Reply
 
LinkBack Thread Tools Display Modes

 [Java] loading a site's source code
Old 10-05-2008, 01:40 PM   #1 (permalink)
Kyo

Male Kyo is offline


 
Kyo's Avatar
 
Join Date: Dec 1969
Posts: 4,298
GPoints: 3,670
iTrader: 12 / 100%
Kyo Is a Lord of AwesomenessKyo Is a Lord of AwesomenessKyo Is a Lord of AwesomenessKyo Is a Lord of AwesomenessKyo Is a Lord of Awesomeness
Rep Power: 130
[Java] loading a site's source code

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;
	}
}
__________________
  Reply With Quote
Reply

Bookmarks



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Powered by vBadvanced CMPS v3.0 RC2

All times are GMT -7. The time now is 07:22 PM.


vBulletin skin developed by: eXtremepixels
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The contents of this webpage are copyright © 2006-2008 GamingGutter.com. All Rights Reserved.

Page generated in 0.10318589 seconds (100.00% PHP - 0% MySQL) with 19 queries