Canvas クラス
- [内容]
- Canvas は,空白の矩形です.アプリケーションはその上に図を描いたり,また,ユーザからの入力イベントを受け取ることができます.
- [コンストラクタ]
- public Canvas()
- Canvas オブジェクトを生成する
- [主なメソッド]
- public Graphics getGraphics() ( Component から継承)
- このコンポーネントのグラフィックスコンテキストを作成する.コンポーネントが現在表示可能でない場合は,null を返す.(参照: TextArea クラス)
- public Point getLocation() ( Component から継承)
- 現在の位置を返す(参照: Point クラス)
- public void paint(Graphics g)
- 描画
- public void paintAll(Graphics g) ( Component から継承)
- このコンポーネントおよびそのすべてのサブコンポーネントを描画
- public void repaint() ( Component から継承)
- public void repaint(int x, int y, int width, int height) ( Component から継承)
- public void repaint(long tm) ( Component から継承)
- public void repaint(long tm, int x, int y, int width, int height) ( Component から継承)
- 指定された矩形領域を,tm ミリ秒以内に再描画する
- public void setBackground(Color c) ( Component から継承)
- バックグラウンドカラーを設定する
- public void setForeground(Color c) ( Component から継承)
- フォアグラウンドカラーを設定する
- public void setLocation(int x, int y) ( Component から継承)
- public void setLocation(Point p) ( Component から継承)
- コンポーネントの位置を設定する(参照: Point クラス)
- public void setSize(int width, int height) ( Component から継承)
- public void setSize(Dimension d) ( Component から継承)
- コンポーネントの大きさを width( d.width ),height ( d.height ) に設定する ( Dimension については,プログラム例を参照)
- public void setVisible(boolean b) ( Component から継承)
- コンポーネントを表示,非表示にする
- [使用例]
- プログラム例は,canvas 上に黄色の正方形を表示し,マウスでボタンがクリックされる毎に,canvas を右へ移動していきます.

- プログラム例は,Canvas を ScrollPane に貼り付け,描いた図をスクロールして表示させています.
