Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.codingllamas;
- import java.awt.Color;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.URL;
- import java.net.URLConnection;
- import java.util.ArrayList;
- import java.util.Collection;
- import javax.swing.DefaultListModel;
- import javax.swing.ImageIcon;
- import javax.swing.JLabel;
- import javax.swing.JTextArea;
- import org.jivesoftware.smack.ConnectionConfiguration;
- import org.jivesoftware.smack.Roster;
- import org.jivesoftware.smack.RosterEntry;
- import org.jivesoftware.smack.XMPPConnection;
- import org.jivesoftware.smack.XMPPException;
- public class start {
- static XMPPConnection connection;
- static ArrayList<String> testing = new ArrayList<String>();
- static gui ui = new gui();
- public static void main(String[] args){
- gui.start();
- listeners();
- }
- public static void listeners(){
- gui.window.addWindowListener(new WindowAdapter(){
- public void windowClosing(WindowEvent e){
- System.exit(0);
- }
- });
- gui.login.addMouseListener(new MouseListener(){
- public void mouseClicked(MouseEvent arg0) {}
- public void mouseEntered(MouseEvent arg0) {
- gui.login.setIcon(gui.selected);
- }
- public void mouseExited(MouseEvent arg0) {
- gui.login.setIcon(new ImageIcon(gui.loginurl));
- }
- public void mousePressed(MouseEvent arg0) {}
- public void mouseReleased(MouseEvent arg0) {
- String username = gui.username.getText();
- String password = gui.password.getText();
- try {
- login(username,password);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- public static void login(String userName, String password) throws XMPPException {
- ConnectionConfiguration config = new ConnectionConfiguration("chat.facebook.com",5222,"Work");
- connection = new XMPPConnection(config);
- try{
- connection.connect();
- connection.login(userName, password);
- System.out.println("Login Successful");
- //gui.removeAll();
- URL temp = start.class.getResource("slate.png");
- gui.window.remove(gui.password);
- gui.window.remove(gui.username);
- gui.window.remove(gui.login);
- gui.window.remove(gui.failed);
- gui.window.setContentPane(new JLabel(new ImageIcon(temp)));
- gui.window.setBackground(new Color(27,27,27));
- System.out.println("Reached 1");
- //displayBuddyList();
- System.out.println("Reached 2");
- gui.list2.setText("text test");
- System.out.println("Reached 3");
- gui.list2.setVisible(true);
- }
- catch(Exception e){
- gui.failed.setVisible(true);
- }
- }
- public static void displayBuddyList() {
- Roster roster = connection.getRoster();
- Collection<RosterEntry> entries = roster.getEntries();
- //String[] test = (String[]) entries.toArray(new String[entries.size()]);
- //System.out.println("\n\n" + entries.size() + " buddy(ies):");
- for(RosterEntry r:entries){
- //for(int i=0; i<test.length; i++)
- //System.out.println(r.getUser());
- //System.out.println(test[i]);
- testing.add(r.getUser());
- }
- //System.out.println(testing);
- String[] test1 = testing.toArray(new String[0]);
- gui.bar.setMaximum(test1.length-1);
- //DefaultListModel listModel = new DefaultListModel();
- for(int temping = 0; 0 < test1.length; temping++){
- test1[temping] = test1[temping].replaceFirst("-","");
- test1[temping] = test1[temping].replace("@chat.facebook.com","");
- //System.out.println(temping + ": " + test1[temping]);
- test1[temping] = thingy(test1[temping]);
- System.out.println(temping + ": " + test1[temping]);
- //gui.list.setListData(test1);
- //listModel.addElement(test1[temping]);
- String tempstring = gui.list2.getText();
- gui.list2.setText(tempstring + test1[temping] + "\n");
- gui.bar.setValue(temping);
- }
- gui.list.setListData(test1);
- gui.window2.add(gui.list);
- gui.window2.setSize(500,800);
- gui.window2.setVisible(true);
- System.out.println("DONE!");
- //System.out.println(test1[4]);
- }
- public static String thingy(String temp){
- String test;
- try {
- URL url = new URL("http://graph.facebook.com/" + temp);
- URLConnection connection = url.openConnection();
- BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
- String test2 = in.readLine();
- String[] testparts = test2.split("\"");
- test = testparts[7];
- return test;
- }
- catch (Exception e){
- test = "ERROR";
- return test;
- }
- }
- }
- ----------------------------------------------------------
- package org.codingllamas;
- import java.awt.Color;
- import java.awt.Font;
- import java.net.URL;
- import javax.swing.ImageIcon;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JList;
- import javax.swing.JPasswordField;
- import javax.swing.JProgressBar;
- import javax.swing.JTextArea;
- import javax.swing.JTextField;
- public class gui {
- static JFrame window = new JFrame("MessageRunner");
- static URL firsturl = start.class.getResource("messager.png");
- static JLabel firstscreen = new JLabel(new ImageIcon(firsturl));
- static JTextField username = new JTextField();
- static JPasswordField password = new JPasswordField();
- static URL iconurl = start.class.getResource("icon.png");
- static ImageIcon icon = new ImageIcon(iconurl);
- static URL loginurl = start.class.getResource("button.png");
- static JLabel login = new JLabel(new ImageIcon(loginurl));
- static URL loginselected = start.class.getResource("selected.png");
- static ImageIcon selected = new ImageIcon(loginselected);
- static URL failedurl = start.class.getResource("failed.png");
- static JLabel failed = new JLabel(new ImageIcon(failedurl));
- static JTextArea list2 = new JTextArea();
- static JList list = new JList();
- static JFrame window2 = new JFrame();
- static JProgressBar bar = new JProgressBar();
- public static void start(){
- window.setVisible(true);
- window.setSize(256,512);
- window.setResizable(false);
- window.setContentPane(firstscreen);
- window.setSize(262,538);
- window.setLayout(null);
- window.setIconImage(icon.getImage());
- window.add(username);
- window.add(password);
- window.add(bar);
- bar.setBounds(0,500,window.getWidth(),10);
- //bar.setOpaque(false);
- //bar.setBorder(null);
- bar.setForeground(Color.BLUE);
- username.setHorizontalAlignment(JTextField.CENTER);
- username.setBounds(16,168,220,25);
- username.setOpaque(false);
- username.setBorder(null);
- username.setForeground(new Color(110,234,252));
- username.setFont(new Font("Glametrix Light",Font.PLAIN,20));
- username.setText("username");
- password.setHorizontalAlignment(JTextField.CENTER);
- password.setBounds(16,206,220,25);
- password.setOpaque(false);
- password.setBorder(null);
- password.setForeground(new Color(110,234,252));
- //password.setFont(new Font("Glametrix Light",Font.PLAIN,30));
- password.setText("password");
- window.add(login);
- login.setBounds(50,250,161,80);
- window.add(failed);
- failed.setBounds(17,430,225,66);
- failed.setVisible(false);
- window.add(list2);
- list2.setBounds(0,0,window.getWidth(),window.getHeight());
- list2.setVisible(false);
- }
- public static void removeAll(){
- //window.removeAll();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement