All pastes #393837 Raw Edit

simple java irc clie

public java v1 · immutable
·published 2007-03-13 21:38 UTC
rendered paste body
import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.io.*;import java.net.*;public class MainGUI implements ActionListener {	public JPanel buttonPanel, textPanel, masterPanel, defaultPanel;	public JButton btnConnect, btnSend;	public JTextArea display;	public JTextField txtMessage;	public JTabbedPane tabbedPane;		public connectGUI con = new connectGUI();	public EditServerGUI edit = new EditServerGUI();		public String userName, realName, nickName;	public PrintWriter output;		public void guiRun() throws Exception {		userName = "rate";		realName = "I'm a Rater User!!";		nickName = "rUser";				Socket socket = new Socket("localhost", 6667);		BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));		output = new PrintWriter(socket.getOutputStream(), true);				while(true) {			String msg = input.readLine();			display.append(msg + "\n");						if (msg.indexOf("Checking Ident") != -1) {				output.println("USER " + userName + " * * :" + realName);				output.println("nick " + nickName);			} else if (msg.substring(0, 4).equalsIgnoreCase("ping")) {				output.println("pong " + msg.substring(5));			}		}	}		public void actionPerformed(ActionEvent e) {		if (e.getSource() == btnSend) {								if (txtMessage.getText().substring(0, 4).equalsIgnoreCase("join")) {				tabbedPane.addTab(txtMessage.getText().substring(5),					new JScrollPane(new JTextArea()));				output.println(txtMessage.getText());				display.append(txtMessage.getText() + "\n");			} else {				output.println("privmsg " + tabbedPane.getTitleAt(tabbedPane.getSelectedIndex()) + 					" " + txtMessage.getText());				//tabbedPane.getComponentAt(tabbedPane.getSelectedIndex()).append("asdf");				//System.out.println(tabbedPane.getComponentAt(tabbedPane.getSelectedIndex()));				//System.out.println(tabbedPane.getModel());			}		}	}		public JPanel getContent() {                masterPanel = new JPanel();        masterPanel.setLayout(new BorderLayout());                btnConnect = new JButton("Connect");        btnConnect.setEnabled(false);        btnConnect.addActionListener(this);        masterPanel.add(btnConnect, BorderLayout.NORTH);                display = new JTextArea();        display.setEditable(false);        display.setLineWrap(true);        defaultPanel = new JPanel();        defaultPanel.setLayout(new BorderLayout());        defaultPanel.add(new JScrollPane(display), BorderLayout.CENTER);                tabbedPane = new JTabbedPane();        tabbedPane.addTab("Status Tab", defaultPanel);        masterPanel.add(tabbedPane, BorderLayout.CENTER);                txtMessage = new JTextField(100);        btnSend = new JButton("Send");        btnSend.addActionListener(this);                textPanel = new JPanel();        textPanel.setLayout(new BorderLayout());        textPanel.add(txtMessage, BorderLayout.CENTER);        textPanel.add(btnSend, BorderLayout.EAST);        masterPanel.add(textPanel, BorderLayout.SOUTH);                return masterPanel;	}		public static void main(String[] args) throws Exception {        MainGUI main = new MainGUI();        JFrame f = new JFrame("Rater IRC Client");        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        f.getContentPane().add(main.getContent());        f.setSize(640,480);        f.setLocation(200,200);        f.setVisible(true);                main.guiRun();    }}