What's new

How to Make a Web Browser

Faffy

Faffy

Enthusiast
Messages
793
Reaction score
91
Points
95
Sin$
0
Java SDK

How to make a Web Browser using Java

1. Download and install the latest version of the Java standard developer's kit (SDK) from Sun Microsystems if you have not previously done so.

2
Open your programming application or text editor and save the file as myFirstWebBrowser.java. Include at the top of the file four class library imports (java.awt, java.io, java.awt.event, and javax.swing). These libraries are necessary to create the user interface components for the application (awt and swint), conducting HTML get and put commands (to view Web pages), and to save files (io). The import statements to include are:

Code:
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
3
Create the new class called myFirstWebBrowser, which will be an extension of JInternalFrame so that you can include the Web browser as an internal frame in a Java Swing application. The beginning of the class definition is:

Code:
public class PageFrame extends JInternalFrame implements ActionListener {
4
Create class definitions for a SiteManager class, a String for the filename to load and a textArea. The constructor of the class will load the site name and SiteManager objects to assign to the protected class variables. The code to do these steps is:
Code:
SiteManager myParent;
String myFilename;
JTextArea myTa;

public PageFrame(String myName, SiteManager mySm) {
super("Page: " + myName, true, true, true, true);
myParent = mySm;
setBounds(50,50,300,150);

Container contentPane = getContentPane();
5
Create the text area that will display the HTML file and load it into a scrollable Swing pane that will allow you to view the entire HTML file. After these steps are complete, create a menu bar for the application to mimic the File menus that you are used to having in other computer applications. In this example, "File" and "Save" menu options will be created. The code to do these steps is:
Code:
myTa = new JTextArea();
JScrollPane myJsp = new JScrollPane(ta);
contentPane.add(jsp, BorderLayout.CENTER);

JMenuBar myJmb = new JMenuBar();
JMenu myfileMenu = new JMenu("File");
JMenuItem mySaveItem = new JMenuItem("Save");
mySaveItem.addActionListener(this);
myFileMenu.add(saveItem);
myJmb.add(fileMenu);
setJMenuBar(myJmb);

myFilename = myName;
loadContent();
}
6
Define "Action Listeners" that will perform method calls on response to the user choosing "File->Menu" options to load and save files. The code to do this is:
Code:
public void actionPerformed(ActionEvent ae) {

saveContent();
}

public void loadContent() {
try {
FileReader myFr = new FileReader(myFilename);
myTa.read(myFr, null);
myFr.close();
} catch (Exception e) {
System.err.println("Could not load the web page: " + myFilename);
}
}

public void saveContent() {
try {
FileWriter myFw = new FileWriter(myFilename);
myTa.write(myFw);
myFw.close();
} catch(Exception e) {
System.err.println("Could not save the webpage: " + myFilename);
}
}

}

Source


Sorry guys its not mine I'm not that great but when I saw it I knew I had to leech it onto s7s
 
RaisinBranshee

RaisinBranshee

Enthusiast
Messages
332
Reaction score
24
Points
70
Sin$
0
A link to the SDK would be nice. For those who don't have it.
 
Wheen

Wheen

Bytesexual
Retired
Programmer Grammar Nazi Mr. Nice Guy
Messages
6,145
Reaction score
2,342
Points
665
Sin$
0
One of the worst tutorials I have seen on the site in a while. It doesn't explain anything, and it promotes a "Copy & Paste" programming attitude, leading the reader to little-to-no comprehension of the actions that they have done. Which is honestly to be expected, as you admitted that you don't even know what you are doing, that you are just "Leaching" it to us.
 
Calamity

Calamity

Retired
Retired
Messages
6,704
Reaction score
1,159
Points
650
Sin$
0
One of the worst tutorials I have seen on the site in a while. It doesn't explain anything, and it promotes a "Copy & Paste" programming attitude, leading the reader to little-to-no comprehension of the actions that they have done. Which is honestly to be expected, as you admitted that you don't even know what you are doing, that you are just "Leaching" it to us.

It's because it's an eHow tutorial, they are made to be simple, which for programming, isn't a good combination for a tutorial.
 
Faffy

Faffy

Enthusiast
Messages
793
Reaction score
91
Points
95
Sin$
0
One of the worst tutorials I have seen on the site in a while. It doesn't explain anything, and it promotes a "Copy & Paste" programming attitude, leading the reader to little-to-no comprehension of the actions that they have done. Which is honestly to be expected, as you admitted that you don't even know what you are doing, that you are just "Leaching" it to us.

True but it was asked for awhile back either here or TTG so I posted what I found then didn't but much more thought into it
 
Top Bottom
Login
Register