⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 weatherdialog.java~11~

📁 有关天气的
💻 JAVA~11~
字号:
package com.hzcc.weather;

import javax.swing.*;
import java.io.*;
import java.net.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class WeatherDialog {
  String city;
  String weather;

  //构造
  public WeatherDialog(String city) {
    this.city = city;
  }

  public String getWeather() {
    String strWeather = "";
    try {
      //从新浪网天气频道取各地天气.要是有web service就更好了.
      URL url = new URL(
          "http://weather.news.sina.com.cn//cgi-bin/figureWeather/simpleSearch.cgi?city=" +
          city);
      BufferedReader in = new BufferedReader(new InputStreamReader(url.
          openStream()));
      String inputLine;
      String temp = "";

      while ( (inputLine = in.readLine()) != null) {
        //注意.每行结束要加分行符号
        temp = temp + inputLine + "\n";
      }
      strWeather = temp.substring(temp.indexOf("<body"),
                                  temp.lastIndexOf("table>") + 5) + "\n</body>";
      return strWeather;

    }
    catch (Exception e) {
      System.out.println(e);
    }
    return strWeather;

  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -