package com.test;
import javax.swing.*;
import java.awt.*;
public class Dome9_1 extends  JFrame{
MyPanel mp =null;
Dome9_1 dome9_1 =new Dome9_1();
/**
 * @param args
 */
public static void main(String[] args) {

}
 public Dome9_1() {
 mp =new MyPanel();
 this.add(mp);
 this.setSize(400,300);
 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 this.setVisible(true);
 
 }}
class MyPanel extends JPanel{
//覆盖JPannel 的paint方法
//Granphics 是绘图的重要类,你可以把它理解成一支笔
public void Paint (Graphics g){
//1.调用父类函数完成初始化

//这句话,不能少
super.paint(g);
System.out.println("你哈");
//
g.drawOval(10, 10, 30, 30);
}
}为什么我的程序运行不了,怎么会事啊???

解决方案 »

  1.   

    public static void main(String[] args) {}你也太狠了,main函数里啥都没有,好歹把窗口对象“Dome9_1”new起来吧public static void main(String[] args) {
      Dome9_1 f = new Dome9_1();
      f.setBounds(100, 100, 300, 250);
      f.setVisible(true);
    }
      

  2.   


    package com.test;
    import javax.swing.*;
    import java.awt.*;
    public class Dome9_1 extends JFrame{
    MyPanel mp =null;
    Dome9_1 dome9_1 =new Dome9_1();
    /**
    * @param args
    */
    public static void main(String[] args) {
    new Dome9_1();
    }
    public Dome9_1() {
    mp =new MyPanel();
    this.add(mp);
    this.setSize(400,300);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setVisible(true);
      
    }}
    class MyPanel extends JPanel{
    //覆盖JPannel 的paint方法
    //Granphics 是绘图的重要类,你可以把它理解成一支笔
    public void Paint (Graphics g){
    //1.调用父类函数完成初始化//这句话,不能少
    super.paint(g);
    System.out.println("你哈");
    //
    g.drawOval(10, 10, 30, 30);
    }
    }