📄 hello.java
字号:
/* * Copyright 2006 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */package com.google.gwt.sample.hello.client;import com.google.gwt.core.client.EntryPoint;import com.google.gwt.user.client.Window;import com.google.gwt.user.client.ui.Button;import com.google.gwt.user.client.ui.ClickListener;import com.google.gwt.user.client.ui.RootPanel;import com.google.gwt.user.client.ui.Widget;/** * HelloWorld application. */public class Hello implements EntryPoint { public void onModuleLoad() { Button b = new Button("Click me", new ClickListener() { public void onClick(Widget sender) { //Window.alert("Hello, AJAX"); bar(new Hello(), "Message sent to the bar native method from Java method"); } }); RootPanel.get().add(b); } // Add native JavaScript code. public static native void myalert(String msg) /*-{ $wnd.alert(msg); }-*/; // Instance and static fields which will be accessed from JavaScript code String myInstanceField = "Life is worth living with Passion!"; static String myStaticField; // Instance method void instanceFoo(String s) { myalert(s); } // Static method static void staticFoo(String s) { myalert(s); } // Native method in which Java methods and fields are accessed from the // JavaScript code. // public native void bar(Hello x, String s) /*-{ // Call instance method instanceFoo() on this this.@com.google.gwt.sample.hello.client.Hello::instanceFoo(Ljava/lang/String;)("The 1st " + s); // Call instance method instanceFoo() on x x.@com.google.gwt.sample.hello.client.Hello::instanceFoo(Ljava/lang/String;)("The 2nd " + s); // Call static method staticFoo() @com.google.gwt.sample.hello.client.Hello::staticFoo(Ljava/lang/String;)("The 3rd " + s); // Read instance field on this var val = this.@com.google.gwt.sample.hello.client.Hello::myInstanceField; @com.google.gwt.sample.hello.client.Hello::staticFoo(Ljava/lang/String;)("Instance field contains " + val); // Write instance field on x and read it again x.@com.google.gwt.sample.hello.client.Hello::myInstanceField = val + " Really!"; var val2 = x.@com.google.gwt.sample.hello.client.Hello::myInstanceField; @com.google.gwt.sample.hello.client.Hello::staticFoo(Ljava/lang/String;)("Instance field contains " + val2); // Write static field (no qualifier) and read it again @com.google.gwt.sample.hello.client.Hello::myStaticField = "Message from static field"; var val3 = @com.google.gwt.sample.hello.client.Hello::myStaticField; @com.google.gwt.sample.hello.client.Hello::staticFoo(Ljava/lang/String;)("Static field contains " + val3); }-*/;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -