package com.example.logic1; import java.util.Random; import android.R.string; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final TextView head = (TextView) findViewById(R.id.TextView1); final TextView in1 = (TextView) findViewById(R.id.Edit1); final TextView in2 = (TextView) findViewById(R.id.Edit2); final TextView in3 = (TextView) findViewById(R.id.Edit3); final TextView in4 = (TextView) findViewById(R.id.Edit4); final TextView out1 = (TextView) findViewById(R.id.Text1); final Button but1 = (Button) findViewById(R.id.but1); but1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /* Random random = new Random(); int[] s = new int[4]; s[0] = random.nextInt(10); s[1] = random.nextInt(10); while (s[1] == s[0]) { s[1] = random.nextInt(10); } s[2] = random.nextInt(10); while (s[2] == s[1] || s[2] == s[0]) { s[2] = random.nextInt(10); } s[3] = random.nextInt(10); while (s[3] == s[1] || s[3] == s[0] || s[3] == s[2]) { s[3] = random.nextInt(10); } */ int[] s = new int[4]; int a, b, c, d, count = 0, count1 = 0, count2 = 0; out1.append("Random = "+s[0]+s[1]+s[2]+s[3]); head.setText("กรุณาใส่ตัวเลข"); String b1 = in1.getText().toString(); String b2 = in2.getText().toString(); String b3 = in3.getText().toString(); String b4 = in4.getText().toString(); if (b1.length() == 0 || b2.length() == 0 || b3.length() == 0 || b4.length() == 0) { head.setText("กรุณาใส่ตัวเลข"); return; } a = Integer.parseInt(b1); b = Integer.parseInt(b2); c = Integer.parseInt(b3); d = Integer.parseInt(b4); { count1 = 0; count = 0; while (count == 0) { if (a == s[0]) { out1.append("X"); count = 1; count1 = count1 + 1; break; } if (a == s[1]) { out1.append("/"); count = 1; break; } if (a == s[2]) { out1.append("/"); count = 1; break; } if (a == s[3]) { out1.append("/"); count = 1; break; } else { break; } } } count = 0; while (count == 0) { if (b == s[0]) { out1.append("/"); count = 1; break; } if (b == s[1]) { out1.append("X"); count1 = count1 + 1; count = 1; break; } if (b == s[2]) { out1.append("/"); count = 1; break; } if (b == s[3]) { out1.append("/"); count = 1; break; } else { break; } } count = 0; while (count == 0) { if (c == s[0]) { out1.append("/"); count = 1; break; } if (c == s[1]) { out1.append("/"); count = 1; break; } if (c == s[2]) { out1.append("X"); count1 = count1 + 1; count = 1; break; } if (c == s[3]) { out1.append("/"); count = 1; break; } else { break; } } count = 0; while (count == 0) { if (d == s[0]) { out1.append("/"); count = 1; break; } if (d == s[1]) { out1.append("/"); count = 1; break; } if (d == s[2]) { out1.append("/"); count = 1; break; } if (d == s[3]) { out1.append("X"); count1 = count1 + 1; count = 1; break; } else { break; } } if (count1 == 4) { out1.append("\nPoint = " + count2 + 1 + "\n"); return; } } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง