Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.finenerds.chat.client;
- import java.io.*;
- import java.net.*;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public final class Client extends JFrame implements ActionListener{
- static String username;
- PrintWriter pw;
- static BufferedReader br;
- static JTextArea cm;
- static JTextField cip;
- Socket chatUsers;
- public Client(String cname, String servername) throws IOException
- {
- super(cname);
- this.username = cname;
- chatUsers = new Socket(servername,80);
- br = new BufferedReader(new InputStreamReader(chatUsers.getInputStream()));
- pw = new PrintWriter(chatUsers.getOutputStream(),true);
- pw.println(cname);
- createInterface();
- new MessageThread().start();
- }
- public static void createInterface()
- {
- JFrame Frame = new JFrame();
- JLabel send = new JLabel("Send");
- cm = new JTextArea();
- cm.setRows(40);
- cm.setColumns(70);
- cip = new JTextField(50);
- JScrollPane scroll = new JScrollPane(cm, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
- Frame.add(scroll, "Center");
- JPanel bp = new JPanel(new FlowLayout());
- bp.add(cip);
- bp.add(send);
- bp.setBackground(new Color(240, 240, 240));
- Frame.add(bp, "North");
- send.addMouseListener(this);
- bp.setSize(200, 300);
- Frame.setVisible(true);
- Frame.setTitle("FN - Chat || Logged in as " + username + ". Server: " + cip);
- Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- Frame.pack();
- }
- public void actionPerformed(ActionEvent evt)
- {
- }
- public static void main(String args[])
- {
- String setUserName = JOptionPane.showInputDialog(null, "Username: ", JOptionPane.PLAIN_MESSAGE);
- String serverName = JOptionPane.showInputDialog(null, "Server: ", JOptionPane.PLAIN_MESSAGE);
- try
- {
- new Client(setUserName, serverName);
- }
- catch(Exception e)
- {
- System.out.println(e.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment