-
Notifications
You must be signed in to change notification settings - Fork 1
/
Game2.java
116 lines (104 loc) · 3.43 KB
/
Game2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package com.example.scoreit;
import androidx.appcompat.app.AppCompatActivity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class Game2 extends AppCompatActivity {
int key=1;
String J1;
String f1;
JSONObject j1;
JSONArray ja;
TextView t1,t2,t3,k1,k2,k3,bbtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game2);
t1 = findViewById(R.id.teama);
t2 = findViewById(R.id.teamb);
t3 = findViewById(R.id.teamc);
k1 = findViewById(R.id.killsA);
k2 = findViewById(R.id.killsB);
k3 =findViewById(R.id.killsC);
bbtn = findViewById(R.id.button);
bbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getJSON(v);
}
});
}
public void getJSON(View view)
{
new BackgroundTask().execute();
}
class BackgroundTask extends AsyncTask<Void,Void,String>
{
String url1;
@Override
protected void onPostExecute(String aVoid) {
f1 = aVoid;
try{
j1 = new JSONObject(f1);
ja = j1.getJSONArray("server_response");
JSONObject j2 = ja.getJSONObject(1);
t1.setText(j2.getString("TeamAname"));
k1.setText(j2.getString("TeamAkills"));
t2.setText(j2.getString("TeamBname"));
k2.setText(j2.getString("TeamBkills"));
t3.setText(j2.getString("TeamCname"));
k3.setText(j2.getString("TeamCkills"));
}
catch (JSONException e)
{
e.printStackTrace();
}
}
@Override
protected void onPreExecute() {
url1 = "https://projectpegasus.000webhostapp.com/getdata.php";
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
@Override
protected String doInBackground(Void... voids) {
try{
URL url = new URL(url1);
HttpURLConnection h1 = (HttpURLConnection)url.openConnection();
InputStream i1 =h1.getInputStream();
BufferedReader b1 = new BufferedReader(new InputStreamReader(i1));
StringBuilder s1 = new StringBuilder();
while((J1 = b1.readLine()) != null)
{
s1.append(J1 + "\n");
}
b1.close();
i1.close();
h1.disconnect();
return s1.toString().trim();
}
catch(MalformedURLException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
return null;
}
}
}