IBM®
跳转到主要内容
    中国 [选择]    使用条款
 
 
Select a scope:Search for:    
    首页    产品    服务与解决方案     支持与下载    个性化服务    
跳转到主要内容

developerWorks 中国  >  Open source | Java technology  >

创建 Geronimo 客户机应用程序

利用 Geronimo 的客户机应用程序容器或者自己创建客户机应用程序

developerWorks

返回文章


CatClient.java,通过 Geronimo 客户机应用程序容器访问 CategoryEntityBean 以获得种类数据
				
package com.ibm.dw.reallybigpet.client;
import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;
import com.ibm.dw.reallybigpet.ejb.cmp.CategoryHome;
import com.ibm.dw.reallybigpet.ejb.cmp.CategoryRemote;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.rmi.PortableRemoteObject;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
public class CatClient extends JFrame {
	public CatClient(String title) {
		super(title);
	}
	public void init() {
		JList catList = new JList(getCats());		
		JPanel pane = new JPanel();
		pane.setLayout(new BorderLayout());
		pane.add(catList, BorderLayout.CENTER);
		this.getContentPane().add(pane);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	private Vector getCats() {
		Vector cats = new Vector();
		Collection coll = null;
		CategoryRemote cr = null;
		try {
			Context ic = new InitialContext();
			Object o = ic.lookup("java:comp/env/ejb/CategoryEntityBean");
			CategoryHome home = (CategoryHome) PortableRemoteObject.narrow(o,
					CategoryHome.class);
			coll = home.findAll();
			Iterator it = coll.iterator();
			while (it.hasNext()) {
				cr = (CategoryRemote) it.next();
				cats.add("Cat id= " + cr.getId() + ";  Name= " + cr.getName());
			} // of while
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return cats;
	}
	public static void main(String[] args) {
		CatClient lc = new CatClient("Really Big Pet Store Categories");
		lc.init();
		lc.setSize(350, 150);
		lc.setVisible(true);
	}
}

返回文章

    关于 IBM 隐私条约 联系 IBM 使用条款