Skip to content

Instantly share code, notes, and snippets.

@ochilab
Last active December 18, 2015 15:19
Show Gist options
  • Save ochilab/5803537 to your computer and use it in GitHub Desktop.
Save ochilab/5803537 to your computer and use it in GitHub Desktop.
GWTでHTML5Canvasを利用して図形を描画する際のサンプル。XMLファイルはUIBinderの記述方法です。 gwt.xmlには <inherits name='com.google.gwt.canvas.Canvas'/>が必要です。
Canvas canvas = Canvas.createIfSupported();
initWidget(uiBinder.createAndBindUi(this));
canvas.setWidth("800px");
canvas.setHeight("800px");
canvas.setCoordinateSpaceWidth(800);
canvas.setCoordinateSpaceHeight(800);
Context2d context = canvas.getContext2d();
context.fillRect(10, 10, 500, 500);
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:c="urn:import:com.google.gwt.canvas.client">
<ui:style>
</ui:style>
<g:HTMLPanel>
<c:Canvas ui:field="canvas"/>
</g:HTMLPanel>
</ui:UiBinder>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment