Advertisement
Guest User

Untitled

a guest
Feb 17th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. public class LogIn extends Activity implements View.OnClickListener{
  2.  
  3. private Socket socket;
  4. private DataOutputStream out;
  5. private DataInputStream in;
  6.  
  7. private String username,password,s;
  8.  
  9. EditText eT_username,eT_password;
  10. Button b_login,b_signup,b_connect;
  11. TextView t;
  12.  
  13. @Override
  14. protected void onCreate(Bundle savedInstanceState) {
  15. super.onCreate(savedInstanceState);
  16. setContentView(R.layout.activity_log_in);
  17.  
  18. eT_username = (EditText)findViewById(R.id.eT_username);
  19. eT_password = (EditText)findViewById(R.id.eT_password);
  20.  
  21. b_login = (Button)findViewById(R.id.b_login);
  22. b_signup = (Button)findViewById(R.id.b_signup);
  23. b_connect = (Button)findViewById(R.id.b_connect);
  24.  
  25. t = (TextView)findViewById(R.id.tV);
  26.  
  27. b_login.setOnClickListener(this);
  28. }
  29.  
  30. @Override
  31. public void onClick(View v) {
  32. String toast_msg;
  33. try {
  34. out = new DataOutputStream(socket.getOutputStream());
  35. in = new DataInputStream(socket.getInputStream());
  36.  
  37. out.writeUTF("1");
  38.  
  39. username = eT_username.getText().toString();
  40. password = eT_password.getText().toString();
  41.  
  42. out.writeUTF(username);
  43. // out.flush();
  44. out.writeUTF(password);
  45. // out.flush();
  46.  
  47. t.setText("hi");
  48.  
  49. s = in.readUTF();
  50.  
  51.  
  52. if (s.equals("ok")) {
  53. toast_msg = "Login is successfull";
  54. t.setText(toast_msg);
  55. } else {
  56. toast_msg = "username or password is incorrect";
  57. t.setText(toast_msg);
  58. }
  59.  
  60. } catch (IOException e) {
  61. t.setText(e.toString());
  62. }
  63. }
  64.  
  65.  
  66.  
  67. public void connect(View v)
  68. {
  69. new Thread(new Runnable() {
  70. @Override
  71. public void run() {
  72. try
  73. {
  74. socket = new Socket("192.168.0.101",5000);
  75.  
  76. }
  77. catch(Exception e)
  78. {
  79. TextView t = (TextView)findViewById(R.id.textView);
  80. t.setText(e.toString());
  81. // Toast.makeText(LogIn.this,"Make sure that you are connected to Internet",Toast.LENGTH_LONG).show();
  82. }
  83. }
  84. }).start();
  85. }
  86. public void openSignUp(View v)
  87. {
  88. if (v.getId()== R.id.b_signup)
  89. {
  90. Intent i = new Intent(LogIn.this,SignUp.class);
  91. startActivity(i);
  92. }
  93. new SignUp(socket);
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement