7/31/2019 Web Browser1
1/34
Click to edit Master subtitle style
8/19/12
using
JAVA
WEB BROWSER
7/31/2019 Web Browser1
2/34
7/31/2019 Web Browser1
3/34
8/19/12
Application and applet
An application is a standalone javaprogram. Every standalone applicationhas the main() method.
An applet is a program that can betransmitted over the internet. It haslimited access to clients resources.
7/31/2019 Web Browser1
4/34
8/19/12
Secure
When you use a Java-compatible Webbrowser, you can safely download Java
applets without fear. Java achieves thisprotection by confining a Java programto the Java execution environment andnot allowing it
access to other parts of the computer
7/31/2019 Web Browser1
5/34
8/19/12
Multithreaded
Java supports multitasking bysupporting multithreading. Thread is aline of execution.
When a process is sub divided into anumber of sub processes and each subprocess is assigned a separate thread,it
is called multithreading.
7/31/2019 Web Browser1
6/34
8/19/12
Architecture neutral
The java source code is first compiledinto bytecode. Then this bytecode isinterpreted by the java virtual machine.
There are separate jvm for differentplatforms therefore same source codecan run on different platforms
7/31/2019 Web Browser1
7/34
8/19/12 Javas bytecode concept
7/31/2019 Web Browser1
8/34
8/19/12
Portable
The java source code can be run on anyplatform that is why it is also portablein nature.
7/31/2019 Web Browser1
9/34
8/19/12
OOP Principles
1. Encapsulation2. Inheritance
3. Abstraction
4. Polymorphism
7/31/2019 Web Browser1
10/34
8/19/12
Encapsulation
Encapsulation is the mechanism thatbinds together code and the data itmanipulates,
and keeps both safe from outsideinterference and misuse
7/31/2019 Web Browser1
11/34
8/19/12
Inheritance
Inheritance is the process by which oneclass acquires the properties of anotherclass.
We use the keyword import to supportinheritance.
7/31/2019 Web Browser1
12/34
8/19/12
Class a extends b
{
}
A is the subclass and b is the
superclass.
7/31/2019 Web Browser1
13/34
8/19/12
Abstraction
It is the art of giving the importantinformation without giving thebackground details.
7/31/2019 Web Browser1
14/34
8/19/12
Polymorphism
It is a greek word that means manyforms.
A method in java can be overloaded oroverridden as per requirement and thuscan exist in more than one form.
7/31/2019 Web Browser1
15/34
8/19/12Concept of Class & Method
7/31/2019 Web Browser1
16/34
Click to edit Master subtitle style
8/19/12
GRAPHICAL USER INTERFACE
AN INTRODUCTION.
7/31/2019 Web Browser1
17/34
8/19/12
Awt and swing
Awt stands for application windowtoolkit.it is a class that is used to creategraphical applications.
Swing is also a built in java class that isused to create graphical applications.
7/31/2019 Web Browser1
18/34
8/19/12
All the entities that you see on yourwindow are called components.whenever these components are
clicked they give rise to events.
Events are Java objects that areinstantiated by the component and
passed as an argument to any listeners.
7/31/2019 Web Browser1
19/34
8/19/12
A listener of an event registers itselfwith the source of the event. When anevent occurs, the source of the event
invokes a method on the listener.The interface contains the methods
that the listener must implement and
that the source of the event invokeswhen the event occurs.
7/31/2019 Web Browser1
20/34
8/19/12
DESCRIPTION
OF THESOURCE CODE
7/31/2019 Web Browser1
21/34
8/19/12
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
8/19/12
7/31/2019 Web Browser1
22/34
8/19/12
THE IMPORT KEYWORD IS USED TO USETHE INBUILD JAVA PACKAGES
import javax.swing.*;
import javax.swing.event.*;
THE AWT AND SWING PACKAGES ARE USED TOCREATE GRAPHICAL APPLICATIONS AND THEAWT.EVENT AND SWING.EVENT ARE USED TOINCLUDE EVENT HANDLING.
import java.awt.*;import java.awt.event.*;
8/19/12
7/31/2019 Web Browser1
23/34
8/19/12
public classWebBrowser
{
public staticvoid main(String[] args)
{
JFrameframe = newEditorPaneFrame();
A public class iscreated namedWebBrowserwhich containsthe main()
function.
A frame is createdand the show
method is invokedon it.
8/19/12
7/31/2019 Web Browser1
24/34
8/19/12
classEditorPaneFrameextends JFrame
{
privateJTextField url;
privateJCheckBox
editable;
private JButton
loadButton;
A classEditorPaneFrameis created thatextends the class
Jframe.
A textfield namedurl, a checkboxnamed editable,
two buttonsnamed loadbuttonand backButton
and an editorPaner l r .
8/19/12
7/31/2019 Web Browser1
25/34
8/19/12
publicEditorPaneFrame()
{
setTitle("Java WebBrowser");
setSize(600,400);
addWindowListener(new
WindowAdapter()
The constructorfor theEditorPaneFrameclass is created.
The title of theweb browserframe is set.
The size of theweb browser isset.
The windowlistener for the
8/19/12
7/31/2019 Web Browser1
26/34
8/19/12
url = new JTextField(30);
loadButton = new JButton("Load");
loadButton.addActionListener(new
ActionListener()
{
public voidactionPerformed(ActionEvent event)
{
try
{
// remember URL for back button
urlStack.push(url.getText());
editorPane.setPage(url.getText());
}
catch(Exception e)
{
editorPane.setText("Error: " +e);
}
A text field and abutton named urland LoadButtonrespectively arecreated.
Event listener forthe LoadButton iscreated.
8/19/12
7/31/2019 Web Browser1
27/34
8/19/12
backButton = new JButton("Back");
backButton.addActionListener(newActionListener()
{
public voidactionPerformed(ActionEvent event)
{
if(urlStack.size()
7/31/2019 Web Browser1
28/34
8/19/12
editorPane = newJEditorPane();
editorPane.setEditable(false);
editorPane.addHyperlinkListener(ne
wHyperlinkListener()
{
An EditorPane iscreated and therequired eventlistener isregistered for it.
8/19/12
7/31/2019 Web Browser1
29/34
8/19/12
editorPane = newJEditorPane();
editorPane.setEditable(false);
editorPane.addHyperlinkListener(ne
wHyperlinkListener()
{
An EditorPane iscreated and therequired eventlistener isregistered for it.
8/19/12
7/31/2019 Web Browser1
30/34
8/19/12
editable = newJCheckBox();
editable.addActionListener(new
ActionListener() {
public
voidactionPerformed(ActionEvent
event)
A checkboxnamed editable iscreated and theevent listener forit is registered.
8/19/12
7/31/2019 Web Browser1
31/34
8/19/12
ContainercontentPane =getContentPane();
contentPane.add(
newJScrollPane(editor
Pane), "Center");
JPanel panel= new JPanel();
A contenetPane iscreated and ascrollPane isadded to it.
A panel is
created.Two labels (URL
and editable) and
the componentsthat were createdbefore (two
button, a
8/19/12
7/31/2019 Web Browser1
32/34
8/19/12JVM
8/19/12execut ng t e yte co e to get t e
7/31/2019 Web Browser1
33/34
8/19/12execut ng t e yte co e to get t eoutput..
8/19/12
7/31/2019 Web Browser1
34/34
8/19/12web browser(output)
Top Related