今天交了网费,两天没网上的日子结束了 ^_^。不过心痛,120大洋没了。
//
设计用户输入界面,获取网址采集规则.
package
test1;
import
java.awt.
*
;
import
javax.swing.
*
;
import
java.awt.event.
*
;
import
java.io.
*
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
public
class
GetUrl
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
String ruleName="测试文件名";
String webAddress=null;
String StringInList=null ;//网址列表中需要包含的字符串
String StringNotInList=null;//网址列表中不能包含的字符串
String ListAreaBegin=null;//网址列表所在区域的开始字符串
String ListAreaEnd=null;//网址列表中所在区域的结束字符串
public void go()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
JFrame jf1=new JFrame("网站信息采集管理系统");
jf1.setBackground(new Color(71,98,172));
JPanel jp1=new JPanel();
jp1.setBackground(new Color(135,220,255));
JPanel jp2=new JPanel();
JPanel jp3=new JPanel();
jf1.getContentPane().add(jp1,BorderLayout.NORTH);
jf1.getContentPane().add(jp2,BorderLayout.CENTER);
GridLayout gdForJp1=new GridLayout(3,3);
//gdForJp1.setHgap(10);
//gdForJp1.setVgap(10);
jp1.setLayout(gdForJp1);
jp1.add(new Label("请输入网站网址"));
final TextField tf1=new TextField();
jp1.add(tf1);
jp1.add(new Label("请输入开始字符串"));
final TextField tf2=new TextField ();
jp1.add(tf2);
jp1.add(new Label("请输入结束字符串"));
final TextField tf3=new TextField ();
jp1.add(tf3);
jp1.add(new Label("网址中应包含字符串"));
final TextField tf4=new TextField ();
jp1.add(tf4);
jp1.add(new Label("网址中不能包含的字符串"));
final TextField tf5=new TextField ();
jp1.add(tf5);
final TextArea ta=new TextArea(20,100);
Button bt1=new Button("确定");
bt1.setBackground(Color.pink);
jp3.add(bt1);
Button bt2=new Button("清空内容");
jp3.add(bt2);
Button bt3=new Button("存储规则");
jp3.add(bt3);
jp3.setBackground(new Color(209,173,159));
jf1.add(jp3,BorderLayout.SOUTH);
//jf1.getContentPane().add(bt1,BorderLayout.SOUTH);
//确定按钮事件
class ButtonHandle1 implements ActionListener
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
public void actionPerformed(ActionEvent e)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
GetUrl.this.webAddress=tf1.getText();
GetUrl.this.ListAreaBegin=tf2.getText();
GetUrl.this.ListAreaEnd=tf3.getText();
GetUrl.this.StringInList=tf4.getText();
GetUrl.this.StringNotInList=tf5.getText();
ta.append(GetUrl.this.webAddress+" ");
ta.append(GetUrl.this.ListAreaBegin+" ");
ta.append(GetUrl.this.ListAreaEnd+" ");
ta.append(GetUrl.this.StringInList+" ");
ta.append(GetUrl.this.StringNotInList+" ");
ta.append("文本长度:"+ta.getText().length()+" ");
ta.append("信息来源:程序人生博客http://blog.csdn.net/zhuche110/ ");
System.out.println(GetUrl.this.webAddress);
}
}
//清空内容事件
class ButtonHandle2 implements ActionListener
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
public void actionPerformed(ActionEvent e)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
ta.replaceRange("", 0, ta.getText().length()) ;
}
}
//存储规则事件
class ButtonHandle3 implements ActionListener
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
public void actionPerformed(ActionEvent e)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
FileOutputStream fos=new FileOutputStream("测试文件名.txt");
OutputStreamWriter osw=new OutputStreamWriter(fos);
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
/**//*
String s= "ruleName="+GetUrl.this.ruleName+" "
+"webAddress="+GetUrl.this.webAddress+" "
+"ListAreaBegin="+GetUrl.this.ListAreaBegin+" "
+"ListAreaEnd="+GetUrl.this.ListAreaEnd+" "
+"StringInList="+GetUrl.this.StringInList+" "
+"StringNotInList="+GetUrl.this.StringNotInList+" ";
*/
String s="www.baidu.com";
osw.write(s);
//ta.append(s);
}
catch(FileNotFoundException f)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
System.out.println("无法找到文件");
}
catch(IOException f)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
f.printStackTrace();
}
}
}
bt1.addActionListener(new ButtonHandle1());
bt2.addActionListener(new ButtonHandle2());
bt3.addActionListener(new ButtonHandle3());
jp2.add(ta);
jf1.setSize(800, 600);
jf1.setLocation(100,100);
jf1.setVisible(true);
}
public static void main(String[] args)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
GetUrl geturl=new GetUrl();
geturl.go();
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
输出为![](https://p-blog.csdn.net/images/p_blog_csdn_net/zhuche110/1-jg-12.jpg)