Guest User

Untitled

a guest
Oct 18th, 2017
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package client.jdbc.sinhvien;
  7. import java.io.DataInputStream;
  8. import java.io.DataOutputStream;
  9. import java.io.IOException;
  10. import java.net.Socket;
  11. import java.util.Scanner;
  12. import java.util.logging.Level;
  13. import java.util.logging.Logger;
  14. /**
  15. *
  16. * @author Phungg
  17. */
  18. public class ClientJDBCSinhVien {
  19.  
  20. /**
  21. * @param args the command line arguments
  22. */
  23. public static class Login extends Thread
  24. {
  25. Socket s;
  26. Login(Socket cl)
  27. {
  28. this.s=cl;
  29. }
  30. public void run()
  31. {
  32. DataOutputStream send;
  33. DataInputStream receive;
  34. Scanner bp = new Scanner(System.in);
  35. try {
  36. send = new DataOutputStream(s.getOutputStream());
  37. receive = new DataInputStream(s.getInputStream());
  38. while(true)
  39. {
  40. System.out.println("User: ");
  41. String user = bp.nextLine();
  42. System.out.println("Password: ");
  43. String password = bp.nextLine();
  44. send.writeUTF(user);
  45. send.writeUTF(password);
  46. String message = receive.readUTF();
  47. System.out.println(message);
  48. if(message.compareTo("Menu: \n 1.Xem Diem \n 2.Nhap Diem \n 3.Thoat" )==0)
  49. break;
  50. }
  51. while(true)
  52. {
  53. System.out.println(receive.readUTF());
  54. int n = bp.nextInt();
  55. send.writeInt(n);
  56. if(n==1)
  57. {
  58. System.out.println(receive.readUTF());
  59. Scanner bp2 = new Scanner(System.in);
  60. String mssv = bp2.nextLine();
  61. send.writeUTF(mssv);
  62. System.out.println(receive.readUTF());
  63. }
  64. else
  65. if(n==2)
  66. {
  67. Scanner bp3 = new Scanner(System.in);
  68. System.out.println(receive.readUTF());
  69. String ms = bp3.nextLine();
  70. send.writeUTF(ms);
  71. System.out.println(receive.readUTF());
  72. String hoten = bp3.nextLine();
  73. send.writeUTF(hoten);
  74. System.out.println(receive.readUTF());
  75. String diem = bp3.nextLine();
  76. send.writeUTF(diem);
  77. System.out.println(receive.readUTF());
  78. }
  79. }
  80. } catch (IOException ex) {
  81. Logger.getLogger(ClientJDBCSinhVien.class.getName()).log(Level.SEVERE, null, ex);
  82. }
  83. }
  84. }
  85.  
  86. public static synchronized void main(String[] args)throws IOException{
  87. Socket cl = new Socket("localhost",1234);
  88. Login a = new Login(cl);
  89. a.start();
  90. // TODO code application logic here
  91. }
  92.  
  93. }
Add Comment
Please, Sign In to add comment