html代码不显示,为什么此代码不显示HTML文件?

java.net.MalformedURLException: no protocol: FAQ.html

at java.net.URL.(Unknown Source)

at java.net.URL.(Unknown Source)

at java.net.URL.(Unknown Source)

at javax.swing.JEditorPane.setPage(Unknown Source)

at org.bihe.com1112.FileViewer.actionPerformed(FileViewer.java:86)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)

at java.awt.Component.processMouseEvent(Unknown Source)

at javax.swing.JComponent.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Window.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

public class FileViewer extends JPanel implements ActionListener {

/**

*

*/

private static final long serialVersionUID = 1L;

JFileChooser chooser;

FileNameExtensionFilter filter = null;

JTextField text;

JButton button;

FileInputStream in;

JEditorPane pane;

public FileViewer(JEditorPane pane) {

this.pane = pane;

setLayout(new FlowLayout(FlowLayout.RIGHT));

text = new JTextField("file...", 31);

text.setColumns(45);

text.revalidate();

text.setEditable(true);

button = new JButton("Browse");

add(text);

add(button);

filter = new FileNameExtensionFilter("html", "html");

chooser = new JFileChooser();

chooser.addChoosableFileFilter(filter);

button.addActionListener(this);

}

public void paintComponent(Graphics g) {

super.paintComponents(g);

Graphics2D graphic = (Graphics2D) g;

graphic.drawString("HTML File:", 10, 20);

}

public void actionPerformed(ActionEvent event) {

int returnVal = 0;

if (event.getSource() == button) {

returnVal = chooser.showOpenDialog(FileViewer.this);

if (returnVal == JFileChooser.APPROVE_OPTION) {

File file = chooser.getSelectedFile();

text.setText(file.getName());

if (file != null) {

try {

pane.setPage(file.getName());

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

} else

System.err.println("Couldn't find this HTML file:"

+ file.getName());

} else

System.exit(0);

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值