import javax.swing.*; // for JFrame, JLabel, JPanel import java.awt.*; // for Graphics public class Ch13_13 // Draw a smiley face { public static void main(String[] args) // JLabel will be center-justified both horizontally and vertically { JFrame frame=new JFrame("Exercise12_1"); // establish title for JFrame frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // establish what to do if JFrame is closed frame.setSize(700,700); // set size to something reasonable for this GUI Smile s=new Smile(); // create the JPanel which will draw the smiley face frame.add(s); // insert the JPanel into the JFrame and make the JFrame visible frame.setVisible(true); } public static class Smile extends JPanel { public void paintComponent(Graphics g) // draw a smiley face { g.drawOval(25,25,500,500); // draw the outline of the face g.drawOval(140,120,120,50); // draw the outer part of the left eye g.fillOval(185,130,30,30); // fill in the iris g.drawOval(290,120,120,50); // draw the outer part of the right eye g.fillOval(335,130,30,30); // fill in the iris g.drawLine(275,200,200,315); // draw the nose g.drawLine(200,315,350,315); g.drawLine(350,315,275,200); g.drawArc(200,280,150,150,190,160); // draw the smile } } }