GUI小程序

来源:互联网 发布:库控制软件 编辑:程序博客网 时间:2024/05/29 12:13
考试周,受学长委托,帮他写了个很水很水,水到要死的抓取网站title标签的GUI。。。。。
据说他是用来测试他的某个算法的。。。哎~去过阿里的人就不是不一样啊- - 动不动就云计算什么的。。。
不过有由于时间外加能力有限,在奋战了1个多小时后,我最终决定终止这场没有“意义”的编程。。(其实我是想赶紧预习离散的。。。。)
然后淡定的拿起了60+页的离散数学题库,开始刷题。。。。
好吧。。。
话说因为能力有限,我只能水过这个抓title的任务。

不过程序发过去还是得到学长的认可的。。。

import java.awt.*;import java.awt.event.*;import java.net.*;import java.io.*;class GetT extends Frame {    Button btn, res;    TextArea tf;    TextArea st;    GetT() {        super("Get the title!!!");        btn = new Button("get");        res = new Button("reset");        tf = new TextArea(30, 70);        st = new TextArea(30, 70);        add(tf);        add(btn);        add(res);        add(st);        btn.addActionListener(new Mint());        res.addActionListener(new Mint2());        addWindowListener(new WindowAdapter() {            public void windowClosing(WindowEvent e) {                System.exit(0);            }        });        setLayout(new FlowLayout());        setVisible(true);        setSize(1300, 600);    }    class Mint2 implements ActionListener {        public void actionPerformed(ActionEvent arg0) {            tf.setText("");            st.setText("");        }    }    class Mint implements ActionListener {        public void actionPerformed(ActionEvent e) {            String stt = new String("http://detail.china.alibaba.com/buyer/offerdetail/");            String stc;            String s[] = tf.getText().split("\n");            for (int i = 0; i < s.length; i++) {                String ss[] = s[i].split("\5");                if (Double.valueOf(ss[3]) > 10) {                    continue;                }                st.append(ss[1] + "         |" + ss[3] + "|        ");                String str = stt + ss[1] + ".html";                try {                    URL u = new URL(str);                    BufferedReader buf = new BufferedReader(new InputStreamReader(u.openStream()));                    int tt;                    while ((str = buf.readLine()) != null) {                        int flag = 0;                        stc = str.trim();                        char cc[] = stc.toCharArray();                        for (tt = 0; tt + 3 < stc.length(); tt++) {                            if (cc[tt] == '<' && cc[tt + 1] == 't' && cc[tt + 2] == 'i' && cc[tt + 3] == 't') {                                flag = 1;                            }                        }                        if (flag == 1) {                            break;                        }                    }                    st.append(str.substring(9) + "\n");                } catch (Exception e1) {                }            }        }    }}public class Main {    public static void main(String[] args) {        new GetT();    }}


原创粉丝点击