public void init() { add(intitule); add(texte); add(bouton); bouton.addActionListener(this); try { ORB orb = ORB.init(this, null); FileReader file = new FileReader(iorfile.value); BufferedReader in = new BufferedReader(file); String ior = in.readLine(); file.close(); org.omg.CORBA.Object obj = orb.string_to_object(ior); annuaire = AnnuaireHelper.narrow(obj); } catch (org.omg.CORBA.SystemException ex) { System.err.println("Error"); ex.printStackTrace(); } catch (FileNotFoundException fnfe) { System.err.println(fnfe.getMessage()); } catch (IOException io) { System.err.println(io.getMessage()); } catch (Exception e) { System.err.println(e.getMessage()); } }
public CryoBay reconnectServer(ORB o, ReconnectThread rct) { BufferedReader reader; File file; ORB orb; org.omg.CORBA.Object obj; orb = o; obj = null; cryoB = null; try { // instantiate ModuleAccessor file = new File("/vnmr/acqqueue/cryoBay.CORBAref"); if (file.exists()) { reader = new BufferedReader(new FileReader(file)); obj = orb.string_to_object(reader.readLine()); } if (obj != null) { cryoB = CryoBayHelper.narrow(obj); } if (cryoB != null) { if (!(cryoB._non_existent())) { // System.out.println("reconnected!!!!"); rct.reconnected = true; } } } catch (Exception e) { // System.out.println("Got error: " + e); } return cryoB; }
public ClientGui(ORB o) throws Exception { ShutdownFrame sf; BufferedReader reader; boolean modulePresent; File file; CryoThread update; orb = o; obj = null; cryoBay = null; // System.out.println("running test client."); // instantiate ModuleAccessor file = new File("/vnmr/acqqueue/cryoBay.CORBAref"); if (file.exists()) { reader = new BufferedReader(new FileReader(file)); obj = orb.string_to_object(reader.readLine()); } if (obj == null) { throw new Exception("string_to_object is null: cryoBay.CORBAref"); } // System.out.println("Got object."); cryoBay = CryoBayHelper.narrow(obj); if (cryoBay == null) { throw new Exception("cryoBay is null"); } if (cryoBay._non_existent()) { throw new Exception("cryoBay is not running"); } sf = new ShutdownFrame(cryoBay); update = new CryoThread(cryoBay, sf, this); sf.show(); update.start(); } /*end of constructor*/
private static void placeBid() { String ir = getRef(); double bid = 0; boolean correct = false; if (!ir.equals("cancel")) { while (!correct) { try { System.out.print("Please enter your bid in £ > "); String x = in.readLine(); bid = Double.parseDouble(x); correct = true; } catch (Exception e) { System.out.println("That's not correct"); } } System.out.println(a.placeBid(ir, loggedUser, bid)); } }
private static void newAuction() { boolean correct = false; String iName = ""; String iDesc = ""; while (!correct) { try { System.out.print("Please enter the items name > "); iName = in.readLine(); System.out.print("Please enter a description > "); iDesc = in.readLine(); correct = true; } catch (Exception e) { } } double minBid = 0; try { System.out.print("Please enter a minimum bid > "); minBid = Double.parseDouble(in.readLine()); } catch (Exception e) { System.out.println("Minimum bid has defaulted to 0."); } int days = 0; int hours = 0; int mins = 0; boolean correct2 = false; try { while (!correct2 && days >= 0 && hours >= 0 && mins >= 0) { System.out.print("Please enter the number of days that the Auction is running for > "); days = Integer.parseInt(in.readLine()); System.out.print("Please enter the number of hours in that day > "); hours = Integer.parseInt(in.readLine()); System.out.print("Please enter the number of minutes in that hour > "); mins = Integer.parseInt(in.readLine()); correct2 = true; } } catch (Exception e) { } long tte = days * 86400000 + hours * 3600000 + mins * 60000; Calendar cal = Calendar.getInstance(); Date d = cal.getTime(); tte = tte + d.getTime(); Random r = new Random(); int rnum = (int) tte % r.nextInt(9999); String iRef = loggedUser.substring(loggedUser.length() / 2) + rnum; a.addItem(new b(iRef, loggedUser, iName, iDesc, minBid, tte, 0.0, "")); }
private static String getRef() { boolean correct = false; b[] bArray = a.getAllItems(); String candidate = ""; while (!correct) { System.out.println("Please enter the reference code of the item you want to place a bid on."); System.out.print("Or type 'cancel' to cancel > "); try { candidate = in.readLine(); } catch (Exception e) { } if (!candidate.equals("cancel")) { for (int i = 0; i < bArray.length; i++) { if (bArray[i].itemRef.equals(candidate)) { return candidate; } } } else { return "cancel"; } } return "cancel"; }
public static void main(String[] args) { loggedUser = args[0]; try { ORB orb = ORB.init(args, null); // initialize ORB o = orb.resolve_initial_references("NameService"); // get reference to Deal object NamingContext ncRef = NamingContextHelper.narrow(o); NameComponent[] nc = new NameComponent[1]; nc[0] = new NameComponent(); nc[0].id = "Auction"; nc[0].kind = ""; a = AuctionHelper.narrow(ncRef.resolve(nc)); isr = new InputStreamReader(System.in); in = new BufferedReader(isr); int sel = 0; System.out.println("******* You have logged in Successfully! ********"); while (sel == 0) { System.out.println("Please make a selection"); System.out.println("\t1. Get all the listed auctions"); System.out.println("\t2. List a new item for auction."); System.out.println("\t3. Lookup an auction."); System.out.println("\t4. Place a bid on an auction."); System.out.println("\t5. Logout."); System.out.print("Please make your selection > "); String f = in.readLine(); try { sel = Integer.parseInt(f); } catch (Exception e) { sel = 42; } switch (sel) { case 1: allItems(); sel = 0; break; case 2: newAuction(); sel = 0; break; case 3: System.out.println("Stub"); sel = 0; break; case 4: placeBid(); sel = 0; break; case 5: a.logout(loggedUser); System.out.println("BYE!"); System.exit(0); default: System.out.println("You have not made a valid selection, please try again."); sel = 0; break; } } } catch (Exception e) { System.out.println("ERROR : " + e); e.printStackTrace(System.out); } }