Faffy
Enthusiast
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:
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:
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:
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:
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:
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
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.*;
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 {
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();
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();
}
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