社区
Java SE
帖子详情
用java制作浏览器
pansiom
2005-12-14 09:27:07
请问怎么做?
...全文
766
7
打赏
收藏
用java制作浏览器
请问怎么做?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
7 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
bovy
2005-12-22
打赏
举报
回复
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.net.URL;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import javax.swing.SwingConstants;
public class JavaExplorer extends JFrame
{
private final class LoadUrlAction extends MouseAdapter
{
/**
* @param meta
* @return
*/
public String getCharsetName(String meta)
{
if (null == meta || meta.trim().length() == 0)
{
return "";
}
meta = meta.trim().toLowerCase();
int index = 0;
if ((index = meta.indexOf("charset")) < 0)
{
return "";
}
if (index >= 0)
{
while (index < meta.length())
{
if (meta.charAt(index) != '=')
{
index++;
}
else
{
index++;
break;
}
}
int endIndex = index;
while (endIndex < meta.length())
{
if (meta.charAt(endIndex) != ';' && meta.charAt(endIndex) != '\"' && meta.charAt(endIndex) != '\'')
{
endIndex++;
}
else
{
break;
}
}
return meta.substring(index, endIndex);
}
return "";
}
public void mousePressed(MouseEvent e)
{
try
{
URL url = new URL(JavaExplorer.this.urlTxt.getText());
JavaExplorer.this.content.setPage(url);
// BufferedInputStream receiver = new
// BufferedInputStream(url.openStream());
// ByteArrayOutputStream _bodyByteBuffer = new
// ByteArrayOutputStream(4 * 1024);
// byte[] buffer = new byte[1024];
// int len = -1;
// do
// {
// len = receiver.read(buffer);
// if (len < 0)
// {
// break;
// }
// _bodyByteBuffer.write(buffer, 0, len);
// }
// while (len != 0);
// String charsetName =
// getCharsetName(_bodyByteBuffer.toString());
// String body;
// if (charsetName.length() > 0)
// {
// body = _bodyByteBuffer.toString(charsetName);
// }
// else
// {
// // if we can't get the charset,let's use the the lastest
// // charset.(usual default charset)
// body = _bodyByteBuffer.toString();
// }
// JavaExplorer.this.content.setText(body);
// JOptionPane.showMessageDialog(JavaExplorer.this, body);
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
}
private JTextField urlTxt;
private SpringLayout springLayout;
private JEditorPane content;
/**
* Launch the application
*
* @param args
*/
public static void main(String args[])
{
try
{
JavaExplorer frame = new JavaExplorer();
frame.setVisible(true);
}
catch (Exception e)
{
e.printStackTrace();
}
}
/**
* Create the frame
*/
public JavaExplorer()
{
super();
springLayout = new SpringLayout();
getContentPane().setLayout(springLayout);
setTitle("Java 浏览器");
setBounds(100, 100, 648, 503);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JLabel label = new JLabel();
label.setHorizontalAlignment(SwingConstants.RIGHT);
label.setHorizontalTextPosition(SwingConstants.RIGHT);
label.setText("地址:");
getContentPane().add(label);
springLayout.putConstraint(SpringLayout.SOUTH, label, 25, SpringLayout.NORTH, getContentPane());
springLayout.putConstraint(SpringLayout.EAST, label, 90, SpringLayout.WEST, getContentPane());
springLayout.putConstraint(SpringLayout.NORTH, label, 5, SpringLayout.NORTH, getContentPane());
springLayout.putConstraint(SpringLayout.WEST, label, 5, SpringLayout.WEST, getContentPane());
urlTxt = new JTextField();
urlTxt.setText("http://www.boasoft.com/t2s/index.jsp");
getContentPane().add(urlTxt);
springLayout.putConstraint(SpringLayout.SOUTH, urlTxt, 0, SpringLayout.SOUTH, label);
springLayout.putConstraint(SpringLayout.EAST, urlTxt, -75, SpringLayout.EAST, getContentPane());
springLayout.putConstraint(SpringLayout.NORTH, urlTxt, 0, SpringLayout.NORTH, label);
springLayout.putConstraint(SpringLayout.WEST, urlTxt, 5, SpringLayout.EAST, label);
final JButton goButton = new JButton();
goButton.addMouseListener(new LoadUrlAction());
goButton.setText("GO");
getContentPane().add(goButton);
springLayout.putConstraint(SpringLayout.SOUTH, goButton, 0, SpringLayout.SOUTH, urlTxt);
springLayout.putConstraint(SpringLayout.EAST, goButton, -5, SpringLayout.EAST, getContentPane());
springLayout.putConstraint(SpringLayout.NORTH, goButton, 0, SpringLayout.NORTH, urlTxt);
springLayout.putConstraint(SpringLayout.WEST, goButton, 5, SpringLayout.EAST, urlTxt);
final JScrollPane scrollPane = new JScrollPane();
getContentPane().add(scrollPane);
springLayout.putConstraint(SpringLayout.SOUTH, scrollPane, -5, SpringLayout.SOUTH, getContentPane());
springLayout.putConstraint(SpringLayout.EAST, scrollPane, 0, SpringLayout.EAST, goButton);
springLayout.putConstraint(SpringLayout.NORTH, scrollPane, 5, SpringLayout.SOUTH, label);
springLayout.putConstraint(SpringLayout.WEST, scrollPane, 0, SpringLayout.WEST, label);
content = new JEditorPane();
scrollPane.setViewportView(content);
}
}
gazhangting
2005-12-21
打赏
举报
回复
这位老兄是不是学软件的啊,你也能做出一个浏览器吗?我们能做的只是他的外壳,我们中国现在都没有一个.....
只是做了不少它的外壳啊,
良少
2005-12-19
打赏
举报
回复
不用自己写浏览器, 可以在界面里加入一个容器,这个容器中显示系统中已存在的其他浏览器,如IE,FireFox等。 一般都是这么做的,没有人傻到自己做浏览器的!
pansiom
2005-12-19
打赏
举报
回复
谢谢哦,
但我有点问题:
当输入http://www.5566.net后,有部分js显示出来了.
还有,我下了个JDIC API 但不知如何用,请问你知道不?
谢谢
Q19830409
2005-12-18
打赏
举报
回复
输入时有加http:// 才可以搜索网址 主要的插件 自己加
Q19830409
2005-12-18
打赏
举报
回复
主要用超连接一些属性而已
package 文昌浏览器;
import java.io.IOException;
import java.net.URL;
import javax.swing.*;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
public class HtmlBrowser extends JFrame{
JPanel contentPane;//include the whole frame container
BorderLayout borderLayoutAll=new BorderLayout();
JLabel jLabelPrompt=new JLabel();
JPanel jPanelMain=new JPanel();
BorderLayout borderLayoutMain=new BorderLayout();
JTextField textFieldURL=new JTextField();
JEditorPane jEditorPane=new JEditorPane();
public HtmlBrowser() {//define the hash and struct it
try{jbInit();//inintalize the GUI
}
catch(Exception e){
e.printStackTrace();}
}
private void jbInit()throws Exception{//GUI inintalize
contentPane=(JPanel)getContentPane();
contentPane.setLayout(borderLayoutAll);
jPanelMain.setLayout(borderLayoutMain);
jLabelPrompt.setText("please translate url");
textFieldURL.setText(" ");// clear the textArea
textFieldURL.addActionListener(new java.awt.event.ActionListener(){
public void actionPerformed(ActionEvent e)
{textFieldURL_actionPerformed(e);}
});
jEditorPane.setEditable(false);//she zhi bu ke bianji
jEditorPane.addHyperlinkListener(new javax.swing.event.HyperlinkListener()
{public void hyperlinkUpdate(HyperlinkEvent e){
jEditorPane_hyperlinkUpdate(e);}
});
JScrollPane scrollPane=new JScrollPane();
scrollPane.getViewport().add(jEditorPane);
jPanelMain.add(textFieldURL,"North");
jPanelMain.add(scrollPane,"Center");
contentPane.add(jLabelPrompt,"North");
contentPane.add(jPanelMain,"Center");
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
this.setSize(new Dimension(600,500));
this.setTitle("我的浏览器");
this.setVisible(true);
}
void textFieldURL_actionPerformed(ActionEvent e){// into enter to response
try{jEditorPane.setPage(textFieldURL.getText());
}
catch(IOException ex){JOptionPane msg=new JOptionPane();
JOptionPane.showMessageDialog(this,"URL地址不正确:"+textFieldURL.getText(),"输入不正确 !",0);
}
}
void jEditorPane_hyperlinkUpdate(HyperlinkEvent e)
{
if(e.getEventType ()==
javax.swing.event.HyperlinkEvent.EventType.ACTIVATED)
{
try{
URL url=e.getURL();
jEditorPane.setPage(url);
textFieldURL.setText(url.toString());}
catch(IOException io){
JOptionPane msg=new JOptionPane();
JOptionPane.showMessageDialog(this,"打开文件失败!"+textFieldURL.getText(),"输入的不正确!",0);
}
}
}
protected void processWindowEvent(WindowEvent e) { //chulichuangti
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
public static void main(String[] args) { //main hashu
new HtmlBrowser();
}
}
pansiom
2005-12-14
打赏
举报
回复
找到这些东东,不知是不是,怎样用:
WebBrowser (Sourceforge Plugin 1.1 API) - [ 翻译此页 BETA ]
java.lang.Object extended by net.sourceforge.mavenplugins.sourceforge.WebBrowser.
public class WebBrowser; extends java.lang.Object. Emulates a web browser.
Version:: $Revision: 1.2 $ $Date: 2004/02/04 23:48:15 $; Author:: Ludovic ...
______________________________________________________________
http://maven-plugins.sourceforge.net/maven-sourceforge-plugin/apidocs/net/sourceforge/mavenplugins/sourceforge/WebBrowser.html
java
制作
的
浏览器
java
制作
的
浏览器
源代码 希望朋友们下载哦
JAVA
制作
HTML
浏览器
JAVA
制作
HTML
浏览器
JAVA
制作
HTML
浏览器
JAVA
制作
HTML
浏览器
Java
制作
浏览器
和源代码查看器.rar
Java
制作
的网页
浏览器
和源代码查看器,仿IE的网页浏览功能,不支持HTML5,窗口采用上下分屏显示的方式,上面显示网页
浏览器
,下面显示该网页的源代码,JTextField jtfAddress; //输入html文件地址或网址 JTextPane jtpShow; //显示页面 JTextArea jtaSource; //显示HTML源文件 public HTTPBrowser(){ super("HTTP连接与浏览"); //调用父类构造函数 jtfAddress=new JTextField(30); //实例化地址输入框 jtpShow=new JTextPane(); //实例化显示内容框 jtaSource=new JTextArea(); JPanel p1=new JPanel(); //实例化面板 JSplitPane spane=new JSplitPane(JSplitPane.VERTICAL_SPLIT); //实例化分隔面板 p1.add(new JLabel("地址")); //增加组件到面板上 p1.add(jtfAddress); spane.add(new JScrollPane(jtpShow),JSplitPane.TOP); spane.add(new JScrollPane(jtaSource),JSplitPane.BOTTOM); spane.setDividerLocation(130); //设置分隔位置 spane.setDividerSize(2); //设置分隔栏尺寸 Container container=getContentPane(); //得到容器 container.add(p1,BorderLayout.NORTH); //增加组件到容器上
用
java
制作
简易
浏览器
java
简易
浏览器
可以实现最简单的浏览网页的功能
用
java
编写的
浏览器
java
编写的
浏览器
。。能浏览网页。和超链接。。有后退和前进等功能
Java SE
62,616
社区成员
307,307
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章