javafx做的天气预报小程序:

数据来源于中央天象台提供的api 。处理的是Json数据,可以播报6天的天气。

天气的数据来源中央气象台. http://m.weather.com.cn/data/101200101.html 其中 101200101 为武汉的城市代码。通过这个网站获取json数据,然后解析json数据,提取相应的天气信息。

1. 软件只添加了几个城市,大家如果有好的方法能够将全国的城市(精确到县一级)都添加进去,希望提提意见。将全国的城市代码都加到CityList.XML文件中不是个好方法......

2. 另外,通过ip显示当前城市,然后显示当前城市的天气这个时灵时不灵(可能是我这网络的原因,获取ip的网站有时不能访问)。通过访问网站 http://61.4.185.48:81/g/ 得到本机访问的IP,根据此IP查询到城市ID。

效果图:

Json数据解析代码:

public Weather(String Cityid) throws IOException, NullPointerException {// 解析本机ip地址this.Ctiyid = Cityid;// 连接中央气象台的APIURL url = new URL("http://m.weather.com.cn/data/" + Ctiyid + ".html");connectionData = url.openConnection();connectionData.setConnectTimeout(1000);try {br = new BufferedReader(new InputStreamReader(connectionData.getInputStream(), "UTF-8"));sb = new StringBuilder();String line = null;while ((line = br.readLine()) != null)sb.append(line);} catch (SocketTimeoutException e) {System.out.println("亲,网络没有连接");} catch (FileNotFoundException e) {System.out.println("亲,网络没有连接");}jsonData = JSONObject.fromObject(sb.toString());weatherinfo = jsonData.getJSONObject("weatherinfo");// 设置第一页吗的城市名称 日期city = weatherinfo.getString("city").toString();week = weatherinfo.getString("week").toString();date_y = weatherinfo.getString("date_y").toString();fchh = weatherinfo.getString("fchh").toString();// 1到6天的天气weather1 = weatherinfo.getString("weather1").toString();weather2 = weatherinfo.getString("weather2").toString();weather3 = weatherinfo.getString("weather3").toString();weather4 = weatherinfo.getString("weather4").toString();weather5 = weatherinfo.getString("weather5").toString();weather6 = weatherinfo.getString("weather6").toString();// 1到6天的气温temp1 = weatherinfo.getString("temp1").toString();temp2 = weatherinfo.getString("temp2").toString();temp3 = weatherinfo.getString("temp3").toString();temp4 = weatherinfo.getString("temp4").toString();temp5 = weatherinfo.getString("temp5").toString();temp6 = weatherinfo.getString("temp6").toString();// 1到6天的风况wind1 = weatherinfo.getString("wind1").toString();wind2 = weatherinfo.getString("wind2").toString();wind3 = weatherinfo.getString("wind3").toString();wind4 = weatherinfo.getString("wind4").toString();wind5 = weatherinfo.getString("wind5").toString();wind6 = weatherinfo.getString("wind6").toString();// 1到6天的风速fl1 = weatherinfo.getString("fl1").toString();fl2 = weatherinfo.getString("fl2").toString();fl3 = weatherinfo.getString("fl3").toString();fl4 = weatherinfo.getString("fl4").toString();fl5 = weatherinfo.getString("fl5").toString();fl6 = weatherinfo.getString("fl6").toString();// 各种天气指数index = weatherinfo.getString("index").toString();index_uv = weatherinfo.getString("index_uv").toString();index_tr = weatherinfo.getString("index_tr").toString();index_co = weatherinfo.getString("index_co").toString();index_cl = weatherinfo.getString("index_cl").toString();index_xc = weatherinfo.getString("index_xc").toString();index_d = weatherinfo.getString("index_d").toString();// 天气情况的图片img_title1 = weatherinfo.getString("img_title1").toString();img_title2 = weatherinfo.getString("img_title2").toString();img_title3 = weatherinfo.getString("img_title3").toString();img_title4 = weatherinfo.getString("img_title4").toString();img_title5 = weatherinfo.getString("img_title5").toString();img_title6 = weatherinfo.getString("img_title6").toString();img_title7 = weatherinfo.getString("img_title7").toString();img_title8 = weatherinfo.getString("img_title8").toString();img_title9 = weatherinfo.getString("img_title9").toString();img_title10 = weatherinfo.getString("img_title10").toString();img_title11 = weatherinfo.getString("img_title11").toString();img_title12 = weatherinfo.getString("img_title12").toString();}

源码下载

所需jar包列表:

commons-beanutils.jar

commons-collections-3.0.jar

commons-logging.jar

commons-lang-2.1.jar

json-lib-1.1-jdk13.jar

ezmorph-1.0.2.jar

转载于:https://www.cnblogs.com/javafx/archive/2013/03/26/2982487.html

javafx做的天气预报小程序相关推荐

  1. 微信小程序开发--利用和风天气API实现天气预报小程序

    本来是参照<微信小程序开发实战>做一个天气预报小程序的,实际运行的时候提示错误,code 400,参数错误.说明问题应该出在查询API的语句上,没有返回结果. 查阅后才知道,可能书籍出版时 ...

  2. 使用微搭搭建天气预报小程序

    1 小程序简介 日常我们在使用手机的时候,查看最近的天气是比较常见的需求,那可不可以做一款小程序来显示最近七天的天气呢?答案是肯定的,利用微搭提供的外部数据源我们就可以方便的获取互联网公开的天气预报的 ...

  3. android更新天气简单方法,简单教你如何编写Android天气预报小程序

    现在很多智能手机上都有实现天气预报这个功能,基本上是出门必备看的一个小程序,那么我们是怎么实现这个小程序的呢,那么本文来讲讲在Android系统上的天气预报的小程序. 研究<精通Android ...

  4. 微信天气预报小程序实战开发视频教程

    此教程属于开发实战系列视频教程,基于之前发布的 「60 集微信小程序开发视频教程」,更新的第二阶段视频课程. 此系列课程将直接进入实战开发部分. 此系列视频课程包含: 项目初始化 页面 UI 开发 页 ...

  5. 《我也能做CTO之程序员职业规划》写作过程重播之二

    又过一个月,写作仍在继续,评论也不停-- 2008-12-19 7:25:14 ξ箫音ξ 接收文件成功,保存于C:\Documents and Settings\dragon\桌面\我也能做CTO之. ...

  6. 程序员的杂想-不要只做一名程序员

    从一次进食堂吃饭感想:食堂运营模式一般有两种: 多个窗口,每个窗口有一位负责打菜 结账: 流水线: 到底哪种方式更好呢?作为程序员,首先想到的是吞吐量:怎么算呢?是以单位出队人次 还是以 工作人员单位 ...

  7. python恶搞-python—做一个恶搞程序

    python-做一个恶搞程序 very easy print("You can't win this game") #你不可能赢这个游戏 n = int(input("B ...

  8. 谈谈环保问题之四-做环保的程序员

    一直想谈谈节制这个问题,俏皮一点来讲,我们要做环保的程序员. 记得大学一年级那会,学校的政策是不让学生用电脑,良苦用心怕我们沉迷网络,考不过英语四级.也怪当时的手机还不是智能机,个别能上WAP的也是慢 ...

  9. 到底能不能做一辈子的程序员——大龄程序员将何去何从

    目录 写在前面 做一辈子的技术到底好不好 迷茫 求大佬指点迷津 写在前面 今天面试一家银行科技部被拒绝了,原因并不是因为自己的技术烂,而是因为-- 自己缺乏银行从业经验. 做java开发快三年了,看过 ...

最新文章

  1. Android Intent的 Component 使用
  2. 2015年蓝汛面试题
  3. Python基本语法元素之温度转换
  4. pygame的一个小问题,未解决
  5. 树莓派C语言点灯,树莓派3 b GPIO 点亮小灯泡
  6. 外模告急时薪翻倍?中国AI虚拟模特取代高价外模,效果逼真与真人无异。
  7. 诺基亚的「翻身」之战
  8. USD MID-160|全球最薄的MID!
  9. 《The Django Book》笔记(未完结)
  10. win10系统设置插入鼠标禁用触控板的方法
  11. 三天晚上看了24集 央视版《神雕侠侣》 还不错
  12. (已解决)win10重装后无法开启双显示屏
  13. 设计表:多张表存储学生成绩及各种信息
  14. 《开源软件开发导论》作业1
  15. LDP协议的相关内容
  16. 【AIOT】语音学习
  17. Argo workflow 入门
  18. CET-4 week8# 细枝末节
  19. android 自定义ViewGroup实现仿淘宝的商品详情页
  20. 十年前只想混一个Apache邮箱装逼,十年后却成了顶级项目创始人

热门文章

  1. NeurIPS 2020 | 微软亚研院论文摘录之强化学习GAN篇
  2. 3D深度估计,让视频特效更梦幻!
  3. 超Mask RCNN速度4倍,仅在单个GPU训练的实时实例分割算法
  4. 重磅!清华商汤开源CVPR2018超高精度人脸对齐算法LAB
  5. 综述 | 深度学习弱目标检测定位
  6. Pygal简单使用——模拟掷骰子
  7. 全局路径规划:图搜索算法介绍3(A stars tie breaker)
  8. java adt is保存快捷键_ADT - Eclipse 常用快捷键
  9. ionic android绝对定位,Safari中的CSS故障与Ionicons作为背景内容和绝对定位
  10. java checkproperties(this)_【转载】java读取.properties配置文件的几种方法