?? updater.java
字號:
/*
* ContentAdapter.java
* Download by http://www.codefans.net
* Created on 2007年9月1日, 上午8:52
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package weather;
import java.util.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
import java.net.*;
import java.awt.event.*;
import java.awt.image.*;
/**
*
* @author yuhui_bear
*/
public class Updater extends Thread{
private WebFilter web;
private Map<String,String> forecast;
private mainFrame mf;
private String url;
private String oCity;
private JProgressBar jpb;
private JTabbedPane jtp;
/** Creates a new instance of ContentAdapter */
public Updater(String name ,Map<String,String> fc_in , mainFrame frame , String place , JProgressBar jpbin ,JTabbedPane jtpin) {
super(name);
jpb = jpbin;
jtp = jtpin;
oCity = place;
url = setUrl(oCity);
web=new WebFilter( url,"src");
forecast = fc_in;
mf = frame;
this.setDaemon(true);
this.setPriority(Thread.MIN_PRIORITY);
jpb.setVisible(true);
this.start();
}
public void run() {
for(int i =0;i<1;i++){
getWebFailed:
try{web.getData();
}catch (UnknownHostException ex2){
new AboutJD (mf ,"網絡不通!" , "老大, 網線是不是被人家做掉了?","\t網絡故障,可能你的網絡不通,請檢查."
,new ImageIcon(mainFrame.class.getResource("crazy.gif")));
break getWebFailed;
}catch (SocketTimeoutException stoute){
new AboutJD (mf ,"網速太慢!" , "老大, 銀太多了(東北口音),偶擠不出去啊!"
,"可能你的帶寬過于擁擠,啟兒天氣 暫時無法獲得足夠帶寬!\n請調節帶寬或者稍候重試."
,new ImageIcon(mainFrame.class.getResource("sad.gif")));
}catch(IOException ex){
try {
this.sleep(8000);
web.getData();
} catch(IOException ioe){
break;
}catch (InterruptedException exi) {
System.err.println("網絡連接時出現嚴重錯誤!!!");
break;
}
}
sendData();
mf.dataUpdate();
saveCity();
jpb.setVisible(false);
jtp.setEnabledAt(0,true);
jtp.setEnabledAt(1,true);
jtp.setSelectedIndex(0);
}
}
private void saveCity(){
try {
RandomAccessFile out = new RandomAccessFile(new File(".\\","city.txt") ,"rw");
out.writeUTF(oCity);
out.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex){
ex.printStackTrace();
}
}
private synchronized void sendData(){
web.adapted(forecast);
}
private String setUrl(String str){
try {
// String tt = URLEncoder.encode("成都","GBK");
return "http://weather.tq121.com.cn/detail.php?city="+URLEncoder.encode(str , "GBK")+"&submit=%B3%C7%CA%D0%CB%D1%CB%F7";
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
return "http://weather.tq121.com.cn/detail.php?city=%B3%C9%B6%BC&submit=%B3%C7%CA%D0%CB%D1%CB%F7";
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -