Advertisement
Guest User

Untitled

a guest
Nov 28th, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.70 KB | None | 0 0
  1. package org.codingllamas;
  2.  
  3. import java.awt.Color;
  4. import java.awt.event.MouseEvent;
  5. import java.awt.event.MouseListener;
  6. import java.awt.event.WindowAdapter;
  7. import java.awt.event.WindowEvent;
  8. import java.io.BufferedReader;
  9. import java.io.IOException;
  10. import java.io.InputStreamReader;
  11. import java.net.URL;
  12. import java.net.URLConnection;
  13. import java.util.ArrayList;
  14. import java.util.Collection;
  15.  
  16. import javax.swing.DefaultListModel;
  17. import javax.swing.ImageIcon;
  18. import javax.swing.JLabel;
  19. import javax.swing.JTextArea;
  20.  
  21. import org.jivesoftware.smack.ConnectionConfiguration;
  22. import org.jivesoftware.smack.Roster;
  23. import org.jivesoftware.smack.RosterEntry;
  24. import org.jivesoftware.smack.XMPPConnection;
  25. import org.jivesoftware.smack.XMPPException;
  26.  
  27. public class start {
  28.    
  29.     static XMPPConnection connection;
  30.     static ArrayList<String> testing = new ArrayList<String>();
  31.     static gui ui = new gui();
  32.    
  33.     public static void main(String[] args){
  34.        
  35.         gui.start();
  36.        
  37.         listeners();
  38.        
  39.     }
  40.    
  41.    
  42.    
  43.     public static void listeners(){
  44.        
  45.         gui.window.addWindowListener(new WindowAdapter(){
  46.             public void windowClosing(WindowEvent e){
  47.                 System.exit(0);
  48.                
  49.             }
  50.            
  51.         });
  52.        
  53.         gui.login.addMouseListener(new MouseListener(){
  54.  
  55.             public void mouseClicked(MouseEvent arg0) {}
  56.             public void mouseEntered(MouseEvent arg0) {
  57.                 gui.login.setIcon(gui.selected);
  58.             }
  59.             public void mouseExited(MouseEvent arg0) {
  60.                 gui.login.setIcon(new ImageIcon(gui.loginurl));
  61.             }
  62.             public void mousePressed(MouseEvent arg0) {}
  63.             public void mouseReleased(MouseEvent arg0) {
  64.                 String username = gui.username.getText();
  65.                 String password = gui.password.getText();
  66.                 try {
  67.                     login(username,password);
  68.                 }
  69.                 catch (Exception e) {
  70.                     e.printStackTrace();
  71.                 }
  72.                
  73.             }
  74.            
  75.         });
  76.        
  77.     }
  78.    
  79.    
  80.      
  81.     public static void login(String userName, String password) throws XMPPException {
  82.        
  83.         ConnectionConfiguration config = new ConnectionConfiguration("chat.facebook.com",5222,"Work");
  84.         connection = new XMPPConnection(config);
  85.  
  86.         try{
  87.             connection.connect();
  88.             connection.login(userName, password);
  89.             System.out.println("Login Successful");
  90.             //gui.removeAll();
  91.            
  92.             URL temp = start.class.getResource("slate.png");
  93.            
  94.             gui.window.remove(gui.password);
  95.             gui.window.remove(gui.username);
  96.             gui.window.remove(gui.login);
  97.             gui.window.remove(gui.failed);
  98.             gui.window.setContentPane(new JLabel(new ImageIcon(temp)));
  99.             gui.window.setBackground(new Color(27,27,27));
  100.            
  101.             System.out.println("Reached 1");
  102.             //displayBuddyList();
  103.            
  104.             System.out.println("Reached 2");
  105.             gui.list2.setText("text test");
  106.             System.out.println("Reached 3");
  107.             gui.list2.setVisible(true);
  108.         }
  109.         catch(Exception e){
  110.             gui.failed.setVisible(true);
  111.         }
  112.    
  113.    
  114.     }
  115.    
  116.     public static void displayBuddyList() {
  117.         Roster roster = connection.getRoster();
  118.         Collection<RosterEntry> entries = roster.getEntries();
  119.         //String[] test = (String[]) entries.toArray(new String[entries.size()]);
  120.  
  121.         //System.out.println("\n\n" + entries.size() + " buddy(ies):");
  122.         for(RosterEntry r:entries){
  123.             //for(int i=0; i<test.length; i++)
  124.    
  125.             //System.out.println(r.getUser());
  126.             //System.out.println(test[i]);
  127.             testing.add(r.getUser());
  128.         }
  129.         //System.out.println(testing);
  130.         String[] test1 = testing.toArray(new String[0]);
  131.        
  132.         gui.bar.setMaximum(test1.length-1);
  133.        
  134.         //DefaultListModel listModel = new DefaultListModel();
  135.  
  136.         for(int temping = 0; 0 < test1.length; temping++){
  137.        
  138.             test1[temping] = test1[temping].replaceFirst("-","");
  139.             test1[temping] = test1[temping].replace("@chat.facebook.com","");
  140.             //System.out.println(temping + ": " + test1[temping]);
  141.             test1[temping] = thingy(test1[temping]);
  142.             System.out.println(temping + ": " + test1[temping]);
  143.             //gui.list.setListData(test1);
  144.             //listModel.addElement(test1[temping]);
  145.             String tempstring = gui.list2.getText();
  146.             gui.list2.setText(tempstring + test1[temping] + "\n");
  147.             gui.bar.setValue(temping);
  148.            
  149.         }
  150.        
  151.         gui.list.setListData(test1);
  152.         gui.window2.add(gui.list);
  153.         gui.window2.setSize(500,800);
  154.         gui.window2.setVisible(true);
  155.         System.out.println("DONE!");
  156.    
  157.         //System.out.println(test1[4]);    
  158.     }
  159.    
  160.     public static String thingy(String temp){
  161.         String test;
  162.        
  163.         try {
  164.        
  165.         URL url = new URL("http://graph.facebook.com/" + temp);
  166.        
  167.         URLConnection connection = url.openConnection();
  168.        
  169.         BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  170.        
  171.         String test2 = in.readLine();
  172.         String[] testparts = test2.split("\"");
  173.        
  174.         test  = testparts[7];
  175.        
  176.         return test;
  177.        
  178.         }
  179.        
  180.         catch (Exception e){
  181.             test = "ERROR";
  182.             return test;
  183.         }
  184.        
  185.     }
  186.    
  187. }
  188.  
  189. ----------------------------------------------------------
  190. package org.codingllamas;
  191.  
  192. import java.awt.Color;
  193. import java.awt.Font;
  194. import java.net.URL;
  195.  
  196. import javax.swing.ImageIcon;
  197. import javax.swing.JFrame;
  198. import javax.swing.JLabel;
  199. import javax.swing.JList;
  200. import javax.swing.JPasswordField;
  201. import javax.swing.JProgressBar;
  202. import javax.swing.JTextArea;
  203. import javax.swing.JTextField;
  204.  
  205. public class gui {
  206.  
  207.     static JFrame window = new JFrame("MessageRunner");
  208.     static URL firsturl = start.class.getResource("messager.png");
  209.     static JLabel firstscreen = new JLabel(new ImageIcon(firsturl));
  210.     static JTextField username = new JTextField();
  211.     static JPasswordField password = new JPasswordField();
  212.     static URL iconurl = start.class.getResource("icon.png");
  213.     static ImageIcon icon = new ImageIcon(iconurl);
  214.     static URL loginurl = start.class.getResource("button.png");
  215.     static JLabel login = new JLabel(new ImageIcon(loginurl));
  216.     static URL loginselected = start.class.getResource("selected.png");
  217.     static ImageIcon selected = new ImageIcon(loginselected);
  218.     static URL failedurl = start.class.getResource("failed.png");
  219.     static JLabel failed = new JLabel(new ImageIcon(failedurl));
  220.     static JTextArea list2 = new JTextArea();
  221.    
  222.     static JList list = new JList();
  223.     static JFrame window2 = new JFrame();
  224.    
  225.     static JProgressBar bar = new JProgressBar();
  226.    
  227.     public static void start(){
  228.        
  229.         window.setVisible(true);
  230.         window.setSize(256,512);
  231.         window.setResizable(false);
  232.         window.setContentPane(firstscreen);
  233.         window.setSize(262,538);
  234.         window.setLayout(null);
  235.         window.setIconImage(icon.getImage());
  236.        
  237.         window.add(username);
  238.         window.add(password);
  239.        
  240.         window.add(bar);
  241.         bar.setBounds(0,500,window.getWidth(),10);
  242.         //bar.setOpaque(false);
  243.         //bar.setBorder(null);
  244.         bar.setForeground(Color.BLUE);
  245.        
  246.         username.setHorizontalAlignment(JTextField.CENTER);
  247.         username.setBounds(16,168,220,25);
  248.         username.setOpaque(false);
  249.         username.setBorder(null);
  250.         username.setForeground(new Color(110,234,252));
  251.         username.setFont(new Font("Glametrix Light",Font.PLAIN,20));
  252.         username.setText("username");
  253.        
  254.         password.setHorizontalAlignment(JTextField.CENTER);
  255.         password.setBounds(16,206,220,25);
  256.         password.setOpaque(false);
  257.         password.setBorder(null);
  258.         password.setForeground(new Color(110,234,252));
  259.         //password.setFont(new Font("Glametrix Light",Font.PLAIN,30));
  260.         password.setText("password");
  261.        
  262.         window.add(login);
  263.         login.setBounds(50,250,161,80);
  264.        
  265.         window.add(failed);
  266.         failed.setBounds(17,430,225,66);
  267.         failed.setVisible(false);
  268.        
  269.         window.add(list2);
  270.         list2.setBounds(0,0,window.getWidth(),window.getHeight());
  271.         list2.setVisible(false);
  272.        
  273.     }
  274.    
  275.     public static void removeAll(){
  276.         //window.removeAll();
  277.     }
  278.    
  279. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement