再规范一下
import java.awt.*;/*UFrame类是想继承Frame类,标出标题"麦当劳欢迎您",然后在创建的UFrame对象(框架内)写入"竭诚为您服务"的内容.本来意图效果只有一个带有"麦当劳欢迎您"标题的框架,且这个框架内写有"竭诚为您服务"的内容,结果却分别是两个框架,一个框架标有"麦当劳欢迎您"的标题,另一个框架的体内有"竭诚为您服务"内容,不知道为什么产生了不想要的结果,谢谢大侠指点*//*这段程序中,paint()方法到底是哪个对象的方法????是UFrame对象的方法,还是Frame类fra对象的方法??这个地方我非常模糊,希望大侠们能够详细的帮我写清楚,先谢谢了*/class UFrame extends Frame{
    public UFrame(){            //无参构造方法,初始化Frame类的标题为"麦当劳为您服务"
Frame fra=new Frame();
fra.setTitle("麦当劳欢迎您!");
fra.setVisible(true);    }
    public void paint(Graphics g){              //这里的Graphics g值得到底是那个对象环境?
String herk="竭诚为您服务^_^";
g.setFont(new Font(null,Font.CENTER_BASELINE,25));
setForeground(Color.red);
g.drawString(herk,250,100);
}
}
public class UTest{
    public static void main(String [] args){
UFrame one=new  UFrame();
one.setVisible(true);
    }
}

解决方案 »

  1.   

    你的构造有问题
    public UFrame()
    {   
    this.setTitle("麦当劳欢迎您!");
    }
      

  2.   

    这才是继承:
    class UFrame extends Frame{
        public UFrame(){            //无参构造方法,初始化Frame类的标题为"麦当劳为您服务"
    this.setTitle("麦当劳欢迎您!");
    this.setVisible(true);    }
        public void paint(Graphics g){              //这里的Graphics g值得到底是那个对象环境?
    String herk="竭诚为您服务^_^";
    g.setFont(new Font(null,Font.CENTER_BASELINE,25));
    setForeground(Color.red);
    g.drawString(herk,250,100);
    }
        }
    public class UTest{
        public static void main(String [] args){
    UFrame one=new  UFrame();
    one.setVisible(true);
        }
    }
      

  3.   

    关于你的代码运行过程:生成UFrame的对象one时首先调用其无参构造函数,而你的构造函数中却又构造了另外的Frame对象fra,并将它设置标题,显示,然后才显示对象one。
    Graphics g是UFrame中的Graphics window
      

  4.   


    回复人: xiaohuasz() ( ) 信誉:100  2005-02-19 20:09:00  得分: 0  
    谢谢你了,运行过程分析的相当清楚,
    回复人: dyhml(VirusCamp) ( ) 信誉:100 
    也谢谢你,给了我正确的代码
    马上揭帖,^_^
      

  5.   

    我觉得用不着两个类来做,一个就行了啊!
    import java.awt.*;
    public class UFrame extends Frame{
        public UFrame(){            
    this.setTitle("麦当劳欢迎您!");
    this.setVisible(true);    }
        public void paint(Graphics g){              
    String herk="竭诚为您服务^_^";
    g.setFont(new Font(null,Font.CENTER_BASELINE,25));
    setForeground(Color.red);
    g.drawString(herk,250,100);
    }
     public static void main(String [] args){
    UFrame one=new  UFrame();
    one.setVisible(true);
        }
     
        }
      

  6.   

    TO:  goga21cn(郭外城)
     你说得很对,我已经习惯这样写了^_^