הלינקייה: מגזין חודשי למפתחים

רוצה לשמוע על כל האירועים, המדריכים, הקורסים והמאמרים שנכתבו החודש ?
הלינקייה הינו מגזין חופשי בעברית שמשאיר אותך בעניינים.
בלי ספאם. בלי שטויות. פעם בחודש אצלך בתיבה.

Facebook API Example

package controller;
 
import java.awt.event.ActionEvent;
import java.io.IOException;
 
import javax.swing.AbstractAction;
import javax.swing.JLabel;
import javax.swing.JTextField;
 
import model.FacebookModel;
 
public class SubmitAction extends AbstractAction {
	JTextField display;
	FacebookModel model;
	JLabel center;
 
	public SubmitAction(String text, JTextField display, FacebookModel model, JLabel center) {
		super(text);
 
		this.display = display;
		this.model = model;
		this.center = center;
	}
 
	public void actionPerformed(ActionEvent arg0) {
		try {			
			center.setIcon(model.getIconImage(display.getText()));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
 
	}
 
}
package model;
 
import java.io.IOException;
import java.net.URL;
 
import javax.swing.ImageIcon;
 
import com.tb.fb.Facebook;
import com.tb.fb.FacebookObject;
 
public class FacebookModel {
 
	public ImageIcon getIconImage(String id) throws IOException {
		String url = "http://graph.facebook.com/" + id + "/picture";
		URL pic = new URL(url);
 
		ImageIcon icon = new ImageIcon(pic);
		return icon;
	}
 
	public String [] getAlbumNames() {
		String [] albums = {"Hello", "Foo", "Bar" };
		return albums;
	}
}
 
package view;
 
import java.awt.BorderLayout;
import java.awt.event.MouseMotionAdapter;
import java.io.IOException;
 
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
 
import controller.RandomBGColorListener;
import controller.SubmitAction;
 
import model.FacebookModel;
 
public class FBFrame {
	private JFrame frame;
	private JTextField userid;
	private JButton    submit;
	private JLabel     center;
 
	private FacebookModel model;
 
	public FBFrame() throws IOException {
		model = new FacebookModel();
		setupUi();
	}
 
	public void setupUi() {
		frame = new JFrame("Facebooking");
		frame.setSize(300, 200);
		JPanel bottom = new JPanel();
		center = new JLabel();
 
		JPanel top = new JPanel();
		userid = new JTextField(10);
		submit = new JButton(new SubmitAction("Submit", this.userid, this.model, center));
 
		top.add(userid);
		top.add(submit);
 
		frame.add(center, BorderLayout.CENTER);
		frame.add(top, BorderLayout.NORTH);
		frame.add(bottom, BorderLayout.SOUTH);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);		
 
		this.userid.addKeyListener(new RandomBGColorListener(bottom));
	}
 
	static class Ml extends MouseMotionAdapter {
 
	}
 
	class Hello extends MouseMotionAdapter {
 
	}
 
	public static void main(String [] args) throws IOException {
		new FBFrame();
	}
}
course: