Gwt-simplepanel-widget
GWT-SimplePanelウィジェット
前書き
*SimplePanel* ウィジェットは、1つのウィジェットのみを含むパネルの基本クラスを表します。
クラス宣言
以下は com.google.gwt.user.client.ui.SimplePanel クラスの宣言です-
public class SimplePanel
extends Panel
implements HasOneWidget
クラスコンストラクター
Sr.No. | Constructor & Description |
---|---|
1 |
SimplePanel() コンテンツにDIVを使用する空のパネルを作成します。 |
2 |
protected SimplePanel(Element elem) コンテンツに指定されたブラウザー要素を使用する空のパネルを作成します。 |
クラスメソッド
Sr.No. | Function name & Description |
---|---|
1 |
void add(Widget w) このパネルにウィジェットを追加します。 |
2 |
protected Element getContainerElement() このメソッドをオーバーライドして、ルート要素以外の要素がパネルの子ウィジェットのコンテナになるように指定します。 |
3 |
Widget getWidget() パネルの子ウィジェットを取得します。 |
4 |
java.util.Iterator<Widget> iterator() 含まれるウィジェットの反復子を取得します。 |
5 |
boolean remove(Widget w) 子ウィジェットを削除します。 |
6 |
void setWidget(IsWidget w) レシーバーの唯一のウィジェットを設定し、以前のウィジェットがあればそれを置き換えます。 |
7 |
void setWidget(Widget w) このパネルのウィジェットを設定します。 |
継承されるメソッド
このクラスは、次のクラスからメソッドを継承します-
- com.google.gwt.user.client.ui.UIObject
- com.google.gwt.user.client.ui.Widget
- com.google.gwt.user.client.ui.Panel
- java.lang.Object
SimplePanelウィジェットの例
この例では、GWTでSimplePanelウィジェットの使用方法を示す簡単な手順を紹介します。 次の手順に従って、_GWTで作成したGWTアプリケーションを更新します-アプリケーションの作成_の章-
Step | Description |
---|---|
1 | Create a project with a name HelloWorld under a package com.finddevguides as explained in the GWT - Create Application chapter. |
2 | Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorldl and HelloWorld.java as explained below. Keep rest of the files unchanged. |
3 | Compile and run the application to verify the result of the implemented logic. |
以下は、変更されたモジュール記述子 src/com.finddevguides/HelloWorld.gwt.xml の内容です。
<?xml version = "1.0" encoding = "UTF-8"?>
<module rename-to = 'helloworld'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name = 'com.google.gwt.user.User'/>
<!-- Inherit the default GWT style sheet. -->
<inherits name = 'com.google.gwt.user.theme.clean.Clean'/>
<!-- Specify the app entry point class. -->
<entry-point class = 'com.finddevguides.client.HelloWorld'/>
<!-- Specify the paths for translatable code -->
<source path = 'client'/>
<source path = 'shared'/>
</module>
以下は、変更されたスタイルシートファイル war/HelloWorld.css の内容です。
body {
text-align: center;
font-family: verdana, sans-serif;
}
h1 {
font-size: 2em;
font-weight: bold;
color: #777777;
margin: 40px 0px 70px;
text-align: center;
}
以下は、変更されたHTMLホストファイル war/HelloWorldl の内容です。
<html>
<head>
<title>Hello World</title>
<link rel = "stylesheet" href = "HelloWorld.css"/>
<script language = "javascript" src = "helloworld/helloworld.nocache.js">
</script>
</head>
<body>
<h1>SimplePanel Widget Demonstration</h1>
<div id = "gwtContainer"></div>
</body>
</html>
SimplePanelウィジェットの使用法を示すJavaファイル src/com.finddevguides/HelloWorld.java の内容を見てみましょう。
package com.finddevguides.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SimplePanel;
public class HelloWorld implements EntryPoint {
public void onModuleLoad() {
//Create a Simple Panel
SimplePanel simplePanel = new SimplePanel();
Label label = new Label("A Simple Label.");
//add label to simple panel
simplePanel.add(label);
//set height and width of simple panel
simplePanel.setHeight("200");
simplePanel.setWidth("200");
DecoratorPanel decoratorPanel = new DecoratorPanel();
decoratorPanel.add(simplePanel);
//Add the widgets to the root panel.
RootPanel.get().add(decoratorPanel);
}
}
すべての変更が完了したら、link:/gwt/gwt_create_application [GWT-アプリケーションの作成]の章で行ったように、アプリケーションをコンパイルして開発モードで実行します。 すべてがあなたのアプリケーションでうまくいけば、これは次の結果を生成します-