Polygon2D(http://codetter.com/?p=273)との組みあわせ
Polygon2D(http://codetter.com/?p=273)との組みあわせ
import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Point;import javax.swing.JFrame;import javax.swing.JPanel;public class Sample {public static void main(String[] args) {final Polygon2D polygon2d = new Polygon2D(new Point(40, 20), new Point(20, 80), new Point(80, 80));JPanel panel = new JPanel() {@Overridepublic void paintComponent(Graphics g) {/** ここでGraphics2Dにキャストしていいのかは微妙なところ・・・* インタフェースはGraphicsなので具象クラスがGrahpics2Dだとは本来限らないはず。*/((Graphics2D)g).draw(polygon2d);}};JFrame frame = new JFrame();frame.getContentPane().add(panel);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setBounds(20, 20, 100, 120);frame.setVisible(true);}}