public void paint(Graphics g) | |
|
super.paint(g); |
|
if(buffer != null} { |
|
Graphics gPanel = jPanel1.getGraphics(); |
|
gPanel.drawImage(buffer, 0, 0, this); |
|
Graphics2D g2 = (Graphics2D)jPanel1.getGraphics(); |
|
myDraw(g2); // パネル内に直線を書き加える |
|
} |
|
} |
void myDraw(Graphics2D g2)
は変更前のpaintメソッド内での直線の描画と同様であり, 次のようなプログラムで実現できる.
private void myDraw(Graphics2D g2) { |
|
if(path != null) { |
|
g2.setColor(Color.RED); |
|
g2.setStroke(new BasicStroke((float)jSlider1.getValue())); |
|
g2.draw(path); |
|
} |
|
} |
このメソッドも,今作成している MyFrameクラス内の適当な場所に定義する.