Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package client.jdbc.sinhvien;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.net.Socket;
- import java.util.Scanner;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author Phungg
- */
- public class ClientJDBCSinhVien {
- /**
- * @param args the command line arguments
- */
- public static class Login extends Thread
- {
- Socket s;
- Login(Socket cl)
- {
- this.s=cl;
- }
- public void run()
- {
- DataOutputStream send;
- DataInputStream receive;
- Scanner bp = new Scanner(System.in);
- try {
- send = new DataOutputStream(s.getOutputStream());
- receive = new DataInputStream(s.getInputStream());
- while(true)
- {
- System.out.println("User: ");
- String user = bp.nextLine();
- System.out.println("Password: ");
- String password = bp.nextLine();
- send.writeUTF(user);
- send.writeUTF(password);
- String message = receive.readUTF();
- System.out.println(message);
- if(message.compareTo("Menu: \n 1.Xem Diem \n 2.Nhap Diem \n 3.Thoat" )==0)
- break;
- }
- while(true)
- {
- System.out.println(receive.readUTF());
- int n = bp.nextInt();
- send.writeInt(n);
- if(n==1)
- {
- System.out.println(receive.readUTF());
- Scanner bp2 = new Scanner(System.in);
- String mssv = bp2.nextLine();
- send.writeUTF(mssv);
- System.out.println(receive.readUTF());
- }
- else
- if(n==2)
- {
- Scanner bp3 = new Scanner(System.in);
- System.out.println(receive.readUTF());
- String ms = bp3.nextLine();
- send.writeUTF(ms);
- System.out.println(receive.readUTF());
- String hoten = bp3.nextLine();
- send.writeUTF(hoten);
- System.out.println(receive.readUTF());
- String diem = bp3.nextLine();
- send.writeUTF(diem);
- System.out.println(receive.readUTF());
- }
- }
- } catch (IOException ex) {
- Logger.getLogger(ClientJDBCSinhVien.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- public static synchronized void main(String[] args)throws IOException{
- Socket cl = new Socket("localhost",1234);
- Login a = new Login(cl);
- a.start();
- // TODO code application logic here
- }
- }
Add Comment
Please, Sign In to add comment