・VRMLソース (m-hiway.wrl) #VRML V2.0 utf8 ・・・・ DEF HANDLE-Sc Script { ・・・・ eventOut SFInt32 nscore ・・・・ url "javascript: ・・・・ nscore=score*100; ・・・・ " } ・・・・ [EOF] ・JAVAソース (mhwhsc.java) import java.awt.*; import java.awt.event.*; import java.applet.*; import vrml.external.exception.*; import vrml.external.field.*; import vrml.external.Node; import vrml.external.Browser; public class mhwhsc_b extends Applet implements EventOutObserver, AdjustmentListener { Browser browser=null; Node score_node=null; Node handle_node=null; EventOutSFInt32 score; EventInSFVec3f translation; EventInSFVec3f scale; Label tx1=new Label(" SCORE"); Label sc1=new Label(" 0"); Label tx2=new Label("HIGH SCORE"); Label sc2=new Label("0"); Label tx3=new Label("Steering size x1.0"); Scrollbar sb1=new Scrollbar(Scrollbar.HORIZONTAL,10,3,5,23); int hisc; float[] padtf={0, 0, 0}; float[] padsc={1, 1, 1}; public void init() { hisc=0; setLayout(new GridLayout(2,3)); add(tx1); add(tx2); add(tx3); add(sc1); add(sc2); add(sb1); sb1.addAdjustmentListener(this); repaint(); try { browser=Browser.getBrowser(this); } catch (Exception e) {} } public void start() { padtf[1]=(float) 0; padsc[0]=padsc[1]=(float) 1; //Connect VRML Browser System.out.println("Connecting now..."); for (int i=0; i<30; i++) { if (browser!=null) break; System.out.println(""+(30-i)+" seconds to the time limit."); try { try { Thread.sleep(1000); } catch(InterruptedException e) { break; } browser=Browser.getBrowser(this); } catch (Exception e) {} } if (browser==null) { System.out.println("I failed connection with this VRML browser."); tx1.setText("Sorry. I failed"); tx2.setText("connection with"); tx3.setText("this VRML browser."); } else { System.out.println("I successed connection with this VRML browser."); //Get Node for (int i=0; i<30; i++) { try { try { Thread.sleep(1000); } catch(InterruptedException e) { break; } score_node=browser.getNode("HANDLE-Sc"); handle_node=browser.getNode("HANDLE-Tf"); } catch (InvalidNodeException e) {} if (score_node!=null && handle_node!=null) break; System.out.println(""+(30-i)+" seconds to the time limit."); } if (score_node==null || handle_node==null) { System.out.println("But, I was not able to find nodes."); tx1.setText("Sorry. I successed"); tx2.setText("connection with"); tx3.setText("this VRML browser."); sc1.setText("But, I was not able to"); sc2.setText("find nodes."); } else { System.out.println("I could find nodes."); //Get eventOut score=(EventOutSFInt32) score_node.getEventOut("nscore"); score.advise(this,new Integer(1)); //Get eventIn translation=(EventInSFVec3f) handle_node.getEventIn("set_translation"); scale=(EventInSFVec3f) handle_node.getEventIn("set_scale"); //display initialize sb1.setValue(10); sc1.setText(" 0"); tx3.setText("Steering size x1.0"); } } } public void callback(EventOut val, double eT, Object data) { Integer Num=(Integer) data; if (Num.intValue()==1) { int scr=score.getValue(); if (scr>hisc) { hisc=scr; } sc1.setText(" "+scr); sc2.setText(""+hisc); } } public void adjustmentValueChanged (AdjustmentEvent e) { Scrollbar s=(Scrollbar) e.getSource(); double advalue=(double) s.getValue(); padtf[1]=(float) ((advalue-10)/500); padsc[0]=padsc[2]=(float) (advalue/10); translation.setValue(padtf); scale.setValue(padsc); tx3.setText("Steering size x"+(advalue/10)); } public int getHighScore() { return hisc; } } [EOF] ・HTML(vr2jv2jswin.htm) VRML -> JAVA -> JavaScript
JAVA Applet

 
VRML

 
JavaScript
ハイスコアを取得して親ウィンドウに送信
 
[EOF] ----------------------------------------------------------------------------------------------- 2000/4/23 初公開 2000/10/27 ロード中の場合、JAVAが有効になっていない場合、JavaScriptがJAVAを見に行かないように、HTML(JavaScript)を書き換えました。 2001/10/20 ゲーム画面を別ウィンドウにし、複種類のプラグインを立ち上げ可能にしました。 但し、どのプラグインでもJAVAと接続出来るわけではありません。 2002/2/22 より確実にJAVAアプレットがVRMLブラウザーに接続できるように、JAVAプログラムを改良しました。 プラグイン選択を削除しました。 2007/6/5 Morning!Highwayのファイル名を最新の m-hiway_f.wrl に更新し、正常に表示できるようにしました。