Canvasコンポーネント
サンプルコード
class SampleFrame extends Frame {
public SampleFrame(String title) {
super(title);
this.setSize(300, 100);
SampleCanvas sampleCanvas = new SampleCanvas();
this.add(sampleCanvas);
this.setVisible(true);
}
}
class SampleCanvas extends Canvas {
public void paint(Graphics g) {
g.drawLine(10, 10, 100, 50);
}
}
画像ファイルの描画
class SampleCanvas extends Canvas {
public void paint(Graphics g) {
try {
BufferedImage image = ImageIO.read(new File("sample.bmp"));
g.drawImage(image, 10, 20, null);
} catch (IOException e) {
e.printStackTrace();
}
}
}