Java 作业:setVisible import
Java Homework: setVisible import
我正在做一些 java 家庭作业,但我很难理解我做错了什么。在这一步中,我需要确定JFrameclass继承的哪个class声明了setVisible方法,然后导入那个class并修改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);
}
}
我会 post 我一直在尝试的东西,但它没有意义,也不值得复制。我的发现是 setVisible 来自 Window.java,而
public void setVisible(boolean bln) {
// compiled code
}
是我发现的,之后我尝试将 setVisible class 从 Window.java 导入我的代码,但我尝试的一切都不起作用。
I am required to determine which class inherited by the JFrame class declares the setVisible method, then import that class and modify the code in the main method so the frame variable is declared as that type rather than as a JFrame type.
Java API 会告诉你这个。查找 JFrame API entry, and then on that page, search for the the setVisible
method and it shows that this method belongs to the Window class: java.awt.Window
(Window API entry)。因此,如果您需要做的只是对其调用 setVisible(true)
,则可以使用 Window 变量代替 JFrame 变量。请注意,如果您需要此变量的更多 JFrame 特定功能,例如获取 contentPane,则 Window 类型将不起作用。
例如
// be sure to import java.awt.Window;
Window window = new ProductFrame();
window.setVisible(true);
最重要的是你要学会使用 API,因为它会回答 大多数 你 Java 的问题。
我正在做一些 java 家庭作业,但我很难理解我做错了什么。在这一步中,我需要确定JFrameclass继承的哪个class声明了setVisible方法,然后导入那个class并修改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);
}
}
我会 post 我一直在尝试的东西,但它没有意义,也不值得复制。我的发现是 setVisible 来自 Window.java,而
public void setVisible(boolean bln) {
// compiled code
}
是我发现的,之后我尝试将 setVisible class 从 Window.java 导入我的代码,但我尝试的一切都不起作用。
I am required to determine which class inherited by the JFrame class declares the setVisible method, then import that class and modify the code in the main method so the frame variable is declared as that type rather than as a JFrame type.
Java API 会告诉你这个。查找 JFrame API entry, and then on that page, search for the the setVisible
method and it shows that this method belongs to the Window class: java.awt.Window
(Window API entry)。因此,如果您需要做的只是对其调用 setVisible(true)
,则可以使用 Window 变量代替 JFrame 变量。请注意,如果您需要此变量的更多 JFrame 特定功能,例如获取 contentPane,则 Window 类型将不起作用。
例如
// be sure to import java.awt.Window;
Window window = new ProductFrame();
window.setVisible(true);
最重要的是你要学会使用 API,因为它会回答 大多数 你 Java 的问题。