📄 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 + -