Web browser in java

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 5161 Views - Last Post: 18 September 2012 - 07:34 AM Rate Topic: -----

#1 Ytry   User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 120
  • Joined: 25-July 12

Web browser in java

Posted 16 September 2012 - 08:29 PM

I am fairly new to java, and programming in general. Java is my first, and only language I know so far. I have been coding for about 1 year now, and I've decided to make a basic web browser in java. When I use the term basic I use it pretty loosely I don't actually know how it will turn out. I plan to use this topic to post any problems I run into, or questions I might have. My first problem so to speak is what to name it. If anyone has any name suggestion or things you think I should try to add please let me know.

Is This A Good Question/Topic? 0
  • +

Replies To: Web browser in java

#2 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8379
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Web browser in java

Posted 16 September 2012 - 08:58 PM

Our tutorial section has a complete basic browser
Was This Post Helpful? 0
  • +
  • -

#3 Ytry   User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 120
  • Joined: 25-July 12

Re: Web browser in java

Posted 17 September 2012 - 03:41 AM

I know that, I looked over it briefly. I just want to challenge myself to make one. Perhaps I will do certain things differently I don't really know until I try right?
Was This Post Helpful? 0
  • +
  • -

#4 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8379
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Web browser in java

Posted 17 September 2012 - 03:46 AM

Have fun.
Don't hesitate to post your problem.
As far as the name is concerned, you can always change it further down so use YWB for now :)
Was This Post Helpful? 1
  • +
  • -

#5 jon.kiparsky   User is online

  • Beginner
  • member icon


Reputation: 11277
  • View blog
  • Posts: 19,320
  • Joined: 19-March 11

Re: Web browser in java

Posted 17 September 2012 - 06:58 AM

View PostYtry, on 16 September 2012 - 10:29 PM, said:

I am fairly new to java, and programming in general. Java is my first, and only language I know so far. I have been coding for about 1 year now, and I've decided to make a basic web browser in java. When I use the term basic I use it pretty loosely I don't actually know how it will turn out. I plan to use this topic to post any problems I run into, or questions I might have.


Sounds like fun. Looking forward to the questions.


Quote

My first problem so to speak is what to name it. If anyone has any name suggestion or things you think I should try to add please let me know.


Your first problem is developing your requirements and doing the high-level design, followed by scheduling and risk analysis. Leave the name up to the marketing department.

Requirements is easy, just write down a list of the things that a browser has to do and rate each item as "must have", "should have", or "could have".

High level design, that's a little more involved. You'll have to be able to think about what the parts are going to look like and how they're going to fit together before you've actually built them. For a big project, it's important to get this part right, or you'll be tearing your hair out later.

Scheduling and risk analysis - The former is important because it allows you to know when you're spinning your wheels, and because it allows you to see the whole project, not just the place you are and some vague notion of the end state. With a good project schedule, you can see the steps you're going to have to take and the steps you've already taken. This is very important on a big project.
Scheduling goes hand in hand with risk analysis. The latter makes you think about the things that might make you miss your schedule, and build in appropriate safeguards or time buffers. For example, if you look down the road and you see "develop a javascript interpreter", you might see that as a risk - what if I don't know how to do that? - and build in some prep time in the preceding weeks for learning how to do that. If you think you're going to have bugs (you are) you should build in some time each week for bug fixing.

All of this seems tangential to the process of building a browser, but a project is a lot more fun if you feel like you have some sense of what you're building, where you need to get to, and how long it's going to take to get there.

If you want to see the opposite of a planned project, you should look up "Spectate Swamp" and read a little of his code... if you dare.
Was This Post Helpful? 2
  • +
  • -

#6 Ytry   User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 120
  • Joined: 25-July 12

Re: Web browser in java

Posted 17 September 2012 - 08:32 AM

To be honest up until now I have not really been doing any of this, and I feel like I really should. Thank you so much for taking the time to post this I feel it is going to be very helpful in the future. If I may ask though How do you suppose I should go about determining how much time each thing should take? Also when coding I find my self running into the problem of what to do first / where to start. Will doing the things you have said help me better deal with that problem? I am asking this because these are some of the things that have limited my coding ability in the past.
Was This Post Helpful? 0
  • +
  • -

#7 jon.kiparsky   User is online

  • Beginner
  • member icon


Reputation: 11277
  • View blog
  • Posts: 19,320
  • Joined: 19-March 11

Re: Web browser in java

Posted 17 September 2012 - 08:57 AM

View PostYtry, on 17 September 2012 - 10:32 AM, said:

To be honest up until now I have not really been doing any of this, and I feel like I really should. Thank you so much for taking the time to post this I feel it is going to be very helpful in the future. If I may ask though How do you suppose I should go about determining how much time each thing should take?


That's a matter of experience, you get better at it with time. At first, you're going to be making guesses and they'll be wrong. That's okay - keep track of your guesses and the actual time required, and you'll see that over time your guesses get better.

Quote

Also when coding I find my self running into the problem of what to do first / where to start. Will doing the things you have said help me better deal with that problem? I am asking this because these are some of the things that have limited my coding ability in the past.

That's exactly what this is supposed to help you solve. You're going to start looking at the big picture.
Designing something like a browser is a big job, and it's a lot easier if you can make a road map.
Was This Post Helpful? 0
  • +
  • -

#8 Ghlavac   User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 519
  • Joined: 14-January 09

Re: Web browser in java

Posted 17 September 2012 - 11:29 AM

If you're aiming to use newer things you can always use the JavaFX2 WebView/WebEngine combination.

Oracle Tutorial on it.

http://docs.oracle.c...pub-webview.htm

This post has been edited by Ghlavac: 17 September 2012 - 11:33 AM

Was This Post Helpful? 0
  • +
  • -

#9 Ytry   User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 120
  • Joined: 25-July 12

Re: Web browser in java

Posted 17 September 2012 - 03:11 PM

I will look over this thanks for the tut
Was This Post Helpful? 0
  • +
  • -

#10 Ytry   User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 120
  • Joined: 25-July 12

Re: Web browser in java

Posted 17 September 2012 - 04:01 PM

Okay I have made the very basic of basic web browsers so far. Here is the code I have so far please feel free to ask any questions / critique it in any way, it all helps, and will make my coding better in the future.
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

public class ReadFile extends JFrame {

	private final JTextField addressBar;
	private final JEditorPane display;

	//constructor
	public ReadFile() {
		super("Simple Browser");

		addressBar = new JTextField("Enter a Url");
		addressBar.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(final ActionEvent event) {
				loadPage(event.getActionCommand());
			}
		});
		add(addressBar, BorderLayout.NORTH);

		display = new JEditorPane();
		display.setEditable(false);
		display.addHyperlinkListener(new HyperlinkListener() {
			@Override
			public void hyperlinkUpdate(final HyperlinkEvent event) {
				if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
					loadPage(event.getURL().toString());
				}
			}
		});
		add(new JScrollPane(display), BorderLayout.CENTER);
		setSize(500, 300);
		setVisible(true);
	}

	//load HTML data to display
	private void loadPage(final String userText) {
		try {
			display.setPage(userText);
			addressBar.setText(userText);
		} catch (final Exception e) {
			System.out.println("Could not load web page");
		}
	}
}

This class pretty much contains all of the browser code so far.


import javax.swing.JFrame;

public class MainFileReader {
	public static void main(final String[] args) {
		final ReadFile read = new ReadFile();
		read.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}



This is just a class to contain my main method, and handling opening / closing the browser. Like I said at this point it really sucks, but let me know what you think.
Was This Post Helpful? 0
  • +
  • -

#11 Ytry   User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 120
  • Joined: 25-July 12

Re: Web browser in java

Posted 18 September 2012 - 05:50 AM

With what I have so far I cannot click any links, or watch videos in browser. How would I go about integrating Javascript to it, and flash?
Was This Post Helpful? 0
  • +
  • -

#12 jon.kiparsky   User is online

  • Beginner
  • member icon


Reputation: 11277
  • View blog
  • Posts: 19,320
  • Joined: 19-March 11

Re: Web browser in java

Posted 18 September 2012 - 06:32 AM

The current Javascript (ECMAscript, technically) language spec can be had at this link. Go to it.
Was This Post Helpful? 0
  • +
  • -

#13 jon.kiparsky   User is online

  • Beginner
  • member icon


Reputation: 11277
  • View blog
  • Posts: 19,320
  • Joined: 19-March 11

Re: Web browser in java

Posted 18 September 2012 - 06:41 AM

View PostYtry, on 17 September 2012 - 06:01 PM, said:

Okay I have made the very basic of basic web browsers so far. Here is the code I have so far please feel free to ask any questions / critique it in any way, it all helps, and will make my coding better in the future.
Like I said at this point it really sucks, but let me know what you think.


Just taking a quick look, I see both Swing components and console output. This is a bad sign. Can you arrange things so you're using one or the other?

Looking a little closer - but not much - I see that you have a class called FileReader which contains Swing. This is a very bad sign. A FileReader should know nothing about output, it should only read files and provide them to client classes, which might want to display them, or archive them, or analyze them for some purpose - the FileReader shouldn't care about what the files are used for.
Was This Post Helpful? 0
  • +
  • -

#14 Ytry   User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 120
  • Joined: 25-July 12

Re: Web browser in java

Posted 18 September 2012 - 07:11 AM

The Class called FileReader is just a class I put in to hold my main method, and handle the JFrame close operation. I didn't know the name held any relevance I have changed it to look like this.
import javax.swing.JFrame;

public class Apples {
	public static void main(final String[] args) {
		final ReadFile read = new ReadFile();
		read.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}


I have changed the name of the main class to apples which hold no relevance to what it actually does, I am really bad with naming and organizing classes. You also mentioned that I have console output, I have the console output where I was catching an exception on an invalid URL. I plan to change that to display something on the page. Currently I have three goals in mind though I am sure how to do two of the the three. I would like to make it so in the browser I do not have to type http:// in front of all my URL's. Secondly, I would like to add support for Javascript, and Flash. Lastly I plan to replace the console output with a JFrame to display that it is an invalid URL, this is the only one of these goals I currently know how to do though I will mess with it a little bit.
Was This Post Helpful? 0
  • +
  • -

#15 jon.kiparsky   User is online

  • Beginner
  • member icon


Reputation: 11277
  • View blog
  • Posts: 19,320
  • Joined: 19-March 11

Re: Web browser in java

Posted 18 September 2012 - 07:26 AM

A class should represent something, and its name should communicate that. If you can't name it, you don't know what it is, and it's impossible to design it correctly.

The names are not arbitrary, they reflect your understanding of the task at hand.

Quote

Lastly I plan to replace the console output with a JFrame to display that it is an invalid URL, this is the only one of these goals I currently know how to do though I will mess with it a little bit.


This is a good plan: do the things you know how to do.
Better still, can you develop a class which generally notifies the user of important developments? This should throw a dialog box, which can be modal or not, with an arbitrary String message. You might want to address the case of needing confirmation, or simply an "okay" to dismiss it.

Having done this, you might also think about how you'd use this to get user input (for example, to replace the navigation bar?) and whether this would be a good idea or not.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2