package jschrj.lyf;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.PrintStream;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;
import jschrj.spider.SpiderTool;
import jschrj.widget.ConsoleTextArea;
import javax.swing.JTextPane;
import java.awt.ScrollPane;
import java.awt.TextArea;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import java.awt.Window.Type;
import java.awt.Component;
/**
* 程序 入口
* @author lyf 2018/07/09
*/
public class Spider extends JFrame {
private JPanel contentPane;
private JTextField txtUrl;
private JTextField txtListRule;
private JTextField txtPageRule;
private JTextField txtDtxt;
private JTextField txtThreadNum;
private ConsoleTextArea textArea_1 = null;
private JTextArea txtContent;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Spider frame = new Spider();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Spider() {
setResizable(false);
setTitle("爬虫工具");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(400, 100, 650, 620);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
JLabel lblNewLabel = new JLabel("抓取地址");
lblNewLabel.setFont(new Font("黑体", Font.PLAIN, 16));
JLabel lblNewLabel_1 = new JLabel("列表规则");
lblNewLabel_1.setFont(new Font("黑体", Font.PLAIN, 16));
JLabel label = new JLabel("页面规则");
label.setFont(new Font("黑体", Font.PLAIN, 16));
JLabel label_1 = new JLabel("抓取内容");
label_1.setFont(new Font("黑体", Font.PLAIN, 16));
JScrollPane scrollPane = new JScrollPane();
JScrollPane scrollPane_2 = new JScrollPane();
txtUrl = new JTextField();
txtUrl.setFont(new Font("黑体", Font.PLAIN, 12));
txtUrl.setText("http://bbs.huainet.com/forum.php");
txtUrl.setColumns(10);
txtListRule = new JTextField();
txtListRule.setFont(new Font("黑体", Font.PLAIN, 12));
txtListRule.setText("http://bbs.huainet.com/forum-[0-9]{1,3}-[0-9]{1,3}.html");
txtListRule.setColumns(10);
txtPageRule = new JTextField();
txtPageRule.setFont(new Font("黑体", Font.PLAIN, 12));
txtPageRule.setText("http://bbs.huainet.com/thread-[0-9]{1,12}-1-[0-9]{1,9}.html");
txtPageRule.setColumns(10);
JLabel lblNewLabel_2 = new JLabel("存放地址");
lblNewLabel_2.setFont(new Font("黑体", Font.PLAIN, 16));
txtDtxt = new JTextField();
txtDtxt.setFont(new Font("黑体", Font.PLAIN, 12));
txtDtxt.setText("D:\\淮水安澜.txt");
txtDtxt.setColumns(10);
JButton btnStart = new JButton("开始");
btnStart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String url = txtUrl.getText();
String txtpath = txtDtxt.getText();
String listRule = txtListRule.getText();
String pageRule = txtPageRule.getText();
String content = txtContent.getText();
String num = txtThreadNum.getText();
SpiderTool.start(url,txtpath,listRule,pageRule,content,num);
// JOptionPane.showMessageDialog(null, "瞎点啥!", "标题", JOptionPane.WARNING_MESSAGE);
}
});
btnStart.setFont(new Font("黑体", Font.PLAIN, 16));
JLabel label_2 = new JLabel("线程数");
label_2.setFont(new Font("黑体", Font.PLAIN, 16));
txtThreadNum = new JTextField();
txtThreadNum.setFont(new Font("黑体", Font.PLAIN, 12));
txtThreadNum.setText("4");
txtThreadNum.setColumns(10);
JButton btnPause = new JButton("暂停");
btnPause.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SpiderTool.stop();
}
});
btnPause.setFont(new Font("黑体", Font.PLAIN, 16));
JButton btnContinue = new JButton("继续");
btnContinue.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SpiderTool.restart();
}
});
btnContinue.setFont(new Font("黑体", Font.PLAIN, 16));
JButton btnClear = new JButton("清空");
btnClear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textArea_1.setText("");
}
});
btnClear.setFont(new Font("黑体", Font.PLAIN, 16));
JScrollPane scrollPane_1 = new JScrollPane();
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(19)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(scrollPane_2, GroupLayout.PREFERRED_SIZE, 590, GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(gl_contentPane.createSequentialGroup()
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addComponent(label_2)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(lblNewLabel)
.addComponent(lblNewLabel_1)
.addComponent(label)
.addComponent(label_1)
.addComponent(lblNewLabel_2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGap(21)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(txtThreadNum, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addComponent(btnStart)
.addGap(9)
.addComponent(btnPause)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(btnContinue)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(btnClear)
.addContainerGap())
.addComponent(scrollPane, Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addComponent(txtListRule, 504, 504, Short.MAX_VALUE)
.addComponent(txtUrl, 504, 504, Short.MAX_VALUE)
.addComponent(txtPageRule, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 504, Short.MAX_VALUE)
.addComponent(scrollPane_1, GroupLayout.DEFAULT_SIZE, 504, Short.MAX_VALUE)
.addComponent(txtDtxt, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 504, Short.MAX_VALUE))
.addGap(237))))))
);
gl_contentPane.setVerticalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(28)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel)
.addComponent(txtUrl, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.UNRELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_1)
.addComponent(txtListRule, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(Componen