Advertisement
craftim_74

ChatClient.java

Oct 30th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.45 KB | None | 0 0
  1. package fr.crafttim.chat.client;
  2.  
  3. import java.awt.Dimension;
  4.  
  5. import javax.swing.JFrame;
  6. import javax.swing.UIManager;
  7.  
  8. import fr.crafttim.chat.client.network.ClientSide;
  9. import fr.crafttim.chat.client.ui.ChatWindow;
  10. import fr.crafttim.chat.client.ui.ConnectWindow;
  11.  
  12. public class ChatClient {
  13.    
  14.     private ClientSide clientSide;
  15.     private ConnectWindow connectUI;
  16.     private ChatWindow ui;
  17.    
  18.     public ChatClient(){
  19.         clientSide = new ClientSide(this);
  20.         showConnectUI();
  21.     }
  22.    
  23.     private void showConnectUI() {
  24.         connectUI = new ConnectWindow(this);
  25.         connectUI.setLocationRelativeTo(null);
  26.         connectUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  27.         connectUI.setVisible(true);
  28.     }
  29.    
  30.     public void onConnected(){
  31.         clientSide.start();
  32.         setupGUI();
  33.     }
  34.  
  35.     private void setupGUI() {
  36.         connectUI.setVisible(false);
  37.         connectUI.dispose();
  38.         ui = new ChatWindow(this);
  39.         ui.setTitle("D-Net Chat");
  40.         ui.setPreferredSize(new Dimension(640, 480));
  41.         ui.validate();
  42.         ui.pack();
  43.         ui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  44.         ui.setLocationRelativeTo(null);
  45.         ui.setVisible(true);
  46.     }
  47.    
  48.     public ChatWindow getWindow(){
  49.         return this.ui;
  50.     }
  51.    
  52.     public ClientSide getClientSide(){
  53.         return this.clientSide;
  54.     }
  55.    
  56.     public static void main(String[] args){
  57.         try {
  58.             UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  59.         } catch (Exception e) {
  60.             e.printStackTrace();
  61.         } finally {
  62.             new ChatClient();
  63.         }
  64.     }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement