PaintTool.java



/** 簡単なペイントツール PaintToolの本体 */
import java.awt.*;
import javax.swing.*;
public class PaintTool extends JFrame {

 /** 部品となるコンポーネントのオブジェクト */
    public PaintCanvas canvas;
    public ControlPanel panel;

 /** 線の色と形状を記憶するオブジェクト */
    public Pen pen;

 /** コンストラクタ */
    public PaintTool() {
        super( "Paint Tool with JDK 1.2" );
        canvas = new PaintCanvas();
        canvas.setSize( 600, 400 );
        pen = new Pen();
        canvas.setPen( pen );
        panel = new ControlPanel();
        Container pane = getContentPane();
        pane.setLayout( new BorderLayout() );
        pane.add( canvas, "Center" );
        pane.add( panel, "South" );

        ColorAdapter cadapter = new ColorAdapter( pen );
        LineStyleAdapter sadapter = new LineStyleAdapter( pen );
        LineWidthAdapter wadapter = new LineWidthAdapter( pen );
        panel.addColorListener( cadapter );
        panel.addLineStyleListener( sadapter );
        panel.addLineWidthListener( wadapter );

        pack();
        setVisible( true );
    }
 
 /** 起動時に呼び出されるメソッド */
    public static void main( String argv[] ) {
        PaintTool tool = new PaintTool();
    }
}