?? weather.java
字號:
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.util.regex.*;
public class Weather extends Frame {
/**
*
*/
private static final long serialVersionUID = -6280689436434350053L;
private String result11="";
private String str="";
private String s="";
private String result1="";
private String result2="";
private Label text=new Label("網址");
private TextField address=new TextField("http://www.dlqx.gov.cn",20);
private TextArea content1=new TextArea(12,12);
private TextArea content2=new TextArea(12,12);
private Button ok=new Button("確定");
private Frame f=new Frame("Weather");
private Panel p=new Panel();
private URL url=null;
public Weather() {
f.setSize(400,400);
p.add(text,"West");
p.add(address,"Center");
p.add(ok,"East");
f.add(p,"North");
f.add(content1,"Center");
f.add(content2,"South");
f.setVisible(true);
ok.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
s=address.getText().trim();
//System.out.println(s);
try{
url=new URL(s);
content1.setText(null);
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
while((str=in.readLine())!=null) {content1.append(str);content1.append("\r"+"\n");}
in.close();
}
catch(Exception ee) {ee.printStackTrace();}
result1=content1.getText().trim();
result11=result1.replaceAll("<br>","\r"+"\n");
result11=result11.replaceAll(" "," ");
Pattern p;
Matcher m;
p=Pattern.compile("大連市氣象臺\\d{1,2}月\\d{1,2}日.*℃");
m=p.matcher(content1.getText().trim());
while(m.find())
{
result2=m.group();
result2=result2.replaceAll("<br>","\r"+"\n");
result2=result2.replaceAll(" "," ");
}
//result2=result111.substring(22056,22161);
content2.setText(result2);
}
});
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
}
public static void main(String args[]) {
new Weather();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -