利用JAVA获取网上信息

本文介绍了一个使用Java实现的简单GUI应用程序案例,该程序通过Swing或AWT创建了一个带有文本区域和按钮的基本窗口,演示了如何响应按钮点击事件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> import java.io.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.net.URL; import java.net.*; class win extends Frame implements ActionListener { TextArea text; TextArea text2=new TextArea();; String url; Panel panel; int ite=0; TextField qihao; TextArea text1=new TextArea(); Button button1; BufferedWriter out; String txt; StringBuffer sb; StringBuffer s2=new StringBuffer(); win() { super("test!"); setLayout(new BorderLayout()); setBackground(Color.cyan); setBounds(150,150,300,120); setVisible(true); text=new TextArea(); button1=new Button("确定"); qihao=new TextField(16); panel=new Panel(); panel.add(qihao); panel.add(button1); add("North",panel); add(text,"Center"); button1.addActionListener(this); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { setVisible(false); System.exit(0); } }); }public void actionPerformed(ActionEvent e) { if(e.getSource()==button1) { System.out.println("beginning!"); int hao=new Integer(qihao.getText().trim()).intValue(); for(int j=1;j<=10;j ){ for(int i=1;i<=1000;i ) { try{ Reder(hao); }catch(Exception er){} hao=hao 1; txt=text1.getText(); try{ txt=getStrings(txt); }catch(Exception er){} text2.append(txt "/n"); text1.setText(""); System.out.println(i); } txt=text2.getText(); text2.setText(""); try{ out=new BufferedWriter(new FileWriter(hao ".txt")); }catch(FileNotFoundException p){} catch(IOException exp){} try{ out.write(txt,0,txt.length()); out.flush(); }catch(IOException exp){} txt=""; } System.out.println("finished!"); } } public String getStrings(String s1) throws Exception { StringBuffer sb; sb=new StringBuffer(s1); while(sb.indexOf("<")!=-1) { int lt=sb.indexOf("<"); int rt=sb.indexOf(">"); if(lt>=rt 1) break; sb=sb.delete(lt,rt 1); } return sb.toString(); } public void Reder(int hao) throws Exception { URL yahoo = new URL("http://app.china.com/business/enp/shwnew.php?enpid=" hao); DataInputStream in = new DataInputStream(yahoo.openStream()); BufferedReader d= new BufferedReader(new InputStreamReader(in)); String inputLine; for(int j=1;j<=121;j ) { inputLine = d.readLine().trim(); } for(int j=1;j<=40;j ) { inputLine = d.readLine().trim(); text1.append(inputLine); } text1.append("/n"); in.close(); } } //-------------------------------- public class AcceptData { public static void main(String args[]) { win window=new win(); window.pack(); } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值