Example #1
0
 public void stop() {
   try {
     if (streamOut != null) streamOut.close();
     if (socket != null) socket.close();
   } catch (IOException ioe) {
     System.err.println("Error closing ...");
     System.exit(0);
   }
   loginThread.close();
 }
Example #2
0
 public void handle(String msg) {
   System.out.println("Idem handleat ovaj msg: " + msg);
   if (msg.equals("REGISTEROK")) {
     /*  otvori onaj dialog koji kaze successful registration */
     SuccessRegister dialog = new SuccessRegister();
     dialog.setVisible(true);
     if (reg != null) reg.dispose();
   } else if (msg.equals("OKADMIN")) {
     AdminWindow window = new AdminWindow(socket, UsernameLogin.getText());
     loginThread.setStopper(true);
     /* kada je uspjesan login, zaustavi loginThread
     koji slusa odgovor od servera (ali socket ostaje otvoren!) */
     dispose(); // rjesi se ovog prozora
     window.setVisible(true);
   } else if (msg.equals("OK")) {
     MainWindow window = new MainWindow(socket, UsernameLogin.getText());
     loginThread.setStopper(true);
     /* kada je uspjesan login, zaustavi loginThread
     koji slusa odgovor od servera (ali socket ostaje otvoren!) */
     dispose(); // rjesi se ovog prozora
     window.setVisible(true);
   } else if (msg.equals("REGISTERFAIL")) {
     try {
       /* provjera za slucaj lose definiranog puta za sliku */
       WarningRegister warnReg = new WarningRegister(new javax.swing.JFrame(), true);
       warnReg.setVisible(true);
     } catch (Exception e) {
     }
   } else {
     try {
       /* provjera za slucaj lose definiranog puta za sliku */
       WarningLogin warnLog = new WarningLogin(new javax.swing.JFrame(), true);
       warnLog.setVisible(true);
     } catch (Exception e) {
     }
   }
 }
Example #3
0
  /** Creates new form Login */
  public Login() {
    initComponents();
    setTitle("Zlatna ribica");
    /*
    napravit konekciju sa serverom
    */
    String servername = "0.0.0.0"; /* pretpostavljen localhost */
    int port = 1000; /* pretpostavljeno da server slusa na portu 23456 */
    try {
      socket = new Socket(servername, port);
      streamOut = new DataOutputStream(socket.getOutputStream());
      streamIn = new DataInputStream(socket.getInputStream());

    } catch (UnknownHostException uhe) {
      System.err.println("Host unknown " + uhe.getMessage());
      System.exit(0);
    } catch (IOException ioe) {
      System.err.println("Unexpected exception; " + ioe.getMessage());
      System.exit(0);
    }

    loginThread = new LoginThread(this, socket);
    loginThread.start();
  }