• 不分手的恋爱
    了解作者
  • Java
    开发工具
  • 175KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 0
    下载次数
  • 2018-12-25 22:10
    上传日期
简单 的天气啦,可以进行实时联网查询,同时可以自行修改
YYFapp.zip
内容介绍
package cn.cc.yyfapp; import android.os.Handler; import android.os.Message; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLEncoder; public class MainActivity extends AppCompatActivity implements View.OnClickListener{ EditText ed_ip,ed_zh,ed_password; Button bt_get,bt_post; TextView tv; Handler handler=new Handler(){ @Override public void handleMessage(Message msg) { tv.setText((msg.obj).toString()); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init(); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.bt_get: get(); break; case R.id.bt_post: post(); break; } } public void init(){ ed_ip=findViewById(R.id.ed_ip); ed_zh=findViewById(R.id.ed_zh); ed_password=findViewById(R.id.ed_password); tv=findViewById(R.id.tv); bt_get=findViewById(R.id.bt_get); bt_post=findViewById(R.id.bt_post); bt_get.setOnClickListener(this); bt_post.setOnClickListener(this); } public void get(){ final String ip=ed_ip.getText().toString().trim(); final String zh=ed_zh.getText().toString().trim(); final String password=ed_password.getText().toString().trim(); new Thread(){ HttpURLConnection httpURLConnection; @Override public void run() { try { URL url=new URL("http://"+ip+"/WebRoot/servlet/LoginServlet?a="+URLEncoder.encode(zh,"UTF-8")+"&b="+URLEncoder.encode(password,"UTF-8")); httpURLConnection=(HttpURLConnection)url.openConnection(); httpURLConnection.setRequestMethod("GET"); httpURLConnection.setConnectTimeout(3000); int code=httpURLConnection.getResponseCode(); if(code==200){ InputStream inputStream=httpURLConnection.getInputStream(); BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(inputStream)); StringBuilder stringBuilder=new StringBuilder(); String c=""; while ((c=bufferedReader.readLine())!=null){ stringBuilder.append(c); } Message message=new Message(); message.what=1; message.obj=stringBuilder; handler.sendMessage(message); } else { Toast.makeText(MainActivity.this, "内容错误!", Toast.LENGTH_SHORT).show(); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }.start(); } public void post() { final String ip=ed_ip.getText().toString().trim(); final String zh=ed_zh.getText().toString().trim(); final String password=ed_password.getText().toString().trim(); new Thread(){ HttpURLConnection httpURLConnection; @Override public void run() { try { URL url=new URL("http://"+ip+"/WebRoot/servlet/LoginServlet"); httpURLConnection=(HttpURLConnection)url.openConnection(); String data="a="+URLEncoder.encode(zh,"UTF-8")+"&b="+URLEncoder.encode(password,"UTF-8"); httpURLConnection.setRequestMethod("POST"); httpURLConnection.setConnectTimeout(3000); httpURLConnection.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); httpURLConnection.setRequestProperty("Content-Length",data.length()+""); httpURLConnection.setDoOutput(true); OutputStream outputStream=httpURLConnection.getOutputStream(); outputStream.write(data.getBytes()); int code=httpURLConnection.getResponseCode(); if(code==200){ InputStream inputStream=httpURLConnection.getInputStream(); BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(inputStream)); StringBuilder stringBuilder=new StringBuilder(); String c=""; while ((c=bufferedReader.readLine())!=null){ stringBuilder.append(c); } Message message=new Message(); message.what=2; message.obj=stringBuilder; handler.sendMessage(message); } else { Toast.makeText(MainActivity.this, "内容错误!", Toast.LENGTH_SHORT).show(); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }.start(); } }
评论
    相关推荐
    • ZxingDemo.rar
      android上使用ZXing识别条形码和二维码,代码简单易懂,相信能帮助读者迅速掌握相关的开发
    • android-order-system.rar
      基于Java的android点餐系统--android手机点餐系统,实现基本点菜功能,供大家参考学习
    • MTK-MT6235-USB-driver-2009082823351054.rar
      MTK 6235 USB driver for Nokia N97
    • Mine.zip
      Android 扫雷游戏源代码,代码中附加了详细的注释,另附加Ophone游戏开发文档,有详细搭建开发环境过程,与开发Android类似
    • J2ME_(chinese)api.rar
      J2ME 中文api以及应用 J2ME 中文api以及应用
    • Gallery3D.rar
      安卓系统原生的3D图片浏览器源代码,有兴趣的可以研究一下
    • wpctsc.rar
      wpctsc.exe for windows mobile 可以使WM手机远程登入PC
    • Animation-J2ME.rar
      手机游戏中的动画和CG是怎么做的呢,这个源代码中给了清晰的讲解,此代码是手机游戏巨头智乐(gameloft)公司所使用的引擎,很值得学习
    • androidexample.rar
      androidexample有130多个实例,是现在国内最全的ANDROID实例代码库,希望对大家有用
    • ColorLinez.rar
      用J2ME写的一种五子连线的手机游戏。ColorLinez是一款由玩家通过功能键移动各色小球,把五个及五个以上相同颜色小球移成一横排、一竖列,小球从而消失的游戏,玩家每移动一个小球,就会随机新出现三个随机颜色的小球,小球消失的数量作为玩家得到的分数!