用Java编程实现“网络蜘蛛” - 编程入门网
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-06-24
errorScroll.setHorizontalScrollBarPolicy(javax.swing. ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); errorScroll.setVerticalScrollBarPolicy(javax.swing. ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); errorScroll.setOpaque(true); getContentPane().add(errorScroll); errorScroll.setBounds(12,120,384,156); errors.setEditable(false); errorScroll.getViewport().add(errors); errors.setBounds(0,0,366,138); current.setText("当前处理进度:"); getContentPane().add(current); current.setBounds(12,72,384,12); goodLinksLabel.setText("正常链接:0"); getContentPane().add(goodLinksLabel); goodLinksLabel.setBounds(12,96,192,12); badLinksLabel.setText("死链接:0"); getContentPane().add(badLinksLabel); badLinksLabel.setBounds(216,96,96,12); //}} //{{INIT_MENUS //}} //{{REGISTER_LISTENERS SymAction lSymAction = new SymAction(); begin.addActionListener(lSymAction); //}} } /** *参数args未使用 */ static public void main(String args[]) { (new CheckLinks()).setVisible(true); } /** *添加通知 */ public void addNotify() { //记录窗口尺寸并调用父类的addNotify. Dimension size = getSize(); super.addNotify(); if ( frameSizeAdjusted ) return; frameSizeAdjusted = true; //根据菜单栏等调整Frame尺寸 Insets insets = getInsets(); javax.swing.JMenuBar menuBar = getRootPane().getJMenuBar(); int menuBarHeight = 0; if ( menuBar != null ) menuBarHeight = menuBar.getPreferredSize().height; setSize(insets.left + insets.right + size.width, insets.top + insets.bottom + size.height + menuBarHeight); } boolean frameSizeAdjusted = false; //{{DECLARE_CONTROLS javax.swing.JLabel label1 = new javax.swing.JLabel(); javax.swing.JButton begin = new javax.swing.JButton(); javax.swing.JTextField url = new javax.swing.JTextField(); javax.swing.JScrollPane errorScroll = new javax.swing.JScrollPane(); /** *存储错误信息 */ javax.swing.JTextArea errors = new javax.swing.JTextArea(); javax.swing.JLabel current = new javax.swing.JLabel(); javax.swing.JLabel goodLinksLabel = new javax.swing.JLabel(); javax.swing.JLabel badLinksLabel = new javax.swing.JLabel(); //}} //{{DECLARE_MENUS //}} /** *后台蜘蛛线程 */ protected Thread backgroundThread; protected Spider spider; protected URL base; protected int badLinksCount = 0; protected int goodLinksCount = 0; /** *用于分发事件的内部类 */ class SymAction implements java.awt.event.ActionListener { public void actionPerformed(java.awt.event.ActionEvent event) { Object object = event.getSource(); if ( object == begin ) begin_actionPerformed(event); } } /** *当begin或cancel按钮被点击时调用 * *参数event与按钮相连 */ void begin_actionPerformed(java.awt.event.ActionEvent event) { if ( backgroundThread==null ) { begin.setLabel("Cancel"); backgroundThread = new Thread(this); backgroundThread.start(); goodLinksCount=0; badLinksCount=0; } else { spider.cancel(); } } /** *执行后台线程操作 */ public void run() { try { errors.setText(""); spider = new Spider(this); spider.clear(); base = new URL(url.getText()); spider.addURL(base); spide |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于用Java编程实现“网络蜘蛛” - 编程入门网的所有评论