,移动开发   工具软件   办公软件   操作系统   网络安全   设计在线   程序开发   教程宝典   软件下载   软件论坛,移动开发
您的位置:软件 > 开发者网络 > 开发工具 > 移动开发 > 正文
SmartPhone手机上查看QQ天气预报
[文章信息]
作者:贺星河
时间:2005-04-26
出处:天极网
责任编辑:方舟
[文章导读]
利用QQ提供的免费天气预报服务,将其包装部署为一个Web服务,并编写程序使智能手机能使用这个服务
advertisement
热点推荐
· 深入探讨SQL Server 2000对XML的支持
· Swing(空)
· 3DS Stodio Max 宝典
· 中小企业服务器配置方案--前 言
· 中小企业服务器配置方案--代理接入服务器(3)
[正文]

上一页  1 2 3 4  下一页

  三、新建手机应用程序项目

  1、新建一个智能设备应用程序,在主面板上拖放如图2所示的几个控件,其中timer是用来检查是否数据已经下载完毕的。


图1-新建智能设备应用程序


图2-界面设计


  2、引用建好的WebService


图3-引用WebService

  3、WeatherService智能手机上运行的程序源代码

using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;

namespace WeatherService
{
 /// <summary>
 /// Summary description for MainForm.
 /// </summary>

 public class MainForm : System.Windows.Forms.Form
 {
  private System.Windows.Forms.ComboBox comboBox_City;
  private System.Windows.Forms.MenuItem menuItem1;
  private System.Windows.Forms.Label txt_Weather1;
  private System.Windows.Forms.Label txt_Date1;
  private System.Windows.Forms.Label txt_Temp1;
  private System.Windows.Forms.Label txt_WindPower1;
  private System.Windows.Forms.Label txt_Temp2;
  private System.Windows.Forms.Label txt_WindPower2;
  private System.Windows.Forms.Label txt_Date2;
  private System.Windows.Forms.Label txt_Weather2;
  private System.Windows.Forms.MainMenu mainMenu1;
  private System.Windows.Forms.MenuItem menuItem_Menu;
  private System.Windows.Forms.MenuItem menuItem_Exit;
  private System.Windows.Forms.Label label_City;
  private System.Windows.Forms.Timer timer1;
  private System.Windows.Forms.MenuItem menuItem2;
  private System.Windows.Forms.MenuItem menuItem3;

  public string[] cityList = new string[]
  {
   "北京",
   "上海",
   "天津",
   "石家庄",
   "哈尔滨",
   "沈阳",
   "长春",
   "太原",
   "济南",
   "郑州",
   "天津",
   "呼和浩特",
   "西安",
   "银川",
   "兰州",
   "西宁",
   "乌鲁木齐",
   "合肥",
   "南昌",
   "南京",
   "杭州",
   "武汉",
   "长沙",
   "广州",
   "深圳",
   "福州",
   "厦门",
   "南宁",
   "桂林",
   "海口",
   "重庆",
   "成都",
   "贵阳",
   "昆明",
   "拉萨",
   "香港",
   "澳门",
   "台北",
  };

  public MainForm()
  {
   InitializeComponent();
   foreach( string x in cityList)
   {
    this.comboBox_City.Items.Add(x);
   }

   this.comboBox_City.SelectedIndex = 0;
  }

  /// <summary>
  /// Clean up any resources being used.
  /// </summary>

  protected override void Dispose( bool disposing )
  {
   base.Dispose( disposing );
  }

  #region Windows Form Designer generated code

  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>

  private void InitializeComponent()
  {
   this.mainMenu1 = new System.Windows.Forms.MainMenu();
   this.menuItem1 = new System.Windows.Forms.MenuItem();
   this.menuItem_Menu = new System.Windows.Forms.MenuItem();
   this.menuItem_Exit = new System.Windows.Forms.MenuItem();
   this.menuItem3 = new System.Windows.Forms.MenuItem();
   this.menuItem2 = new System.Windows.Forms.MenuItem();
   this.comboBox_City = new System.Windows.Forms.ComboBox();
   this.label_City = new System.Windows.Forms.Label();
   this.txt_Weather1 = new System.Windows.Forms.Label();
   this.txt_Date1 = new System.Windows.Forms.Label();
   this.txt_Temp1 = new System.Windows.Forms.Label();
   this.txt_WindPower1 = new System.Windows.Forms.Label();
   this.txt_Temp2 = new System.Windows.Forms.Label();
   this.txt_WindPower2 = new System.Windows.Forms.Label();
   this.txt_Date2 = new System.Windows.Forms.Label();
   this.txt_Weather2 = new System.Windows.Forms.Label();
   this.timer1 = new System.Windows.Forms.Timer();

   //
   // mainMenu1
   //

   this.mainMenu1.MenuItems.Add(this.menuItem1);
   this.mainMenu1.MenuItems.Add(this.menuItem_Menu);
   //
   // menuItem1
   //

   this.menuItem1.Text = "确定";
   this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);

   //
   // menuItem_Menu
   //

   this.menuItem_Menu.MenuItems.Add(this.menuItem_Exit);
   this.menuItem_Menu.MenuItems.Add(this.menuItem3);
   this.menuItem_Menu.MenuItems.Add(this.menuItem2);
   this.menuItem_Menu.Text = "菜单";

   //
   // menuItem_Exit
   //

   this.menuItem_Exit.Text = "退出";
   this.menuItem_Exit.Click += new System.EventHandler(this.menuItem_Exit_Click);

   //
   // menuItem3
   //

   this.menuItem3.Text = "-";

   //
   // menuItem2
   //

   this.menuItem2.Text = "关于";
   this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);

   //
   // comboBox_City
   //

   this.comboBox_City.Font = new System.Drawing.Font("Nina", 9F, System.Drawing.FontStyle.Regular);
   this.comboBox_City.Location = new System.Drawing.Point(52, 8);
   this.comboBox_City.Size = new System.Drawing.Size(114, 22);

   //
   // label_City
   //

   this.label_City.Font = new System.Drawing.Font("Nina", 9F, System.Drawing.FontStyle.Bold);
   this.label_City.Location = new System.Drawing.Point(4, 12);
   this.label_City.Size = new System.Drawing.Size(52, 16);
   this.label_City.Text = "城市:";
   this.label_City.TextAlign = System.Drawing.ContentAlignment.TopCenter;

   //
   // txt_Weather1
   //

   this.txt_Weather1.Font = new System.Drawing.Font("Nina", 9F, System.Drawing.FontStyle.Regular);
   this.txt_Weather1.Location = new System.Drawing.Point(12, 50);
   this.txt_Weather1.Size = new System.Drawing.Size(152, 14);
   this.txt_Weather1.Text = "天气:";

   //
   // txt_Date1
   //

   this.txt_Date1.Font = new System.Drawing.Font("Nina", 9F, System.Drawing.FontStyle.Regular);
   this.txt_Date1.Location = new System.Drawing.Point(12, 34);
   this.txt_Date1.Size = new System.Drawing.Size(152, 14);
   this.txt_Date1.Text = "日期:";

   //
   // txt_Temp1
   //

   this.txt_Temp1.Font = new System.Drawing.Font("Nina", 9F, System.Drawing.FontStyle.Regular);
   this.txt_Temp1.Location = new System.Drawing.Point(12, 68);
   this.txt_Temp1.Size = new System.Drawing.Size(152, 14);
   this.txt_Temp1.Text = "气温:";

   //
   // txt_WindPower1
   //

   this.txt_WindPower1.Font = new System.Drawing.Font("Nina", 9F, System.Drawing.FontStyle.Regular);
   this.txt_WindPower1.Location = new System.Drawing.Point(12, 84);
   this.txt_WindPower1.Size = new System.Drawing.Size(152, 14);
   this.txt_WindPower1.Text = "风力:";

   //
   // txt_Temp2
   //

   this.txt_Temp2.Font = new System.Drawing.Font("Nina", 9F, System.Drawing.FontStyle.Regular);
   this.txt_Temp2.Location = new System.Drawing.Point(12, 140);
   this.txt_Temp2.Size = new System.Drawing.Size(152, 14);
   this.txt_Temp2.Text = "气温:";

   //
   // txt_WindPower2
   //

   this.txt_WindPower2.Font = new System.Drawing.Font("Nina", 9F, System.Drawing.FontStyle.Regular);
   this.txt_WindPower2.Location = new System.Drawing.Point(12, 156);
   this.txt_WindPower2.Size = new System.Drawing.Size(152, 14);
   this.txt_WindPower2.Text = "风力:";

   //
   // txt_Date2
   //

   this.txt_Date2.Font = new System.Drawing.Font("Nina", 9F, System.Drawing.FontStyle.Regular);
   this.txt_Date2.Location = new System.Drawing.Point(12, 108);
   this.txt_Date2.Size = new System.Drawing.Size(152, 14);
   this.txt_Date2.Text = "日期:";

   //
   // txt_Weather2
   //

   this.txt_Weather2.Font = new System.Drawing.Font("Nina", 9F, System.Drawing.FontStyle.Regular);
   this.txt_Weather2.Location = new System.Drawing.Point(12, 124);
   this.txt_Weather2.Size = new System.Drawing.Size(152, 14);
   this.txt_Weather2.Text = "天气:";

   //
   // timer1
   //

   this.timer1.Interval = 200;
   this.timer1.Tick += new System.EventHandler(this.timer1_Tick);

   //
   // MainForm
   //

   this.Controls.Add(this.comboBox_City);
   this.Controls.Add(this.txt_Date1);
   this.Controls.Add(this.txt_Weather1);
   this.Controls.Add(this.label_City);
   this.Controls.Add(this.txt_Temp1);
   this.Controls.Add(this.txt_WindPower1);
   this.Controls.Add(this.txt_Temp2);
   this.Controls.Add(this.txt_WindPower2);
   this.Controls.Add(this.txt_Date2);
   this.Controls.Add(this.txt_Weather2);
   this.Menu = this.mainMenu1;
   this.Text = "天气预报";
  }

  #endregion

  /// <summary>
  /// The main entry point for the application.
  /// </summary>

  static void Main()
  {
   Application.Run(new MainForm());
  }

  private void menuItem_Exit_Click(object sender, System.EventArgs e)
  {
   this.Dispose();
  }

  private void menuItem1_Click(object sender, System.EventArgs e)
  {
   SearchWeather(this.comboBox_City.Text);
  }

  private string[] myString = new string[]
  {
    "日期: ",
    "温度: ",
    "天气: ",
    "风力: ",
  };

  public void SearchWeather(string cityName)
  {
   if( this.txt_Date1.Text != myString[0] )
   {
    ReSelect();
   }

   this.Text = "正在下载...";
   this.timer1.Enabled = true;

   WeatherService.Weather weather = new WeatherService.Weather();
   DataSet myDs = weather.GetWeatherDataSet(cityName);

   this.txt_Date1.Text = myString[0] + myDs.Tables[0].Rows[0]["Date1"].ToString();
   this.txt_Temp1.Text = myString[1] + myDs.Tables[0].Rows[0]["Temp1"].ToString();
   this.txt_Weather1.Text = myString[2] + myDs.Tables[0].Rows[0]["Weather1"].ToString();
   this.txt_WindPower1.Text = myString[3] + myDs.Tables[0].Rows[0]["WindPower1"].ToString();

   this.txt_Date2.Text = myString[0] + myDs.Tables[0].Rows[0]["Date2"].ToString();
   this.txt_Temp2.Text = myString[1] + myDs.Tables[0].Rows[0]["Temp2"].ToString();
   this.txt_Weather2.Text = myString[2] + myDs.Tables[0].Rows[0]["Weather2"].ToString();
   this.txt_WindPower2.Text = myString[3] + myDs.Tables[0].Rows[0]["WindPower2"].ToString();
  }

  private void ReSelect()
  {
   this.txt_Date1.Text = myString[0];
   this.txt_Temp1.Text = myString[1];
   this.txt_Weather1.Text = myString[2];
   this.txt_WindPower1.Text = myString[3];
   this.txt_Date2.Text = myString[0];
   this.txt_Temp2.Text = myString[1];
   this.txt_Weather2.Text = myString[2];
   this.txt_WindPower2.Text = myString[3];
  }

  private void timer1_Tick(object sender, System.EventArgs e)
  {
   if( this.txt_Date1.Text.IndexOf("月") != -1)
   {
    this.timer1.Enabled = false;
    this.Text = "天气预报";
   }
  }

  private void menuItem2_Click(object sender, System.EventArgs e)
  {
   this.Text = "作者:贺星河";
   System.Threading.Thread.Sleep(3000);
   this.Text = "天气预报";
  }
 }
}


上一页  1 2 3 4  下一页

发表评论推荐给朋友我想参加相关培训打印我对此感兴趣订阅电子杂志
天极社区邀请您:写博客日记  上传相片   论坛聊天  订阅电子杂志  推荐网摘   免费图铃工具
笔名:   请您注意:

 遵守国家有关法律、法规,尊重网上道德,承担一切因您的行为而直接或间接引起的法律责任。

 天极网拥有管理笔名和留言的一切权利。
评论:
 
,移动开发相关内容,移动开发焦点新闻
  • 用C#开发.NET CF 蓝牙通信模块
  • 基于CMPP2及东软API短信平台的开发
  • 2004开发技术年度综述之移动开发
  • Windows Mobile开发环境搭建指南
  • ucLinux下sqlite数据库移植全攻略
  • FVD刺激高清碟机加速商业化 抢占商机最重要
  • 3家搜索引擎集体诉讼8848 吕春维未敢出席
  • 杨元庆:没有准备不会获批的备用方案
  • 军队信息化诞生新领域 电子军务呼之欲出
  • 世界经济论坛公布信息化程度全球最新排名
  • 2004政务绩效评估:政府门户尚处于发展阶段
  • 甲骨文出资5.15亿美元 意图收购RetekInc
  • 技术并购:帮你突破传统增长的“天花板”
  • ,移动开发Advertisement