12. There are many ways to develop software, from the platform of the software running, can be run on the following platform:
- Web pages (software or services can be accessed as long as a browser is available)
- Windows platforms (such as the latest Windows 10 support Pc,surface,mobile, even Xbox run)
- Android Platform
- IOS platform (MAC and IPhone)
Please find a classmate pair (see this book pair programming content), two people work together (can not work separately), from the list above to choose two platforms, on each platform, write one of the simplest "Hello World" type of program, write the experience of the program written blog published, The content includes:
-What platform, what programming language, what software building Environment (IDE), what are the tools of the engineering, what is the process of development, what is the source of the final program, and what is the user interface?
(Can find relevant information from the Internet, even the source program can refer to other people, but to own The program compiled, run)
1. Choose to output one on the Web page: Hello World
Write a servlet to display HelloWorld on a Web page, using the language Java, the specific development process and build environment are as follows:
First, a new package is created under SRC under the Java resources, and then the Myservlet class is established.
The code is written as follows:
Package Page;import java.io.ioexception;import java.io.printwriter;import javax.servlet.ServletException; Import Javax.servlet.servletrequest;import javax.servlet.servletresponse;import javax.servlet.http.HttpServlet; Public classMyservlet extends httpservlet{@Override Public voidService (ServletRequest req, servletresponse Res) throws Servletexception, IOException {//TODO auto-generated Method StubRes.setcontenttype ("text/html"); Res.setcharacterencoding ("Utf-8"); PrintWriter writer=NULL; Try{writer=Res.getwriter (); Writer.write ("Hello world!"); }Catch(IOException e) {e.printstacktrace (); }}}
After the servlet is configured, add the project to the server and then run server. After successful operation, open browser input: http://localhost:8080/firstweb/hello.do
You can get the Hello world displayed on the page
2. Choose to output A: Hello World on the Android table
Use the original Android platform to develop the app, modify the code to show Hello World. Configuration environment for Android app development specific environment, the language is Java, the code and interface are as follows:
PackageCom.example.audiosharer;Importjava.io.IOException;ImportOrg.apache.http.HttpResponse;Importorg.apache.http.client.ClientProtocolException;ImportOrg.apache.http.client.methods.HttpGet;Importorg.apache.http.impl.client.DefaultHttpClient;Importorg.apache.http.util.EntityUtils;Importorg.json.JSONException;ImportOrg.json.JSONObject;ImportOrg.json.JSONTokener;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.os.StrictMode;ImportAndroid.util.Log;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.Button;ImportAndroid.widget.EditText;ImportAndroid.widget.ImageView;ImportAndroid.widget.TextView; Public classSecondextendsActivity {PrivateButton Search; PrivateEditText CityName; //private SayHello HelloWorld; PrivateImageView Weatherimage; PrivateTextView temperature; PrivateTextView Weather; PrivateTextView Wind; @Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Strictmode.setthreadpolicy (NewStrictMode.ThreadPolicy.Builder (). Detectdiskreads (). Detectdiskwrites (). Detectnetwork () . Penaltylog (). build ()); Strictmode.setvmpolicy (NewStrictMode.VmPolicy.Builder (). Detectleakedsqlliteobjects (). Detectleakedclosableobjects () . Penaltylog (). Penaltydeath (). build ()); Setcontentview (R.layout.second); Search=(Button) Findviewbyid (R.id.search); CityName=(EditText) Findviewbyid (r.id.cityname); //HelloWorld = (SayHello) Findviewbyid (R.id.helloworld);Weatherimage =(ImageView) Findviewbyid (r.id.weatherimage); Temperature=(TextView) Findviewbyid (r.id.temperature); Weather=(TextView) Findviewbyid (R.id.weather); Wind=(TextView) Findviewbyid (R.id.wind); Changeweather (Nanjing); Search.setonclicklistener (NewOnclicklistener () {@OverridePrivatestring[] GetDate () {return NewString[] {"Hello world"}; } Public voidOnClick (View arg0) {changeweather (Cityname.gettext (). toString ()); } }); } Public voidchangeweather (String cityname) {string ServerURL= "Http://v.juhe.cn/weather/index?key=206b256d722ae1d509bd9760f22fbc69&dtype=json&cityname=" + CityName + " &format=1 "; String result= ""; HttpGet HttpRequest=NewHttpGet (ServerURL);//establishing an HTTP GET online Try{HttpResponse HttpResponse=Newdefaulthttpclient (). Execute (HttpRequest); if(Httpresponse.getstatusline (). Getstatuscode () = = 200) Result= Entityutils.tostring (Httpresponse.getentity ());//get the appropriate string}Catch(clientprotocolexception e) {e.printstacktrace (); } Catch(IOException e) {e.printstacktrace (); }//make an HTTP request//System.out.println ("====================>" + result);String TempStr= ""; String Weatherstr= ""; String Windstr= ""; Try{Jsontokener Jsonparser=NewJsontokener (Result); Jsonobject Weatherjson=(Jsonobject) jsonparser.nextvalue (); TempStr= Weatherjson.getjsonobject ("Result"). Getjsonobject ("Today"). GetString ("Temperature")); Weatherstr= Weatherjson.getjsonobject ("Result"). Getjsonobject ("Today"). GetString ("Weather")); Windstr= Weatherjson.getjsonobject ("Result"). Getjsonobject ("Today"). GetString ("Wind")); } Catch(jsonexception e) {e.printstacktrace (); } temperature.settext (" " +tempstr); Weather.settext (" " +weatherstr); Wind.settext (" " +windstr); if(Weatherstr = = "Fine") {Weatherimage.setimageresource (r.drawable.weathericon_condition_01); } Else if(Weatherstr.trim (). Contains ("Cloudy") {weatherimage.setimageresource (r.drawable.weathericon_condition_03); } Else if(Weatherstr.trim (). Contains ("Yin")) {weatherimage.setimageresource (r.drawable.weathericon_condition_04); } Else if(Weatherstr.trim (). Contains ("Fog")) {weatherimage.setimageresource (r.drawable.weathericon_condition_05); } Else if(Weatherstr.trim (). Contains ("Sandstorm") {weatherimage.setimageresource (r.drawable.weathericon_condition_06); } Else if(Weatherstr.trim (). Contains ("Shower") {weatherimage.setimageresource (r.drawable.weathericon_condition_07); } Else if(Weatherstr.trim (). Contains ("Rain") {weatherimage.setimageresource (r.drawable.weathericon_condition_08); } Else if(Weatherstr.trim (). Contains ("Light Rain") {weatherimage.setimageresource (r.drawable.weathericon_condition_08); } Else if(Weatherstr.trim (). Contains ("Heavy rain") {weatherimage.setimageresource (r.drawable.weathericon_condition_09); } Else if(Weatherstr.trim (). Contains ("Thunder") {weatherimage.setimageresource (r.drawable.weathericon_condition_10); } Else if(Weatherstr.trim (). Contains ("Snow")) {weatherimage.setimageresource (r.drawable.weathericon_condition_11); } Else if(Weatherstr.trim (). Contains ("Snow") {weatherimage.setimageresource (R.drawable.weathericon_condition_12); } Else if(Weatherstr.trim (). Contains ("Snow") {weatherimage.setimageresource (r.drawable.weathericon_condition_13); } Else if(Weatherstr.trim (). Contains ("Sleet") {weatherimage.setimageresource (r.drawable.weathericon_condition_14); } }}
The interface shown in the app is:
The 12th question of modern software engineering operation (original 14 questions)