您的位置:程序门 -> java -> j2se / 基础类



刚学到gui,有个地方不知道什么意思 万望解答


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


刚学到gui,有个地方不知道什么意思 万望解答
发表于:2007-02-25 05:01:24 楼主
import   javax.swing.*;
import   java.awt.*;

public   class   nothelloworld
{
public   static   void   main(string[]   args)
{
    nothelloworldframe   frame   =   new   nothelloworldframe();
    frame.setdefaultcloseoperation(jframe.exit_on_close);
    frame.setvisible(true);
}
}

class   nothelloworldframe   extends   jframe
{
public   nothelloworldframe()
{
settitle( "nothelloworld ");
setsize(default_width,default_height);
nothelloworldpanel   panel   =   new   nothelloworldpanel();
add(panel);
}
public   static   final   int   default_width   =   300;
public   static   final   int   default_height   =   200;
}

class   nothelloworldpanel   extends   jpanel
{
public   void   paintcomponent(graphics   g)
{
//super.paintcomponent(g);
g.drawstring( "not   a   hello   ,world   program ",message_x,message_y);
}

public   static   final   int   message_x   =   75;
public   static   final   int   message_y   =   100;
}


这段代码中,第21行的     add(panel);     代表什么意思???
书上说如果使用的是jdk1.4一下的版本,这句该这么写   getcontentpane().add(panel)  
没有分分可以散给大家,但还是希望可以帮忙解答一下啦,谢谢了。
发表于:2007-02-25 09:49:131楼 得分:0
你去看看java文档,反正有中文版的啊。
发表于:2007-02-25 10:53:162楼 得分:0
jframe是窗体,jpanel是面板
add(panel);   是将这个面板添加到窗体中
jdk1.4一下的版本确实是用getcontentpane().add(panel)   这个方法
jdk1.5以后版本可以直接添加了
发表于:2007-02-26 13:11:103楼 得分:0
jdk5.0   中可以直接把面板放入内容窗格!
以前的版本不可以!只有调用   getcontentpane().add(panel)


快速检索

最新资讯
热门点击