再规范一下
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);
}
}
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);
}
}
public UFrame()
{
this.setTitle("麦当劳欢迎您!");
}
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);
}
}
Graphics g是UFrame中的Graphics window
回复人: xiaohuasz() ( ) 信誉:100 2005-02-19 20:09:00 得分: 0
谢谢你了,运行过程分析的相当清楚,
回复人: dyhml(VirusCamp) ( ) 信誉:100
也谢谢你,给了我正确的代码
马上揭帖,^_^
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);
}
}
你说得很对,我已经习惯这样写了^_^