Topic: 求助高手,有关this的,不太理解

  Print this page

1.求助高手,有关this的,不太理解 Copy to clipboard
Posted by: needd
Posted on: 2005-10-06 22:55

import javax.swing.*;
import java.awt.*;

public class why
{
public static void main(String agrs[])
{
   haha frame=new haha();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.show();
   }
}
   class test extends JFrame
{
    public test()
{
      this.setTitle("helloworld");
      this.setSize(500,400);
    }
  }
  
以上代码我不太懂的地方就是当我运行我没有调用test方法
为什么我的面板的setTitle和setSize给更改了?
还有test()和test类同名使不是叫构造函数?要不同名使不是叫构造方法?我老是分不清楚

2.Re:求助高手,有关this的,不太理解 [Re: needd] Copy to clipboard
Posted by: ranchgirl
Posted on: 2005-10-06 23:55

1) Your code is not compilable, let alone runs

2) Where is your haha class defined???

3) Class name should start with a capital letter.

4) If you insist to use all kinds of trash class or variable names, no employer will hire you as programmer. We should not answer your questions either.

5) Fix all above, post your fix here again!!!!!!

Thanks!

3.Re:求助高手,有关this的,不太理解 [Re: needd] Copy to clipboard
Posted by: lizhihua
Posted on: 2005-10-07 13:11

在JAVA中如果方法名与类名相同被称为构造方法,其它定义的方法就应该是类的成员方法。ToungeSmileConfused

4.Re:求助高手,有关this的,不太理解 [Re: needd] Copy to clipboard
Posted by: needd
Posted on: 2005-10-07 13:35

import javax.swing.*;
import java.awt.*;

public class why
{
public static void main(String agrs[])
{
test frame=new test();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class test extends JFrame
{
public test()
{
this.setTitle("helloworld");
this.setSize(500,400);
}
}

谢了各位,斑竹代码我改了

5.Re:求助高手,有关this的,不太理解 [Re: gongshi] Copy to clipboard
Posted by: 孤独的狼
Posted on: 2005-10-07 18:32

this是指当前的类对象


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923