啊,这好象不容易,要对那么多HTML标记进行解析,哈哈,强烈关注。
解决方案 »
- 空指针异常求解
- 请教Java中的evaluate问题
- 求助!如何自己执行存储过程代码?
- JAVA入门级新手提问有关J2SE版本问题
- 请教在JSP文件中加入JApplet的方法(在JApplet中可能带有Swing组件)
- 请高手帮忙指点一下,如何把一个java应用程序做为windows的服务,开机时自动运行??
- 新手入门:如何在项目中导入原有的java包(jbuilder)?
- 求助大神:如何从电脑上随机输入限定范围的数字
- 简单问题:字符串格式转换问题(判断时间范围)
- 请教一个取得文件大小的问题?
- 请问各位xdjm:UltraEdit-32 的Authorization Code 到那里可以找到啊?
- 求源代码!
// This program uses a JEditorPane to display the
// contents of a file on a Web server.// Java core packages
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.util.*;// Java extension packages
import javax.swing.*;
import javax.swing.event.*;public class WebReader extends JFrame {
private JTextField enterField;
private JEditorPane contentsArea;
private JButton backButton,fwdButton;
private JPanel contralPanel;
private URLList urllist;
// set up GUI
public WebReader()
{
super( "My Web Browser" );
JMenu fileMenu = new JMenu("File");//set up File menu ane its menu item
fileMenu.setMnemonic('F'); JMenuItem exitItem = new JMenuItem("Exit");
exitItem.setMnemonic('X');
exitItem.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
System.exit(0);
}
}
);
fileMenu.add( exitItem ); JMenuBar bar = new JMenuBar();
setJMenuBar( bar );
bar.add( fileMenu ); JMenu editMenu = new JMenu("Edit");
editMenu.setMnemonic('E'); JMenuItem nextItem = new JMenuItem( "Next" );
nextItem.setMnemonic( 'N' );
nextItem.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
System.exit(0);
}
}
);
editMenu.add( nextItem );
bar.add( editMenu ); Container container = getContentPane(); FlowLayout lay=new FlowLayout();
lay.setAlignment( FlowLayout.LEFT ); contralPanel = new JPanel();
contralPanel.setLayout( lay ); urllist = new URLList(); Icon back = new ImageIcon( "back.gif" );
backButton = new JButton( "back",back );
backButton.addActionListener(
new ActionListener()
{
public void actionPerformed( ActionEvent event )
{
String strback=new String( urllist.back() );
System.out.println( strback );
if( !strback.equals( "Noop" ) )
getThePage( strback );
}
}
);
contralPanel.add( backButton ); Icon fwd = new ImageIcon( "fwd.gif" );
fwdButton = new JButton( "fwd",fwd );
fwdButton.addActionListener(
new ActionListener()
{
public void actionPerformed( ActionEvent event )
{
String strfwd=new String( urllist.forward() );
System.out.println( strfwd );
if( !strfwd.equals( "Noop" ) )
getThePage( strfwd );
}
}
);
contralPanel.add( fwdButton ); // create enterField and register its listener
enterField = new JTextField( "Enter file URL here",24 ); enterField.addActionListener( new ActionListener() { // get document specified by user
public void actionPerformed( ActionEvent event )
{
urllist.push( event.getActionCommand() );
getThePage( event.getActionCommand() );
} } // end anonymous inner class ); // end call to addActionListener enterField.addMouseListener(
new MouseListener(){
public void mouseClicked( MouseEvent e )
{
enterField.selectAll();
} public void mousePressed( MouseEvent e )
{
} public void mouseReleased( MouseEvent e )
{
}
public void mouseEntered( MouseEvent e )
{
}
public void mouseExited( MouseEvent e )
{
}
}
); contralPanel.add( enterField ); container.add( contralPanel, BorderLayout.NORTH );
// create contentsArea and register HyperlinkEvent listener
contentsArea = new JEditorPane();
contentsArea.setEditable( false ); contentsArea.addHyperlinkListener( new HyperlinkListener() { // if user clicked hyperlink, go to specified page
public void hyperlinkUpdate( HyperlinkEvent event )
{
if ( event.getEventType() ==
HyperlinkEvent.EventType.ACTIVATED )
{
urllist.push( event.getURL().toString() );
getThePage( event.getURL().toString() );
}
} } // end anonymous inner class ); // end call to addHyperlinkListener container.add( new JScrollPane( contentsArea ) ,
BorderLayout.CENTER ); setSize( 1000, 700 );
setVisible( true );
} // load document; change mouse cursor to indicate status
private void getThePage( String location )
{
// change mouse cursor to WAIT_CURSOR
setCursor( Cursor.getPredefinedCursor(
Cursor.WAIT_CURSOR ) ); if(!location.startsWith( "http://" ))
location="http://" + location; // load document into contentsArea and display location in
// enterField
try {
contentsArea.setPage( location );
enterField.setText( location );
} // process problems loading document
catch ( IOException ioException ) {
JOptionPane.showMessageDialog( this,
"Error retrieving specified URL",
"Bad URL", JOptionPane.ERROR_MESSAGE );
} setCursor( Cursor.getPredefinedCursor(
Cursor.DEFAULT_CURSOR ) );
} // begin application execution
public static void main( String args[] )
{
WebReader application = new WebReader(); application.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE ); }} // end class WebReader
class URLList
{
private int now = 0;
private Vector vector; URLList()
{
vector = new Vector( 1 );
}
public void push(String url)
{
vector.add(url);
now = vector.size()-1;
} public String back()
{
System.out.println( "back " + now );
if( now == 0 )
return( "Noop" );
else
{
now--;
System.out.println( "back----" + now );
return( (String)vector.get( now ));
}
} public String forward()
{
System.out.println( "fwd" + now + vector.size() );
if( ( vector.size() == 0 ) || ( now == ( vector.size()-1 ) ) )
return( "Noop" );
else
{
now++;
System.out.println( "fwd+++" + now );
return( (String)vector.get( now ));
}
}
public int getnow()
{
return now;
}
}