import java.awt.*; import java.awt.event.*; import java.awt.geom.*; public class HorizontalBarMeter extends BarMeter { protected AffineTransform trans; public Dimension getMinimumSize(){ return new Dimension(100, 50); } public void createBufferImage(){ // アプレットのサイズをえる Dimension size = this.getSize(); // 回転をさせるために、高さと幅を入れ替える height = size.width; width = size.height; // 90度回転 AffineTransform rotate = AffineTransform.getRotateInstance(Math.toRadians(90), 0.0, 0.0); // 移動 trans = AffineTransform.getTranslateInstance(height, 0.0); // 回転と移動を組み合わせる trans.concatenate(rotate); // イメージの生成 if(width != 0 && height != 0){ image = this.createImage(width, height); graphics = image.getGraphics(); } } public void paint(Graphics g){ // ダブルバッファリング用のイメージがなければ、 // 生成し、グラフィックコンテキストをえる。 if(image == null || resizeFlag){ createBufferImage(); resizeFlag = false; } // 背景色で塗りつぶす graphics.setColor(this.getBackground()); graphics.fillRect(0, 0, width, height); // バーの描画 drawBar(graphics, value); // Java2D のグラフィックコンテキストに変換 Graphics2D g2 = (Graphics2D)g; // イメージバッファの描画 g2.drawImage(image, trans, this); } }