hi friends,
can u help me in, Designing a new web browser
i have some sample code to desing a new browser
but its not sufficient , it only show's URL bar and Go button
i want some advance level
like
1. Next ,Prev ,Stop , Refresh Buttons
2. Status Bar
and some good Grapics look
hope u will help me ,
Thank you,
java Web Browser
Started by markwilson, Sep 19 2008 04:52 AM
13 replies to this topic
#1
Posted 19 September 2008 - 04:52 AM
|
|
|
#2
Posted 19 September 2008 - 09:31 AM
Well, you could do the graphic part in swing and have a flowlayout. That would work, but I wonder how would flash and js work under a java based webbrowser lol(I know the answer already).
#3
Posted 19 September 2008 - 08:55 PM
thnx Turk4n,
for reply , fine its right with the help of swing i can design GUI part,
and thing else i can use for same .
one more thing can u tell me how i can run "flash and js under web browser "
c i have one code which is only show simple text (means HTML part)
no js , css supported.
so can u plz help me in this , its urgent .
for reply , fine its right with the help of swing i can design GUI part,
and thing else i can use for same .
one more thing can u tell me how i can run "flash and js under web browser "
c i have one code which is only show simple text (means HTML part)
no js , css supported.
so can u plz help me in this , its urgent .
#4
Posted 19 September 2008 - 08:56 PM
here is my source code
#5
Posted 19 September 2008 - 08:56 PM
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.html.*;
// The Mini Web Browser.
public class MiniBrowser extends JFrame
implements HyperlinkListener
{
// These are the buttons for iterating through the page list.
private JButton backButton, forwardButton;
// Page location text field.
private JTextField locationTextField;
// Editor pane for displaying pages.
private JEditorPane displayEditorPane;
// Browser's list of pages that have been visited.
private ArrayList pageList = new ArrayList();
// Constructor for Mini Web Browser.
public MiniBrowser()
{
// Set application title.
super("Mini Browser");
// Set window size.
setSize(640, 480);
// Handle closing events.
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
actionExit();
}
});
// Set up file menu.
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
fileMenu.setMnemonic(KeyEvent.VK_F);
JMenuItem fileExitMenuItem = new JMenuItem("Exit",
KeyEvent.VK_X);
fileExitMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
actionExit();
}
});
fileMenu.add(fileExitMenuItem);
menuBar.add(fileMenu);
setJMenuBar(menuBar);
// Set up button panel.
JPanel buttonPanel = new JPanel();
backButton = new JButton("< Back");
backButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
actionBack();
}
});
backButton.setEnabled(false);
buttonPanel.add(backButton);
forwardButton = new JButton("Forward >");
forwardButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
actionForward();
}
});
forwardButton.setEnabled(false);
buttonPanel.add(forwardButton);
locationTextField = new JTextField(35);
locationTextField.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
actionGo();
}
}
});
buttonPanel.add(locationTextField);
JButton goButton = new JButton("GO");
goButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
actionGo();
}
});
buttonPanel.add(goButton);
// Set up page display.
displayEditorPane = new JEditorPane();
displayEditorPane.setContentType("text/html");
displayEditorPane.setEditable(false);
displayEditorPane.addHyperlinkListener(this);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(buttonPanel, BorderLayout.NORTH);
getContentPane().add(new JScrollPane(displayEditorPane),
BorderLayout.CENTER);
}
// Exit this program.
private void actionExit() {
System.exit(0);
}
// Go back to the page viewed before the current page.
private void actionBack() {
URL currentUrl = displayEditorPane.getPage();
int pageIndex = pageList.indexOf(currentUrl.toString());
try {
showPage(
new URL((String) pageList.get(pageIndex - 1)), false);
}
catch (Exception e) {}
}
// Go forward to the page viewed after the current page.
private void actionForward() {
URL currentUrl = displayEditorPane.getPage();
int pageIndex = pageList.indexOf(currentUrl.toString());
try {
showPage(
new URL((String) pageList.get(pageIndex + 1)), false);
}
catch (Exception e) {}
}
// Load and show the page specified in the location text field.
private void actionGo() {
URL verifiedUrl = verifyUrl(locationTextField.getText());
if (verifiedUrl != null) {
showPage(verifiedUrl, true);
} else {
showError("Invalid URL");
}
}
// Show dialog box with error message.
private void showError(String errorMessage) {
JOptionPane.showMessageDialog(this, errorMessage,
"Error", JOptionPane.ERROR_MESSAGE);
}
// Verify URL format.
private URL verifyUrl(String url) {
// Only allow HTTP URLs.
if (!url.toLowerCase().startsWith("http://"))
return null;
// Verify format of URL.
URL verifiedUrl = null;
try {
verifiedUrl = new URL(url);
} catch (Exception e) {
return null;
}
return verifiedUrl;
}
/* Show the specified page and add it to
the page list if specified. */
private void showPage(URL pageUrl, boolean addToList)
{
// Show hour glass cursor while crawling is under way.
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
// Get URL of page currently being displayed.
URL currentUrl = displayEditorPane.getPage();
// Load and display specified page.
displayEditorPane.setPage(pageUrl);
// Get URL of new page being displayed.
URL newUrl = displayEditorPane.getPage();
// Add page to list if specified.
if (addToList) {
int listSize = pageList.size();
if (listSize > 0) {
int pageIndex =
pageList.indexOf(currentUrl.toString());
if (pageIndex < listSize - 1) {
for (int i = listSize - 1; i > pageIndex; i--) {
pageList.remove(i);
}
}
}
pageList.add(newUrl.toString());
}
// Update location text field with URL of current page.
locationTextField.setText(newUrl.toString());
// Update buttons based on the page being displayed.
updateButtons();
}
catch (Exception e)
{
// Show error messsage.
showError("Unable to load page");
}
finally
{
// Return to default cursor.
setCursor(Cursor.getDefaultCursor());
}
}
/* Update back and forward buttons based on
the page being displayed. */
private void updateButtons() {
if (pageList.size() < 2) {
backButton.setEnabled(false);
forwardButton.setEnabled(false);
} else {
URL currentUrl = displayEditorPane.getPage();
int pageIndex = pageList.indexOf(currentUrl.toString());
backButton.setEnabled(pageIndex > 0);
forwardButton.setEnabled(
pageIndex < (pageList.size() - 1));
}
}
// Handle hyperlink's being clicked.
public void hyperlinkUpdate(HyperlinkEvent event) {
HyperlinkEvent.EventType eventType = event.getEventType();
if (eventType == HyperlinkEvent.EventType.ACTIVATED) {
if (event instanceof HTMLFrameHyperlinkEvent) {
HTMLFrameHyperlinkEvent linkEvent =
(HTMLFrameHyperlinkEvent) event;
HTMLDocument document =
(HTMLDocument) displayEditorPane.getDocument();
document.processHTMLFrameHyperlinkEvent(linkEvent);
} else {
showPage(event.getURL(), true);
}
}
}
// Run the Mini Browser.
public static void main(String[] args) {
MiniBrowser browser = new MiniBrowser();
browser.show();
}
}
can u do some changes in this ?
i am very thankful to u if u do it.
Edited by WingedPanther, 20 September 2008 - 07:07 AM.
add code tags
#6
Posted 20 September 2008 - 07:00 AM
Please use code tags when posting code. Thank you :)
#7
Posted 20 September 2008 - 07:06 AM
morefood2001 said:
Please use code tags when posting code. Thank you :)
Couldn't say it better myself :)
And thanks WingedPanther for fixing !
#8
Posted 20 September 2008 - 07:31 AM
markwilson said:
hi friends,
can u help me in, Designing a new web browser
i have some sample code to desing a new browser
but its not sufficient , it only show's URL bar and Go button
i want some advance level
like
1. Next ,Prev ,Stop , Refresh Buttons
2. Status Bar
and some good Grapics look
hope u will help me ,
Thank you,
can u help me in, Designing a new web browser
i have some sample code to desing a new browser
but its not sufficient , it only show's URL bar and Go button
i want some advance level
like
1. Next ,Prev ,Stop , Refresh Buttons
2. Status Bar
and some good Grapics look
hope u will help me ,
Thank you,
Double post here, sorry about it;but did you get your browser from here?
Creating a web browser in Java - DevX.com Forums
#9
Posted 20 September 2008 - 08:59 AM
Turk4n said:
Double post here, sorry about it;but did you get your browser from here?
Creating a web browser in Java - DevX.com Forums
Creating a web browser in Java - DevX.com Forums
Looks really similar. As I've said thousands of times, it doesn't pay to copy other people's code because normally you have no clue what they did and how it works. The easiest way for me to code is to start from scratch so I know exactly what everything does, its also helpful when others ask you to explain what a certain part does.
#10
Posted 20 September 2008 - 10:22 AM
morefood2001 said:
Looks really similar. As I've said thousands of times, it doesn't pay to copy other people's code because normally you have no clue what they did and how it works. The easiest way for me to code is to start from scratch so I know exactly what everything does, its also helpful when others ask you to explain what a certain part does.
Well said old bean!
#11
Posted 21 September 2008 - 10:21 PM
thankx u all for reply,
ok Mr.morefood2001 ya u r right ,we have 2 start from scratch and den only we will get something ,
fine but i m also devloping my own broser but ony i m taking help of that site ,
2 button and 1 text box can anyone add it , but de main par it running Css and Js its Difficult , fine
thankx u both for such a good comments , i will remember that .
Bye
ok Mr.morefood2001 ya u r right ,we have 2 start from scratch and den only we will get something ,
fine but i m also devloping my own broser but ony i m taking help of that site ,
2 button and 1 text box can anyone add it , but de main par it running Css and Js its Difficult , fine
thankx u both for such a good comments , i will remember that .
Bye
#12
Posted 25 September 2008 - 08:54 PM
thnx its very useful ,
fine i have downloaded that "JDesktop.jar file
and extract that using WinRar Software , its show some class files and
Web-inf and some more files
how can i view that source code (.class file )
u have any software for Converting (class file to Java file ) .
or one more thing is jdic has there own API , if i m doing same project den i have to mention that jdic Class on my project .
is it ok if i m doing same project at my Final year.
can u clear my dought on "jdic classes or API "
fine i have downloaded that "JDesktop.jar file
and extract that using WinRar Software , its show some class files and
Web-inf and some more files
how can i view that source code (.class file )
u have any software for Converting (class file to Java file ) .
or one more thing is jdic has there own API , if i m doing same project den i have to mention that jdic Class on my project .
is it ok if i m doing same project at my Final year.
can u clear my dought on "jdic classes or API "


Sign In
Create Account

Back to top









