效果图:
MyPanel.java
import java.awt.*;
class MyPanel extends Panel{
public void paint(Graphics g){
g.setColor(Color.yellow);
g.fillOval(123, 30, 30, 35);
g.fillOval(90, 70, 40, 10);
g.fillOval(90, 90, 45, 10);
g.fillOval(150, 70, 40, 10);
g.fillOval(150, 90, 45, 10);
g.fillOval(135, 105, 15, 40);
g.setColor(new Color(62,174,26));
g.fillOval(110, 50, 60, 70);
g.setColor(Color.white);
g.drawLine(120, 60, 130, 70);
g.drawLine(130, 70, 145, 70);
g.drawLine(145, 70, 160, 60);
g.drawLine(130, 70, 130, 90);
g.drawLine(130, 90, 115, 100);
g.drawLine(130, 90, 145, 90);
g.drawLine(145, 90, 165, 100);
g.drawLine(145, 90, 145, 70);
g.setColor(Color.black);
g.fillOval(140, 40, 5,5);
g.fillOval(130, 40, 5,5);
}
}
MyTest.java
import java.awt.*;
import java.awt.event.*;
public class MyTest{
public static void main(String args[]){
Frame f = new Frame();
MyPanel mp = new MyPanel();
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
f.add(mp);
f.setSize(300,300);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}