1 7 package poker.spec; 8 9 import java.lang.reflect.Constructor ; 10 11 public class PokerGameFactory { 12 13 16 private PokerGameFactory() { 17 } 18 19 22 public static PokerGame getPokerGame(String fullClassName) { 23 24 PokerGame result = null; 25 26 Class objectClass = null; 27 28 try { 29 31 32 objectClass = Class.forName(fullClassName); 33 34 result = (PokerGame)objectClass.newInstance(); 35 36 37 38 } catch (Exception ex) { 39 System.out.println("Error on creating the object" + ex); 40 } 41 42 return result; 43 } 44 45 48 public static PokerGame getPokerGame(String fullClassName,String username,String pw,String id,int cash) { 49 50 PokerGame result = null; 51 52 Class objectClass = null; 53 54 try { 55 57 objectClass = Class.forName(fullClassName); 58 59 Class [] parameterTypes =new Class [4]; 60 61 parameterTypes[0]= String .class; 62 parameterTypes[1]= String .class; 63 parameterTypes[2]= String .class; 64 parameterTypes[3]= int.class; 65 66 Constructor constr = objectClass.getConstructor(parameterTypes); 67 68 69 70 Object [] objects = new Object [4]; 71 objects[0]=username; 72 objects[1]=pw; 73 objects[2]=id; 74 objects[3]=new Integer (cash); 75 76 Object obj = constr.newInstance(objects); 77 78 return (PokerGame)obj; 79 80 81 82 83 } catch (Exception ex) { 84 System.out.println("Error on creating the object" + ex); 85 } 86 87 return result; 88 } 89 90 91 92 93 94 95 96 97 } | Popular Tags |