Java作业:setVisible导入
我正在做一些java作业,很难理解我做错了什么。在这一步中,我需要确定JFrame类继承的哪个类声明setVisible方法,然后导入该类并修改main方法中的代码,以便将frame变量声明为该类型而不是JFrame类型Java作业:setVisible导入,java,swing,inheritance,jframe,Java,Swing,Inheritance,Jframe,我正在做一些java作业,很难理解我做错了什么。在这一步中,我需要确定JFrame类继承的哪个类声明setVisible方法,然后导入该类并修改main方法中的代码,以便将frame变量声明为该类型而不是JFrame类型 import javax.swing.JFrame; public class ProductFrame extends JFrame { public ProductFrame() { // all of these methods are
import javax.swing.JFrame;
public class ProductFrame extends JFrame {
public ProductFrame()
{
// all of these methods are available because
// they are inherited from the JFrame class
// and its superclasses
this.setTitle("Product")
this.setSize(200, 200);
this.setLocation(10, 10);
this.setResizable(false);
// this method uses a field that's available
// because it's inherited
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
// this creates an instance of the ProductFrame
JFrame frame = new ProductFrame();
// this displays the frame
frame.setVisible(true);
}
}
我会发布我一直在尝试的东西,但它没有意义,也不值得复制。我的发现是setVisible来自Window.java,并且
public void setVisible(boolean bln) {
// compiled code
}
这就是我发现的,之后我尝试将setVisible类从Window.java导入到我的代码中,但我尝试的一切都不起作用
我需要确定JFrame类继承的哪个类声明setVisible方法,然后导入该类并修改main方法中的代码,以便将frame变量声明为该类型而不是JFrame类型
import javax.swing.JFrame;
public class ProductFrame extends JFrame {
public ProductFrame()
{
// all of these methods are available because
// they are inherited from the JFrame class
// and its superclasses
this.setTitle("Product")
this.setSize(200, 200);
this.setLocation(10, 10);
this.setResizable(false);
// this method uses a field that's available
// because it's inherited
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
// this creates an instance of the ProductFrame
JFrame frame = new ProductFrame();
// this displays the frame
frame.setVisible(true);
}
}
JavaAPI将告诉您这一点。查找,然后在该页面上搜索setVisible方法,它显示该方法属于Window类:java.awt.Window。因此,如果只需调用setVisibletrue,就可以使用窗口变量代替JFrame变量。请注意,如果您需要此变量提供更多JFrame特定的功能,例如获取contentPane,那么窗口类型将不起作用
e、 g
底线是让您学习如何使用API,因为它将回答您的大多数Java问题
我需要确定JFrame类继承的哪个类声明setVisible方法,然后导入该类并修改main方法中的代码,以便将frame变量声明为该类型而不是JFrame类型
import javax.swing.JFrame;
public class ProductFrame extends JFrame {
public ProductFrame()
{
// all of these methods are available because
// they are inherited from the JFrame class
// and its superclasses
this.setTitle("Product")
this.setSize(200, 200);
this.setLocation(10, 10);
this.setResizable(false);
// this method uses a field that's available
// because it's inherited
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
// this creates an instance of the ProductFrame
JFrame frame = new ProductFrame();
// this displays the frame
frame.setVisible(true);
}
}
JavaAPI将告诉您这一点。查找,然后在该页面上搜索setVisible方法,它显示该方法属于Window类:java.awt.Window。因此,如果只需调用setVisibletrue,就可以使用窗口变量代替JFrame变量。请注意,如果您需要此变量提供更多JFrame特定的功能,例如获取contentPane,那么窗口类型将不起作用
e、 g
底线是让您学习如何使用API,因为它将回答您的大多数Java问题