package udpchatserver; import javax.swing.UIManager; import java.awt.*; import java.net.*; import java.util.*; import java.io.*; public class ClientInterface { boolean packFrame = false; DatagramSocket ChatSocket; /**Construct the application*/ public ClientInterface() { try{ //create the master thread for the new client interface ChatSocket = new DatagramSocket(); } catch (SocketException se) { System.err.println(se); } catch (IOException e) { System.err.println(e); } //create the new UI frame and recieving thread. //Pass each a reference of the master thread. //pass the thread the frame text area and the entire frame. //Didn't need to pass the frame.textare if already passing the whole frame, //but had already written it this way and not worth changing the whole thing. ClientInterfaceFrame frame = new ClientInterfaceFrame(ChatSocket); Thread r = new ClientRecieve(frame.GetTextArea(),ChatSocket, frame); r.start(); //Validate frames that have preset sizes //Pack frames that have useful preferred size info, e.g. from their layout if (packFrame) { frame.pack(); } else { frame.validate(); } //Center the window Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); frame.setVisible(true); } /**Main method*/ public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) { e.printStackTrace(); } new ClientInterface(); } }