import java.awt.*; import javax.swing.*; import java.awt.geom.*; public class Foo extends JFrame { private static final long serialVersionUID = 1L; private JPanel jContentPane = null; private JPanel jPanel = null; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub SwingUtilities.invokeLater(new Runnable() { public void run() { Foo thisClass = new Foo(); thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); thisClass.setVisible(true); } }); } /** * This is the default constructor */ public Foo() { super(); initialize(); } /** * This method initializes this * * @return void */ private void initialize() { this.setSize(300, 200); this.setContentPane(getJContentPane()); this.setTitle("JFrame"); } /** * This method initializes jContentPane * * @return javax.swing.JPanel */ private JPanel getJContentPane() { if (jContentPane == null) { jContentPane = new JPanel(); jContentPane.setLayout(new BorderLayout()); jContentPane.add(getJPanel(), BorderLayout.CENTER); } return jContentPane; } /** * This method initializes jPanel * * @return javax.swing.JPanel */ private JPanel getJPanel() { if (jPanel == null) { jPanel = new JPanel() { protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; Insets insets = getInsets(); // int w = getWidth() - insets.left - insets.right; int h = getHeight() - insets.top - insets.bottom; AffineTransform oldAT = g2.getTransform(); try { //Move the origin to bottom-left, flip y axis g2.scale(1.0, -1.0); g2.translate(0, -h - insets.top); int xpoints[] = { 20, 30, 30, 35, 25, 15, 20 }; int ypoints[] = { 10, 10, 30, 30, 45, 30, 30 }; int npoints = 7; g2.fillPolygon(xpoints, ypoints, npoints); } finally { //restore g2.setTransform(oldAT); } } }; jPanel.setLayout(new GridBagLayout()); } return jPanel; } }