⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 catalogtestclient1.java~8~

📁 Java源码 Java源码
💻 JAVA~8~
字号:
package cmp2image;

import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.util.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class CatalogTestClient1
    extends JFrame {
  private CatalogHome catalogHome = null;
  String name;
  Image flowerImage;
  //Construct the EJB test client
  public CatalogTestClient1(String title) {
   super(title);
    initialize();
  }

  public void initialize() {
    try {
      //get naming context
      Context context = getInitialContext();

      //look up jndi name
      Object ref = context.lookup("Catalog");
      //look up jndi name and cast to Home interface
      catalogHome = (CatalogHome) PortableRemoteObject.narrow(ref, CatalogHome.class);
      Catalog catalog = catalogHome.create();
      ArrayList collection = catalog.findOne("AfricanOrchid");
      Iterator i = collection.iterator();
      Flower flower = null;
      System.out.println("Invento");
      while (i.hasNext()) {
        Object obj = i.next();
        if (obj instanceof String)
        {
          name = (String) obj;
          System.out.println("flowerName: " + name);
        }

      }
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  public void paint(Graphics g) {
    Font ft1 = new Font("TimesRoman", Font.BOLD, 25);
    g.setFont(ft1);
    String str = "The Flower Name:  " + name;
    g.drawString(str, 50, 50);
    g.drawImage(flowerImage, 70, 80, this);
  }

  private Context getInitialContext() throws Exception {
    String url = "t3://zhb:7001";
    String user = null;
    String password = null;
    Properties properties = null;
    try {
      properties = new Properties();
      properties.put(Context.INITIAL_CONTEXT_FACTORY,
                     "weblogic.jndi.WLInitialContextFactory");
      properties.put(Context.PROVIDER_URL, url);
      if (user != null) {
        properties.put(Context.SECURITY_PRINCIPAL, user);
        properties.put(Context.SECURITY_CREDENTIALS,
                       password == null ? "" : password);
      }

      return new InitialContext(properties);
    }
    catch (Exception e) {
      System.out.println("Unable to connect to WebLogic server at " + url);
      System.out.println("Please make sure that the server is running.");
      throw e;
    }
  }

  //----------------------------------------------------------------------------
  // Utility Methods
  //----------------------------------------------------------------------------

  public CatalogHome getHome() {
    return catalogHome;
  }


  //Main method

  public static void main(String[] args) {
    CatalogTestClient1 win1 = new CatalogTestClient1("CatalogTestClient1");
              win1.setSize(400,400);
                win1.setVisible(true);
                win1.addWindowListener(new WindowClose());
  }
}
class WindowClose extends WindowAdapter
 {
         public void windowClosing(WindowEvent e)
         {
               System.exit(0);
         }
 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -