Uncategorized

Java GUI APIs Quick View

Posted on

Java AWT Tutorial

AWT and Swing. Not really popular in mainstream GUI design. But can be really helpful in learning the MVC architecture and building small interfaces.

MVC

Model, View, Controller.

“It divides a given application into three interconnected parts in order to separate internal representations of information from the ways that information is presented to and accepted from the user.The MVC design pattern decouples these major components allowing for efficient code reuse and parallel development.”

—- “Model-view-controller” from Wikipedia

AWT

Screen Shot 2017-05-02 at 9.31.17 PM

Frame includes the title and menu bars or other optional buttons and textfields.

Panel is the main area where textfields, buttons etc.

 

Socket programming in Java: Socket & IO

Posted on

Java Stream, File and IO

ServerSocket v.s. Socket

ServerSocket:

Set up the connection with address and port number. Listen to the response from client. Once the setup is finished and ServerSocket accept(), the control power is transferred to Socket.

Socket:

The actual role for communication between client and server.

Server-side:

  1. Setup ServerSocket with port number.
  2. accept()
  3. accept() returns a Socket

Client-side:

  1. Initiate a client Socket
  2. Use Socket.getOutputStream/getInputStream

Basic structure of client:

  1. Open a socket.
  2. Open an input stream and output stream to the socket.
  3. Read from and write to the stream according to the server’s protocol.
  4. Close the streams.
  5. Close the socket.