codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Beanshell web browser  PlayCay at 18:02 on Thursday, August 23, 2007
 

http://www.beanshell.org/examples/browser.html

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import java.awt.event.*;
import java.awt.*;

JFrame browser( startingUrl ) {
invoke( method, args ) {}

windowClosing(WindowEvent we) {
we.getWindow().setVisible(false);
}

setPage( url ) {
try {
pane.setPage( url );
} catch(Exception e) {
statusBar.setText("Error opening page: "+url);
}
}

hyperlinkUpdate( HyperlinkEvent he ) {
type = he.getEventType();
if (type == HyperlinkEvent.EventType.ENTERED) {
pane.setCursor(
Cursor.getPredefinedCursor( Cursor.HAND_CURSOR) );
statusBar.setText(he.getURL().toString());
} else
if (type == HyperlinkEvent.EventType.EXITED) {
pane.setCursor( Cursor.getDefaultCursor() );
statusBar.setText(" ");
} else {
setPage( he.getURL() );
if (urlField != null)
urlField.setText(he.getURL().toString());
}
}

frame = new JFrame("Browser");
frame.setSize(400,300);
frame.addWindowListener( this );

urlPanel = new JPanel();
urlPanel.setLayout(new BorderLayout());
urlField = new JTextField(startingUrl);
urlPanel.add(new JLabel("Site: "), BorderLayout.WEST);
urlPanel.add(urlField, BorderLayout.CENTER);

statusBar = new JLabel(" ");
pane = new JEditorPane();
pane.setEditable(false);
setPage( startingUrl );
jsp = new JScrollPane(pane);

frame.getContentPane().add(jsp, BorderLayout.CENTER);
frame.getContentPane().add(urlPanel, BorderLayout.SOUTH);
frame.getContentPane().add(statusBar, BorderLayout.NORTH);

// This is the equivalent of an inner class in bsh.
urlTextHandler() {
actionPerformed(ActionEvent ae) {
setPage( ae.getActionCommand() );
}
return this;
}

urlField.addActionListener( urlTextHandler() );
pane.addHyperlinkListener( (HyperlinkListener)this );

return frame;
}

browser = browser("http://java.sun.com/");
browser.show();

how can i make it

  Re: Beanshell web browser  kanad at 10:41 on Friday, August 24, 2007
 

JEditorPane(javax.swing.JEditorPane) is used
JEditorPane e = new JEditorPane();

implement HyperlinkListener which is in
javax.swing.event.HyperlinkListener package
HyperlinkEvent event is in
javax.swing.event.HyperlinkEvent package

e.addHyperlinkListener(your class on which hyperlinklistener implemented);
e.setEditable(false);
e.setPage(URL)
or
e.setPage(String)//String url="www.google.com"

note it doesn't support css or javascript or activex









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Re: Security - Code verify
•  Job @ EarlySail
•  Job @ EarlySail (perl)
•  IPC problem
•  Re: import contacts of msn/yahoo
•  Cookies and Threads C++
•  right justify a background in a table?
•  Help with Loop (C++/MFC)
•  Help with Loop (C++/MFC)


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007