このコンボボックスを用いて, (例えば,黒,赤,緑,青などの) 描画色を選択できる機能を追加せよ.
g.clearRect(x, y, width, height)
(x, y) を頂点とする幅width, 高さheightの長方形領域を消去する.
private void jButton1Action ...() { |
Graphics g = buffer.getGraphics(); |
g.clearRect(0,0, buffer.getWidth(jPanel1), buffer.getHeight(jPanel1)); |
path = null; // 直線の描画を行わないように path
を消去する |
} |
int getSelectedIndex()
選択されている項目の番号(先頭は0)を返す.
項目を編集することで,表示する文字列と項目数を設定する.
Color color = Color.RED; // 初期値を赤にしておく
デザイン画面内でコンボ・ボックスのイベントをイベント・リスナに登録する
「イベント」「item」
「itemStateChanged」
int n = jComboBox1.getSelectedIndex();
if(n == 0) color = Color.RED; |
else if(n == 1) ... |
... |
あるいは |
switch(n) { |
case 0: |
color = Color.RED; |
... |
g2.setColor(color);