[Java] 刷网站访问量 刷网站PV浏览量 →→→→→进入此内容的聊天室

来自 , 2020-07-10, 写在 Java, 查看 106 次.
URL http://www.code666.cn/view/2dace78f
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.io.*;
  4. import java.net.*;
  5.  
  6. import javax.swing.*;
  7.  
  8. public class Boxx extends Thread implements ActionListener, WindowListener {
  9.  
  10.         JFrame f;
  11.  
  12.         JPanel panel1;
  13.         JPanel panel11;
  14.  
  15.         JPanel panel2;
  16.         JPanel panel22;
  17.  
  18.         JPanel panel3;
  19.  
  20.         TextField url;
  21.         TextField time;
  22.         TextField max;
  23.  
  24.         TextArea iP;
  25.  
  26.         JLabel urlname;
  27.         JLabel timename;
  28.         JLabel maxname;
  29.         JLabel ipName;
  30.         JLabel quit;
  31.         JLabel pause;
  32.  
  33.         JButton start;
  34.         JButton end;
  35.  
  36.         public void run() {
  37.                 f = new JFrame("域名IP查询");
  38.  
  39.                 // 创建按钮
  40.                 start = new JButton("开始");
  41.                 end = new JButton("结束");
  42.                 quit = new JLabel("<html>shi_sky,特别制作</html");
  43.                 pause = new JLabel(
  44.                                 "<html>软件开发环境:win_xp_32系统,ie8浏览器,JDK1.6,对于其他环境可能出现程序运行不正常!</html>");
  45.  
  46.                 // 创建相关的文本域
  47.                 url = new TextField("http://www.baidu.com");
  48.                 time = new TextField("3");
  49.                 max = new TextField("200");
  50.                 iP = new TextArea();
  51.                 iP.setColumns(30);
  52.                 iP.setRows(50);
  53.  
  54.                 // 创建相关的Label标签
  55.                 urlname = new JLabel("访问网址(如:http://www.baidu.com)");
  56.                 timename = new JLabel("访问间隔时间(秒)");
  57.                 maxname = new JLabel("访问次数(0~99999次内)");
  58.                 ipName = new JLabel("输出访问信息:");
  59.                 // 初始化容器和容器属性
  60.                 panel1 = new JPanel(new GridLayout(2, 1));// 两行一列
  61.                 panel11 = new JPanel(new GridLayout(2, 1));
  62.                 panel2 = new JPanel(new GridLayout(2, 2));
  63.                 panel3 = new JPanel(new GridLayout(1, 4));
  64.  
  65.                 // 把相关窗口对象添加到容器中去
  66.                 panel1.add(urlname, BorderLayout.CENTER);
  67.                 panel1.add(url, BorderLayout.CENTER);
  68.  
  69.                 panel11.add(ipName);
  70.                 panel11.add(iP);
  71.  
  72.                 panel2.add(timename);
  73.                 panel2.add(maxname);
  74.                 panel2.add(time);
  75.                 panel2.add(max);
  76.  
  77.                 panel3.add(pause);
  78.                 panel3.add(start);
  79.                 panel3.add(end);
  80.                 panel3.add(quit);
  81.  
  82.                 panel22 = new JPanel(new GridLayout(4, 1));
  83.  
  84.                 panel22.add(panel1);
  85.                 panel22.add(panel2);
  86.                 panel22.add(panel11);
  87.                 panel22.add(panel3);
  88.  
  89.                 // 添加事件的監聽
  90.                 start.addActionListener(this);
  91.                 end.addActionListener(this);
  92.  
  93.                 f.setLayout(new BorderLayout());
  94.                 f.add(panel22, BorderLayout.CENTER);
  95.  
  96.                 // 初始化JFrame窗口
  97.  
  98.                 f.setLocation(500, 100);
  99.                 f.setSize(500, 500);
  100.                 f.setBackground(Color.darkGray);
  101.                 f.setResizable(false);
  102.                 f.setVisible(true);
  103.  
  104.         }
  105.  
  106.         // 事件响应类
  107.         public void actionPerformed(ActionEvent arg0) {
  108.  
  109.                 int t = (Integer.valueOf(time.getText()).intValue());// 获取text原件中的int类型的值(访问间隔时间)
  110.                 int m = (Integer.valueOf(max.getText()).intValue());// 获取text原件中的int类型的值(访问次数)
  111.                 int go = 1; // 计数
  112.                 int times = t * 1000;// 由秒转化为毫秒
  113.  
  114.                 if (arg0.getSource() == start) {
  115.  
  116.                         if (url.getText() != null && time.getText() != null
  117.                                         && max.getText() != null) {
  118.  
  119.                                 String url2 = null;
  120.                                 String url1 = url.getText();// 获取text内的url
  121.                                 // 对获取到的网址进行协议或者其他的类型处理(http、ftp、https、file、mailto等协议)
  122.                                 if ((url1.substring(0, 7)).equalsIgnoreCase("http://")
  123.                                                 || (url1.substring(0, 6)).equalsIgnoreCase("ftp://")
  124.                                                 || (url1.substring(0, 8)).equalsIgnoreCase("https://")
  125.                                                 || (url1.substring(0, 7)).equalsIgnoreCase("file://")
  126.                                                 || (url1.substring(0, 7)).equalsIgnoreCase("mailto://")) {
  127.  
  128.                                         url2 = url1;
  129.                                         System.out.println("url1:" + url2);
  130.                                 } else {
  131.                                         url2 = "http://" + url1;
  132.                                         System.out.println("url2:" + url2);
  133.                                 }// 结束对地址的处理
  134.  
  135.                                 while (true) {
  136.                                         // 打开系统默认浏览器
  137.                                         Desktop d = Desktop.getDesktop();
  138.  
  139.                                         try {
  140.                                                 String u = url2.toString(); // 获取处理后的地址
  141.                                                 // Runtime.getRuntime().exec("cmd /c start"+u);
  142.                                                 d.browse(new URI(u));// 指定要打开的网站地址
  143.                                                 System.out.println("url3:" + url2);
  144.  
  145.                                         } catch (IOException e1) {
  146.                                                 e1.printStackTrace();
  147.                                         } catch (Exception e1) {
  148.                                                 e1.printStackTrace();
  149.                                         }
  150.  
  151.                                         System.out.println("访问次数:" + go);
  152.                                         iP.append("访问次数:" + go + "\n");// 输出到前端
  153.                                         go++;// 计数器累加记录访问次数
  154.  
  155.                                         try {
  156.                                                 Thread.sleep(times);// 线程休息
  157.  
  158.                                                 String[] cmd = { "tskill iexplore", "tskill chrome",
  159.                                                                 "tskill sogouexplorer", "tskill The world",
  160.                                                                 "tskill Firefox", "tskill opera",
  161.                                                                 "tskill 360SE", "tskill Safari",
  162.                                                                 "tskill Maxthon" };
  163.                                                 Process p;
  164.  
  165.                                                 // String command = "tskill iexplore";// 想DOS传入命令字符
  166.                                                 // " ntsd -c q -p ";
  167.                                                 // 循环执行DOS命令
  168.                                                 for (int i = 0; i < cmd.length; i++) {
  169.  
  170.                                                         p = Runtime.getRuntime().exec("cmd /c" + cmd[i]);
  171.  
  172.                                                         InputStream in = p.getInputStream();
  173.                                                         BufferedReader inr = new BufferedReader(
  174.                                                                         new InputStreamReader(in, "utf-8"));
  175.                                                         String line = null;
  176.                                                         while ((line = inr.readLine()) != null) {
  177.                                                                 System.out.println(line);
  178.                                                         }
  179.  
  180.                                                         p.waitFor();
  181.                                                         System.out.println("DOS:" + i);
  182.                                                 }
  183.  
  184.                                                 // 初始化DOS方法
  185.                                                 // 加载命令行
  186.                                                 // 判断反问次数是否到达设置次数,如果达到则结束程序
  187.  
  188.                                         } catch (InterruptedException e) {
  189.                                                 // TODO Auto-generated catch block
  190.                                                 e.printStackTrace();
  191.                                         } catch (Exception e) {
  192.                                                 // TODO Auto-generated catch block
  193.                                                 e.printStackTrace();
  194.                                         }
  195.  
  196.                                         if (go > m) {
  197.                                                 iP.append("程序执行结束!!!");
  198.                                                 System.out.println("程序执行结束!!!");
  199.                                                 break;
  200.                                         }
  201.  
  202.                                 }
  203.  
  204.                         } else {
  205.                                 iP.append("对不起!你输入的参数不正确!!");
  206.                         }
  207.                 }
  208.  
  209.                 if (arg0.getSource() == end) {
  210.  
  211.                         System.exit(0);
  212.                 }
  213.  
  214.         }
  215.  
  216.         public void windowActivated(WindowEvent arg0) {
  217.  
  218.         }
  219.  
  220.         public void windowClosed(WindowEvent arg0) {
  221.  
  222.                 System.exit(0);
  223.  
  224.         }
  225.  
  226.         public void windowClosing(WindowEvent arg0) {
  227.  
  228.                 System.exit(0);
  229.  
  230.         }
  231.  
  232.         public void windowDeactivated(WindowEvent arg0) {
  233.  
  234.         }
  235.  
  236.         public void windowDeiconified(WindowEvent arg0) {
  237.  
  238.         }
  239.  
  240.         public void windowIconified(WindowEvent arg0) {
  241.  
  242.         }
  243.  
  244.         public void windowOpened(WindowEvent arg0) {
  245.  
  246.         }
  247.  
  248.         public static void main(String[] args) {
  249.                 // TODO Auto-generated method stub
  250.                 Boxx b = new Boxx();
  251.                 b.run();
  252.         }
  253.  
  254. }
  255.  

回复 "刷网站访问量 刷网站PV浏览量"

这儿你可以回复上面这条便签

captcha