简体   繁体   English

java.AWT - setSize() 方法

[英]java.AWT - setSize() method

I am facing an issue using setSize() method in the below program.我在下面的程序中使用 setSize() 方法遇到问题。

Error : The method setSize(int,int) is not defined for the type frame.错误:未为类型框架定义 setSize(int,int) 方法。

When I see Java API, "Class Frame" has this Method inherited from class java.awt.Window.当我看到 Java API 时,“类框架”具有从类 java.awt.Window 继承的此方法。 As i have instantiated the Frame class, this object should have setSize() method as Frame is derived class of Window.因为我已经实例化了 Frame 类,所以这个对象应该有 setSize() 方法,因为 Frame 是 Window 的派生类。 Why am I getting this error then?为什么我会收到这个错误? How can a derived class doesnt contain its superclass method?派生类如何不包含其超类方法?

public class AwtPrac{

  public static void main(String[] args) {
    Frame fm = new Frame("Java Programm");
    Button b= new Button ("Click Here");
    fm.add(b);
    fm.setVisible(true);
    fm.SetSize(300,300);
    fm.dispose();
  }
}

Take this code拿这个代码

   import java.awt.Frame;

  public class AwtPrac  {

private static  void init(){
    Frame fm = new Frame("Java Programm");
   fm.setTitle("AwtPrac");
   fm.setSize(300,300);
    fm.setVisible(true);
}

public static void main(String[] args) {
    init();
}

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM