All pastes #463413 Raw Edit

Something

public text v1 · immutable
#463413 ·published 2007-04-28 23:10 UTC
rendered paste body
import java.awt.BorderLayout;
import javax.swing.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.util.*;

class ChatFrame extends JFrame implements ActionListener {
	DataInputStream is;
	PrintStream os;
	String line;
	String line2;
	JTextField input;
	public ChatFrame() {
		Socket myClient;
		try {
			myClient = new Socket("irc.freenode.net",6667);
			is = new DataInputStream(myClient.getInputStream());
			os = new PrintStream(myClient.getOutputStream());
		} catch (Exception e) {
			System.out.println("Fatal Connection Error!! Exception caught: " + e);
		}
		 

		os.println("USER  DrIRC 8 *  : DrIRC v0.1 Alpha");
		os.println("NICK DrIRC");
		os.println("JOIN #betatest");

		
		setTitle("DrIRC");
		setLayout(new BorderLayout());
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setSize(550,400);
		setVisible(true);
		JTextArea textarea = new JTextArea("# Welcome to DrIRC Alpha.\n# Connecting to server...\n", 30, 50);
		JScrollPane viewer = new JScrollPane(textarea);
		add(viewer, BorderLayout.PAGE_START);
		input = new JTextField(20);
		add(input, BorderLayout.PAGE_END);
		input.addActionListener(this);
		pack();
		
           while (true) {
             try {
             	line = is.readLine();
             	if (line == null) {
             		textarea.setText(textarea.getText() + "# Disconnected from server.");
             		System.exit(0);	
             	} else if (line.startsWith("PING :")) {
             		String pingsend = line.substring(6).trim();
             		os.println("PONG " + pingsend);
             	}
             } catch (Exception e) {
             	System.out.println("Read/Write error: "+e);
             }
             textarea.setText(textarea.getText() + line + "\n");
           }  
		
	}
	
	public void actionPerformed(ActionEvent e) {
		String value = input.getText();
		if (value.startsWith("/me ")) {
			String action = value.substring(4).trim();
			os.println("privmsg #betatest ACTION " + action + "");
		} else {
			os.println("privmsg #betatest :"+value);
		}
		input.setText("");
	}
	
}