package swingExamples; import javax.swing.*; import java.awt.*; public class PaintDemo { private JFrame frame; private class PaintPanel extends JPanel { // called by the system when necessary public void paintComponent(Graphics g ) { super.paintComponent(g); ImageIcon antIcon = new ImageIcon("ant.jpg"); Image antImage = antIcon.getImage( ); g.drawImage(antImage, 3, 4, this); g.fillOval(3, 4, 50, 50); // x, y, width, height } } public PaintDemo() { frame = new JFrame("Paint Demo"); frame.setSize( 300, 300); frame.setLocation( 200, 200); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // create the Panel on which the image will be displayed PaintPanel paintPanel = new PaintPanel(); frame.add(BorderLayout.CENTER, paintPanel); } public void launch( ) { frame.setVisible(true); } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub PaintDemo demo = new PaintDemo( ); demo.launch( ); } }