import javax.swing.*; import java.awt.*; import static java.awt.Color.*; class ShapeTest extends JPanel { public ShapeTest() { setPreferredSize(new Dimension(200, 150)); } @Override public void paintComponent(Graphics g) { // ((Graphics2D)g).setRenderingHint( // RenderingHints.KEY_ANTIALIASING, // RenderingHints.VALUE_ANTIALIAS_ON); super.paintComponent(g); int[] xs = { 100, 137, 175, 175, 137, 100 }; int[] ys = { 5, 5, 30, 55, 55, 30 }; g.setColor(RED); g.drawLine(5, 5, 80, 55); g.setColor(GREEN); g.drawRect(5, 5, 75, 50); g.setColor(BLUE); g.fillOval(5, 75, 75, 50); g.setColor(ORANGE); g.drawPolygon(xs, ys, 6); g.setColor(CYAN); g.fillRect(90, 65, 75, 50); g.setColor(MAGENTA); g.fillRect(100, 75, 75, 50); g.setColor(YELLOW); g.fillRect(110, 85, 75, 50); } } void main() { SwingUtilities.invokeLater(() -> { JFrame frame = new JFrame("Graphics Sample!"); frame.add(new ShapeTest()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }); }