Name: EXPERTIRCPROGRAMMER 2007-08-25 22:31 ID:uQ2YpOJT
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class IRC extends JFrame implements ActionListener, KeyListener
{
String username;
JTextArea chatBox;
JScrollPane chatBoxScroll;
JMenu menu;
JMenuBar menuBar;
JMenuItem file;
JTextField userChat;
JButton send;
public IRC()
{
super("Single Person IRC");
setSize(600, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
username = JOptionPane.showInputDialog(null, "Username: ", "What is your username?", JOptionPane.QUESTION_MESSAGE);
menu = new JMenu("File");
menuBar = new JMenuBar();
file = new JMenuItem("Close");
file.addActionListener(this);
menu.add(file);
menuBar.add(menu);
setJMenuBar(menuBar);
JPanel pane = new JPanel();
chatBox = new JTextArea("* Welcome to IRC " + username, 10, 50);
chatBox.setLineWrap(true);
chatBox.setWrapStyleWord(true);
chatBox.setEditable(false);
chatBoxScroll = new JScrollPane(chatBox,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
pane.add(chatBoxScroll);
JPanel pane2 = new JPanel();
BoxLayout horizontal = new BoxLayout(pane2, BoxLayout.X_AXIS);
userChat = new JTextField(30);
userChat.addKeyListener(this);
pane2.add(userChat);
send = new JButton("Send");
send.addActionListener(this);
pane2.add(send);
FlowLayout flow = new FlowLayout();
setLayout(flow);
addKeyListener(this);
add(pane);
add(pane2);
this.setFocusable(true);
setVisible(true);
}
public void keyPressed(KeyEvent event)
{
char character = event.getKeyChar();
if(character == KeyEvent.VK_ENTER)
{
chatBox.append("\n* " + username + ": " + userChat.getText());
userChat.setText("");
}
}
public void keyReleased(KeyEvent event){}
public void keyTyped(KeyEvent event){}
public void actionPerformed(ActionEvent event)
{
Object source = event.getSource();
if(source == send)
{
chatBox.append("\n* " + username + ": " + userChat.getText());
userChat.setText("");
}
else if(source == file)
{
System.exit(1);
}
}
public static void main(String[] arguements)
{
IRC irc = new IRC();
}
}
import java.awt.event.*;
import javax.swing.*;
public class IRC extends JFrame implements ActionListener, KeyListener
{
String username;
JTextArea chatBox;
JScrollPane chatBoxScroll;
JMenu menu;
JMenuBar menuBar;
JMenuItem file;
JTextField userChat;
JButton send;
public IRC()
{
super("Single Person IRC");
setSize(600, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
username = JOptionPane.showInputDialog(null, "Username: ", "What is your username?", JOptionPane.QUESTION_MESSAGE);
menu = new JMenu("File");
menuBar = new JMenuBar();
file = new JMenuItem("Close");
file.addActionListener(this);
menu.add(file);
menuBar.add(menu);
setJMenuBar(menuBar);
JPanel pane = new JPanel();
chatBox = new JTextArea("* Welcome to IRC " + username, 10, 50);
chatBox.setLineWrap(true);
chatBox.setWrapStyleWord(true);
chatBox.setEditable(false);
chatBoxScroll = new JScrollPane(chatBox,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
pane.add(chatBoxScroll);
JPanel pane2 = new JPanel();
BoxLayout horizontal = new BoxLayout(pane2, BoxLayout.X_AXIS);
userChat = new JTextField(30);
userChat.addKeyListener(this);
pane2.add(userChat);
send = new JButton("Send");
send.addActionListener(this);
pane2.add(send);
FlowLayout flow = new FlowLayout();
setLayout(flow);
addKeyListener(this);
add(pane);
add(pane2);
this.setFocusable(true);
setVisible(true);
}
public void keyPressed(KeyEvent event)
{
char character = event.getKeyChar();
if(character == KeyEvent.VK_ENTER)
{
chatBox.append("\n* " + username + ": " + userChat.getText());
userChat.setText("");
}
}
public void keyReleased(KeyEvent event){}
public void keyTyped(KeyEvent event){}
public void actionPerformed(ActionEvent event)
{
Object source = event.getSource();
if(source == send)
{
chatBox.append("\n* " + username + ": " + userChat.getText());
userChat.setText("");
}
else if(source == file)
{
System.exit(1);
}
}
public static void main(String[] arguements)
{
IRC irc = new IRC();
}
}