高分请教:在应用中如何嵌入浏览器功能 去查看Swing组件都具有这功能,尤其是JXXHTML XXPanel...的你有些Caption直接setText("<html><font xxx>sdfsdfd...");就ok 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 好像一直没有好的解决方案jintegra 可以 使用过不错 就是整合的中间包不过要收费的http://www.intrinsyc.com/products/j-integra/ to:liaomingxue() 就是想在应用中实现一个简单的浏览器功能,如地址栏,GO,Back,Home,超链接这些就是用java实现浏览器谢谢先 还是给个演示程序你吧,把下面的代码放到一个Frame1.java文件中我不肯定能适合你的需要,因为我不能完全领会你的需要,希望对你有帮助:(下面用到的方法我也是从别人,但已经忘记是谁了,那里获得的)import java.awt.*;import java.awt.event.*;import java.io.*;import java.util.*;import javax.swing.*;import javax.swing.event.*;public class Frame1{ public static void main(String[] args) { JFrame frame = new EditorPaneFrame(); frame.show(); }}class EditorPaneFrame extends JFrame{ public EditorPaneFrame() { this.setTitle("EditorPaneTest"); this.setSize(600, 400); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e){ System.exit(0); } } ); // set up text field and load button for typing in URL url = new JTextField(30); loadButton = new JButton("Load"); loadButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { // remember URL for back button urlStack.push(url.getText()); editorPane.setPage(url.getText()); } catch(IOException e) { editorPane.setText("Error: " + e); } } }); // set up back button and button action backButton = new JButton("Back"); backButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if (urlStack.size() <= 1) return; try { // get URL from back button urlStack.pop(); // show URL in text field String urlString = (String)urlStack.peek(); url.setText(urlString); editorPane.setPage(urlString); } catch(IOException e){ editorPane.setText("Error: " + e); } } }); // set up editor pane and hyperlink listener editorPane = new JEditorPane(); editorPane.setEditable(false); editorPane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent event) { if (event.getEventType()== HyperlinkEvent.EventType.ACTIVATED) { try { // remember URL for back button urlStack.push(event.getURL().toString()); // show URL in text field url.setText(event.getURL().toString()); editorPane.setPage(event.getURL()); } catch(IOException e){ editorPane.setText("Error: " + e);} } } }); // set up checkbox for toggling edit mode editable = new JCheckBox(); editable.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { editorPane.setEditable(editable.isSelected()); } }); Container contentPane = getContentPane(); contentPane.add(new JScrollPane(editorPane), "Center"); // put all control components in a panel JPanel panel = new JPanel(); panel.add(new JLabel("URL")); panel.add(url); panel.add(loadButton); panel.add(backButton); panel.add(new JLabel("Editable")); panel.add(editable); contentPane.add(panel, "South"); } private JTextField url; private JCheckBox editable; private JButton loadButton; private JButton backButton; private JEditorPane editorPane; private Stack urlStack = new Stack();} to:liaomingxue() 非常感谢,你的代码基本上能够实现我的想法,另外如果方便的话,麻烦告诉前进功能如何实现呢 to:liaomingxue()好像不支持javascript:)哪儿有官方的包下载吗 class EditorPaneFrame extends JFrame{ private JTextField url; private JCheckBox editable; private JButton loadButton; private JButton backButton; private JButton forwardButton=new JButton("forward"); private JEditorPane editorPane; final static int MAX_PAGES=100; private Vector pages=new Vector(); private int currentPage=-1; public EditorPaneFrame() { this.setTitle("EditorPaneTest"); this.setSize(600, 400); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // set up text field and load button for typing in URL url = new JTextField(30); loadButton = new JButton("Load"); loadButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { currentPage++; pages.add(url.getText()); editorPane.setPage(url.getText()); } catch(IOException e) { editorPane.setText("Error: " + e); } } }); // set up back button and button action backButton = new JButton("Back"); backButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { currentPage--; if(currentPage<0) return; try { String urlString = (String)pages.get(currentPage); url.setText(urlString); editorPane.setPage(urlString); } catch(IOException e){ editorPane.setText("Error: " + e); } } }); forwardButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { currentPage++; if (currentPage>=pages.size()) return; try { String urlString = (String)pages.get(currentPage); url.setText(urlString); editorPane.setPage(urlString); } catch (IOException e) {editorPane.setText("Error: " + e);} } }); // set up editor pane and hyperlink listener editorPane = new JEditorPane(); editorPane.setEditable(false); editorPane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent event) { if (event.getEventType()== HyperlinkEvent.EventType.ACTIVATED) { try { currentPage++; pages.add(event.getURL().toString()); url.setText(event.getURL().toString()); editorPane.setPage(event.getURL()); } catch(IOException e){editorPane.setText("Error: " + e);} } } }); // set up checkbox for toggling edit mode editable = new JCheckBox(); editable.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { editorPane.setEditable(editable.isSelected()); } }); Container contentPane = getContentPane(); contentPane.add(new JScrollPane(editorPane), "Center"); // put all control components in a panel JPanel panel = new JPanel(); panel.add(new JLabel("URL")); panel.add(url); panel.add(loadButton); panel.add(backButton); panel.add(forwardButton); panel.add(new JLabel("Editable")); panel.add(editable); contentPane.add(panel, "South"); }} 啊,javascript呀?如果你真的要超过ie,那么我是没有办法喽。你可以直接调用ie呀。 谁有办法把IE嵌在JAVA应用程序里我就服了他,我加他三百分 可以呀,下面时演示:不过要换个被演示的html哟:public class Frame1{ public static void main(String[] args) { try { // 使用命令行,相当于在windows命令行中运行 Runtime.getRuntime().exec("cmd /c start F://javaProjects//WatMaker//doc//index.html"); } catch (IOException e) {} }} 是内嵌,这样做是在程序外部启动,能嵌在JFrame或其他容器里吗? jar运行的怪问题 如何判断两个对象是同一类型 问一个很弱的问题, Thread问题! 如何设定SplitPane的两个分区的大小? 求发送邮件的源代码 有 的请把Email留下 用java调dll,在打包后报错 怎样判断一个目录中的文件和文件目录 请问哪里有用JAVA实现语音聊天的例子或代码参考? *.bat的问题 关于Date类的使用问题,请大家帮忙!!! 问一个有关swing的问题,大虾们帮帮忙
jintegra 可以 使用过不错 就是整合的中间包
不过要收费的http://www.intrinsyc.com/products/j-integra/
就是想在应用中实现一个简单的浏览器功能,
如地址栏,GO,Back,Home,超链接这些
就是用java实现浏览器谢谢先
我不肯定能适合你的需要,因为我不能完全领会你的需要,希望对你有
帮助:(下面用到的方法我也是从别人,但已经忘记是谁了,那里获得的)
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;public class Frame1
{
public static void main(String[] args)
{
JFrame frame = new EditorPaneFrame();
frame.show();
}
}
class EditorPaneFrame extends JFrame
{
public EditorPaneFrame()
{
this.setTitle("EditorPaneTest");
this.setSize(600, 400);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e){ System.exit(0); }
} );
// set up text field and load button for typing in URL
url = new JTextField(30);
loadButton = new JButton("Load");
loadButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
try
{ // remember URL for back button
urlStack.push(url.getText());
editorPane.setPage(url.getText());
}
catch(IOException e) { editorPane.setText("Error: " + e); }
}
});
// set up back button and button action
backButton = new JButton("Back");
backButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
if (urlStack.size() <= 1) return;
try
{ // get URL from back button
urlStack.pop();
// show URL in text field
String urlString = (String)urlStack.peek();
url.setText(urlString);
editorPane.setPage(urlString);
}
catch(IOException e){ editorPane.setText("Error: " + e); }
}
});
// set up editor pane and hyperlink listener
editorPane = new JEditorPane();
editorPane.setEditable(false);
editorPane.addHyperlinkListener(new HyperlinkListener()
{
public void hyperlinkUpdate(HyperlinkEvent event)
{
if (event.getEventType()== HyperlinkEvent.EventType.ACTIVATED)
{
try
{ // remember URL for back button
urlStack.push(event.getURL().toString());
// show URL in text field
url.setText(event.getURL().toString());
editorPane.setPage(event.getURL());
}
catch(IOException e){ editorPane.setText("Error: " + e);}
}
}
});
// set up checkbox for toggling edit mode
editable = new JCheckBox();
editable.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
editorPane.setEditable(editable.isSelected());
}
});
Container contentPane = getContentPane();
contentPane.add(new JScrollPane(editorPane), "Center");
// put all control components in a panel
JPanel panel = new JPanel();
panel.add(new JLabel("URL"));
panel.add(url);
panel.add(loadButton);
panel.add(backButton);
panel.add(new JLabel("Editable"));
panel.add(editable);
contentPane.add(panel, "South");
}
private JTextField url;
private JCheckBox editable;
private JButton loadButton;
private JButton backButton;
private JEditorPane editorPane;
private Stack urlStack = new Stack();
}
非常感谢,你的代码基本上能够实现我的想法,
另外如果方便的话,麻烦告诉前进功能如何实现呢
好像不支持javascript:)
哪儿有官方的包下载吗
{
private JTextField url;
private JCheckBox editable;
private JButton loadButton;
private JButton backButton;
private JButton forwardButton=new JButton("forward");
private JEditorPane editorPane;
final static int MAX_PAGES=100;
private Vector pages=new Vector();
private int currentPage=-1;
public EditorPaneFrame()
{
this.setTitle("EditorPaneTest");
this.setSize(600, 400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// set up text field and load button for typing in URL
url = new JTextField(30);
loadButton = new JButton("Load");
loadButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
try
{
currentPage++;
pages.add(url.getText());
editorPane.setPage(url.getText());
}
catch(IOException e) { editorPane.setText("Error: " + e); }
}
}); // set up back button and button action
backButton = new JButton("Back");
backButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
currentPage--;
if(currentPage<0) return;
try
{
String urlString = (String)pages.get(currentPage);
url.setText(urlString);
editorPane.setPage(urlString);
}
catch(IOException e){ editorPane.setText("Error: " + e); }
}
});
forwardButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
currentPage++;
if (currentPage>=pages.size()) return;
try
{
String urlString = (String)pages.get(currentPage);
url.setText(urlString);
editorPane.setPage(urlString);
}
catch (IOException e) {editorPane.setText("Error: " + e);}
}
}); // set up editor pane and hyperlink listener
editorPane = new JEditorPane();
editorPane.setEditable(false);
editorPane.addHyperlinkListener(new HyperlinkListener()
{
public void hyperlinkUpdate(HyperlinkEvent event)
{
if (event.getEventType()== HyperlinkEvent.EventType.ACTIVATED)
{
try
{
currentPage++;
pages.add(event.getURL().toString());
url.setText(event.getURL().toString());
editorPane.setPage(event.getURL());
}
catch(IOException e){editorPane.setText("Error: " + e);}
}
}
});
// set up checkbox for toggling edit mode
editable = new JCheckBox();
editable.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
editorPane.setEditable(editable.isSelected());
}
});
Container contentPane = getContentPane();
contentPane.add(new JScrollPane(editorPane), "Center");
// put all control components in a panel
JPanel panel = new JPanel();
panel.add(new JLabel("URL"));
panel.add(url);
panel.add(loadButton);
panel.add(backButton);
panel.add(forwardButton);
panel.add(new JLabel("Editable"));
panel.add(editable);
contentPane.add(panel, "South");
}
}
直接调用ie呀。
public class Frame1
{
public static void main(String[] args)
{
try
{
// 使用命令行,相当于在windows命令行中运行
Runtime.getRuntime().exec("cmd /c start F://javaProjects//WatMaker//doc//index.html");
}
catch (IOException e) {}
}
}