Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.io.PrintWriter;
- import java.net.Socket;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JList;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import javax.swing.JTextArea;
- import javax.swing.JTextField;
- import javax.swing.ScrollPaneConstants;
- import javax.swing.SwingConstants;
- public class ClientGUI {
- //Global Variables
- private static Client client;
- public static String userName = "";
- //GUI Global Variables - Main Window
- public static JFrame MainWindow = new JFrame();
- public static JButton connect = new JButton();
- public static JButton disconnect = new JButton();
- public static JButton send = new JButton();
- private static JLabel conversation = new JLabel();
- private static JLabel online = new JLabel();
- private static JLabel loggedIn = new JLabel();
- private static JLabel loggedInAs = new JLabel();
- public static JTextField taMessage = new JTextField();
- public static JTextArea taConversation = new JTextArea();
- private static JScrollPane spConversation = new JScrollPane();
- private static JScrollPane spOnline = new JScrollPane();
- public static JList lOnline = new JList();
- //GUI Global Variables - Login Window
- public static JFrame LoginWindow = new JFrame();
- public static JTextField username = new JTextField();
- private static JButton login = new JButton("Enter");
- private static JLabel enterUsername = new JLabel("Enter your desired UserName: ");
- private static JPanel pLogin = new JPanel();
- //-------------------------------------------------------------------------------------
- public static void main(String args[])
- {
- BuildMainWindow();
- Initialize();
- }
- public static void Connect()
- {
- try
- {
- final int port = 2525;
- final String host = "LoveTree";
- Socket socket = new Socket(host, port);
- System.out.println("Connected to: " +host);
- /**PrintWriter out = new PrintWriter(socket);
- out.println(username);
- out.flush();
- client = new Client(socket.getOutputStream());
- Thread x = new Thread(client);**/
- }
- catch(Exception e)
- {
- System.out.println(e);
- JOptionPane.showMessageDialog(null, "Server not responding. Try Again.");
- System.exit(0);
- }
- }
- public static void Initialize()
- {
- send.setEnabled(false);
- connect.setEnabled(false);
- disconnect.setEnabled(false);
- }
- public static void BuilLogInWindow()
- {
- LoginWindow.setTitle("What's your username?");
- LoginWindow.setSize(400,100);
- LoginWindow.setLocationRelativeTo(null);
- LoginWindow.setResizable(false);
- pLogin = new JPanel();
- pLogin.add(enterUsername);
- pLogin.add(username);
- pLogin.add(login);
- LoginWindow.add(pLogin);
- //Login_Action();
- LoginWindow.setVisible(true);
- }
- public static void BuildMainWindow()
- {
- MainWindow.setTitle("The Tree");
- MainWindow.setSize(615, 375);
- MainWindow.setLocationRelativeTo(null);
- MainWindow.setResizable(false);
- MainWindowProperties();
- //MainWindow_Action();
- MainWindow.setVisible(true);
- }
- public static void paint(Graphics g)
- {
- g.setColor(new Color(0, 0, 0));
- g.drawRect(496, 296, 2, 2);
- g.drawRect(138, 24, 2, 2);
- g.drawRect(18, 26, 2, 2);
- g.drawRect(15, 269, 2, 2);
- }
- public static void MainWindowProperties()
- {
- MainWindow.setBackground(new Color(56, 60, 68));
- MainWindow.setSize(615, 375);
- MainWindow.getContentPane().setLayout(null);
- send.setBackground(new Color(0, 0, 0));
- send.setForeground(new Color(255, 108, 22));
- send.setText("Send");
- MainWindow.getContentPane().add(send);
- send.setBounds(496, 243, 559, 296);
- disconnect.setBackground(new Color(0, 0, 0));
- disconnect.setForeground(new Color(255, 108, 22));
- disconnect.setText("Disconnect");
- MainWindow.getContentPane().add(disconnect);
- send.setBounds(138, 11, 242, 24);
- connect.setBackground(new Color(0, 0, 0));
- connect.setForeground(new Color(255, 108, 22));
- connect.setText("Connect");
- MainWindow.getContentPane().add(connect);
- send.setBounds(18, 11, 122, 24);
- taMessage.setBackground(new Color(0, 0, 0));
- taMessage.setForeground(new Color(255, 255, 255));
- taMessage.requestFocus();
- MainWindow.getContentPane().add(taMessage);
- taMessage.setBounds(15, 31, 487, 269);
- taConversation.setColumns(24);
- taConversation.setFont(new Font("Tahoma", 0, 12));
- taConversation.setForeground(new Color(255, 255, 255));
- taConversation.setLineWrap(true);
- taConversation.setRows(12);
- taConversation.setEditable(false);
- spConversation.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
- spConversation.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
- spConversation.setViewportView(taConversation);
- MainWindow.getContentPane().add(spConversation);
- spConversation.setBounds(473, 33, 485, 267);
- online.setHorizontalAlignment(SwingConstants.CENTER);
- online.setText("Online:");
- online.setToolTipText("");
- MainWindow.getContentPane().add(online);
- online.setForeground(new Color(255, 208, 22));
- online.setBounds(495, 8, 601, 30);
- String [] TestNames = {"Jack", "Connor", "Sophie", "Lucy"};
- lOnline.setForeground(new Color(255, 255, 255));
- lOnline.setListData(TestNames);
- spOnline.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
- spOnline.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
- spOnline.setViewportView(lOnline);
- MainWindow.getContentPane().add(spOnline);
- spOnline.setBounds(497, 33, 599, 267);
- loggedInAs.setFont(new Font("Tahoma", 0, 12));
- loggedInAs.setText("Logged in as:");
- MainWindow.setContentPane(loggedInAs);
- loggedInAs.setForeground(new Color(255, 208, 22));
- loggedInAs.setBounds(282, 9, 0, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment