Created
August 19, 2012 18:22
-
-
Save jmurth1234/3396899 to your computer and use it in GitHub Desktop.
Halp plz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package rymate.irc; | |
import java.util.Scanner; | |
import javax.swing.JTextArea; | |
import org.pircbotx.PircBotX; | |
import org.pircbotx.hooks.Listener; | |
import org.pircbotx.hooks.ListenerAdapter; | |
import org.pircbotx.hooks.events.JoinEvent; | |
import org.pircbotx.hooks.events.MessageEvent; | |
public class IRCConnectionManager extends ListenerAdapter implements Listener { | |
private String activeChannel; | |
private PircBotX bot; | |
private RymateIRCUI ui; | |
public IRCConnectionManager(RymateIRCUI aThis) { | |
this.ui = aThis; | |
} | |
public void connect(String server) throws Exception { | |
bot = new PircBotX(); | |
bot.setName("rymate1234|test"); | |
bot.setLogin("rymate1234"); | |
bot.setVerbose(true); | |
bot.setVersion("Rymate IRC Client"); | |
bot.connect(server); | |
//bot.joinChannel("#GameMakingGuys"); | |
bot.getListenerManager().addListener(this); | |
} | |
@Override | |
public void onMessage(MessageEvent event) throws Exception { | |
String message = event.getMessage(); | |
System.out.println(event.getChannel().getName() + " - <" + event.getUser().getNick() + "> " + message); | |
// Get number of tabs | |
int count = ui.getTabs().getTabCount(); | |
// Get the properties of each tab | |
for (int i = 0; i < count; i++) { | |
// Get label | |
String label = ui.getTabs().getTitleAt(i); | |
//System.out.println(label); | |
if (label.equals("event.getChannel().getName()")) { | |
JTextArea text = (JTextArea) ui.getTabs().getTabComponentAt(i); | |
text.append("<" + event.getUser().getNick() + "> " + message + "\n"); | |
} | |
} | |
} | |
@Override | |
public void onJoin(JoinEvent event) throws Exception { | |
System.out.println("Joined " + event.getChannel().getName()); | |
} | |
public void setActiveChannel(String s) { | |
activeChannel = s; | |
} | |
public String getActiveChannel() { | |
return activeChannel; | |
} | |
public PircBotX getClient() { | |
return bot; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package rymate.irc; | |
import java.awt.GridLayout; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
import javax.swing.JComponent; | |
import javax.swing.JLabel; | |
import javax.swing.JPanel; | |
import javax.swing.JScrollPane; | |
import javax.swing.JTabbedPane; | |
import javax.swing.JTextArea; | |
/** | |
* | |
* @author rymate | |
*/ | |
public class RymateIRCUI extends javax.swing.JFrame { | |
/** | |
* Creates new form RymateIRCUI | |
*/ | |
public RymateIRCUI() { | |
initComponents(); | |
} | |
IRCConnectionManager conn; | |
/** | |
* This method is called from within the constructor to initialize the form. | |
* WARNING: Do NOT modify this code. The content of this method is always | |
* regenerated by the Form Editor. | |
*/ | |
@SuppressWarnings("unchecked") | |
// <editor-fold defaultstate="collapsed" desc="Generated Code"> | |
private void initComponents() { | |
jToolBar1 = new javax.swing.JToolBar(); | |
serverHost = new javax.swing.JTextField(); | |
joinServer = new javax.swing.JButton(); | |
inputBox = new javax.swing.JTextField(); | |
jTabbedPane1 = new javax.swing.JTabbedPane(); | |
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | |
jToolBar1.setRollover(true); | |
serverHost.setPreferredSize(new java.awt.Dimension(300, 26)); | |
jToolBar1.add(serverHost); | |
joinServer.setText("Connect!"); | |
joinServer.setFocusable(false); | |
joinServer.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); | |
joinServer.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); | |
joinServer.addMouseListener(new java.awt.event.MouseAdapter() { | |
public void mousePressed(java.awt.event.MouseEvent evt) { | |
joinServerMousePressed(evt); | |
} | |
}); | |
jToolBar1.add(joinServer); | |
inputBox.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
inputBoxActionPerformed(evt); | |
} | |
}); | |
jTabbedPane1.setTabPlacement(javax.swing.JTabbedPane.LEFT); | |
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); | |
getContentPane().setLayout(layout); | |
layout.setHorizontalGroup( | |
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 573, Short.MAX_VALUE) | |
.addComponent(inputBox, javax.swing.GroupLayout.Alignment.TRAILING) | |
.addComponent(jTabbedPane1) | |
); | |
layout.setVerticalGroup( | |
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() | |
.addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(inputBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) | |
); | |
pack(); | |
}// </editor-fold> | |
private void joinServerMousePressed(java.awt.event.MouseEvent evt) { | |
try { | |
conn = new IRCConnectionManager(this); | |
conn.connect(serverHost.getText()); | |
} catch (Exception ex) { | |
Logger.getLogger(RymateIRCUI.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
JTextArea ta = new JTextArea(""); | |
ta.setLineWrap(true); | |
JScrollPane text = new JScrollPane(ta); | |
text.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); | |
String motd = conn.getClient().getServerInfo().getMotd(); | |
ta.setText(motd); | |
jTabbedPane1.addTab(conn.getClient().getServer(), text); | |
} | |
private void inputBoxActionPerformed(java.awt.event.ActionEvent evt) { | |
if (inputBox.getText().startsWith("/join")) { | |
String s = inputBox.getText().replaceFirst("/join ", ""); | |
conn.getClient().joinChannel(s); | |
inputBox.setText(""); | |
JTextArea ta = new JTextArea(""); | |
ta.setLineWrap(true); | |
JScrollPane text = new JScrollPane(ta); | |
text.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); | |
jTabbedPane1.addTab(s, text); | |
} | |
} | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String args[]) { | |
/* Set the Nimbus look and feel */ | |
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> | |
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. | |
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html | |
*/ | |
try { | |
// for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { | |
// if ("Nimbus".equals(info.getName())) { | |
// javax.swing.UIManager.setLookAndFeel(info.getClassName()); | |
// break; | |
// } | |
// } | |
javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); | |
} catch (ClassNotFoundException ex) { | |
java.util.logging.Logger.getLogger(RymateIRCUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (InstantiationException ex) { | |
java.util.logging.Logger.getLogger(RymateIRCUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (IllegalAccessException ex) { | |
java.util.logging.Logger.getLogger(RymateIRCUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (javax.swing.UnsupportedLookAndFeelException ex) { | |
java.util.logging.Logger.getLogger(RymateIRCUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} | |
//</editor-fold> | |
/* Create and display the form */ | |
java.awt.EventQueue.invokeLater(new Runnable() { | |
public void run() { | |
new RymateIRCUI().setVisible(true); | |
} | |
}); | |
} | |
public JTabbedPane getTabs() { | |
return jTabbedPane1; | |
} | |
// Variables declaration - do not modify | |
private javax.swing.JTextField inputBox; | |
private javax.swing.JTabbedPane jTabbedPane1; | |
private javax.swing.JToolBar jToolBar1; | |
private javax.swing.JButton joinServer; | |
private javax.swing.JTextField serverHost; | |
// End of variables declaration | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment