//绘图 package com.test1; import java.awt.*; import javax.swing.*; public class Demo9_1 extends JFrame{ MyPanel mp=null; public static void main(String[] args) { // TODO Auto-generated method stub Demo9_1 demo9_1=new Demo9_1(); } public Demo9_1(){ mp=new MyPanel(); this.add(mp); this.setSize(400,300); this.setVisible(true); } } //定义一个MyJpanel class MyPanel extends JPanel{ //覆盖paint public void paint(Graphics g){ //调用父类函数完成初始化 super.paint(g); //先画一个圆 g.drawOval(10, 10, 30, 30); } }