java.AWT-setSize()方法 [英] java.AWT - setSize() method
本文介绍了java.AWT-setSize()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面的程序中使用setSize()方法遇到问题.
I am facing an issue using setSize() method in the below program.
错误:未为类型框架定义方法setSize(int,int).
Error : The method setSize(int,int) is not defined for the type frame.
当我看到Java API时,类框架"具有从类继承的该方法java.awt.Window.当我实例化Frame类时,此对象应具有setSize()方法,因为Frame是Window的派生类.那我为什么会收到这个错误?派生类如何不包含其超类方法?
When I see Java API, "Class Frame" has this Method inherited from class java.awt.Window. As i have instantiated the Frame class, this object should have setSize() method as Frame is derived class of 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();
}
}
推荐答案
使用此代码
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();
}
}
这篇关于java.AWT-setSize()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文